public void Handle(BookAppointmentCommand command) { var property = _context.Properties.Find(command.PropertyId); if (property != null) { var appointment = new Appointment { Property_Id = command.PropertyId, AppointmentDateTime = command.AppointmentDateTime, BuyerUserId = command.BuyerUserId, Status = AppointmentStatus.Accepted, // as of now it will be accepted, but it needs to be pending by default and appointment should be accepted by seller/agent in future CreatedAt = DateTime.Now, }; if (property.Appointments == null) { property.Appointments = new List <Appointment>(); } property.Appointments.Add(appointment); _context.SaveChanges(); } }
public bool Handle(BookAppointmentCommand command) { var property = _context.Properties.Find(command.PropertyId); //if (property.Appointments != null && property.Appointments.Count(o => o.BuyerUserId == command.BuyerUserId) > 0) { return false; } var appointment = new Appointment { PropertyId = command.PropertyId, ViewingDateTime = command.ViewingDateTime, BuyerUserId = command.BuyerUserId, IsViewing = true, UpdatedAt = DateTime.Now }; if (property.Appointments == null) { property.Appointments = new List <Appointment>(); } property.Appointments.Add(appointment); _context.SaveChanges(); return(true); }
/// <summary> /// Creates appointment for the specified date and property. /// </summary> public void Handle(BookAppointmentCommand command) { var property = _context.Properties.SingleOrDefault(p => p.Id == command.PropertyId); var appointment = new Appointment { Date = command.Date, Status = AppointmentStatus.Pending, BuyerUserId = command.BuyerUserId }; if (property.Appointments == null) { property.Appointments = new List <Appointment>(); } property.Appointments.Add(appointment); _context.Appointments.Add(appointment); _context.SaveChanges(); }