0

I'm trying to create class where Physician.cs have a ICollection Appointmets property with DateTime inside of it but I'm trying to create Workday class where Physician can say from when he start to when he finishes his workday (ex. Monday from 07:00 to 13:00 regardless of the date).

Do I need to declare DateTime as datatype to the property of Start and Finish in Workday class?

Physician.cs

using System.Collections.Generic;

namespace Med_App_API.Models
{
    public class Physician
    {
        public int Id { get; set; }
        public int UserId { get; set; }
        public User User { get; set; }
        public ICollection<Patient> Patients { get; set; }
        public ICollection<Appointments> Appointments { get; set; }
    }
}

Appointment.cs

using System;

namespace Med_App_API.Models
{
    public class Appointments
    {
        public int Id { get; set; }
        public int PatientId { get; set; }
        public Patient Patient { get; set; }
        public int PhysicianId { get; set; }
        public Physician Physician { get; set; }
        public DateTime TimeofAppointment { get; set; }
        public string TypeOfAppointment { get; set; }
    }
}

Workday.cs

using System;

namespace Med_App_API.Models
{
    public class Workday
    {
        public int Id { get; set; }
        public int PhysicianId { get; set; }
        public Physician Physician { get; set; }
        public DateTime Start { get; set; }
        public DateTime Finish { get; set; }
    }
}
  • Use `TimeSpan` instead of `DateTime` if you don't want the date portion. You'll need to add guards/validation to the properties to ensure the values are in the appropriate range (0 - 24 hours, or whatever). – Heretic Monkey Mar 24 '20 at 13:37
  • Or you can use the `LocalTime` struct in the NodaTime library. – Sweeper Mar 24 '20 at 13:38
  • Does this answer your question? [How do I represent a time only value in .NET?](https://stackoverflow.com/questions/2037283/how-do-i-represent-a-time-only-value-in-net) – Heretic Monkey Mar 24 '20 at 13:39
  • *>Do I need to declare DateTime as datatype to the property of Start and Finish in Workday class?* No, you don't. You might for example use a `TimeSpan` or a `byte` or `int` that represents the hour part of the weekday. – mm8 Mar 24 '20 at 13:41
  • Ok but when lets say patient wants to create an appointment on some date during the time physician works ```DateTime``` is enough as property @HereticMonkey? – Lazar Slavković-Raco Mar 24 '20 at 13:41
  • If you have a date and a time on that date, `DateTime` (or `DateTimeOffset` if you need to deal with time zones) is an appropriate type to use, sure. You should really just look at [the documentation for DateTime](https://learn.microsoft.com/en-us/dotnet/api/system.datetime?view=netframework-4.8) and the associated topics. Keeping track of events occurring in time is a huge topic, and many, many, people have written papers and developed millions of lines of codes devoted to the subject. – Heretic Monkey Mar 24 '20 at 13:49
  • "Easy : DateTime date = DateTime.Now; TimeSpan time = date - date.Date; – jdweng Mar 24 '20 at 14:03

0 Answers0