public async Task<int> Create(AppointmentCreateDTO model, NonRegisteredUserCreateDTO user) { if (!await userManager.IsInRoleAsync(model.AgentId, AgentRole)) { throw new NotAuthorizedException("Потребителят на който заявявате среща не е Брокер или не е намерен!"); } if (!await unitOfWork.PropertiesBaseRepository.GetAll().AnyAsync(p => p.Id == model.PropertyId)) { throw new ContentNotFoundException("Имотът, за който заявявате среща не е намерен в системата!"); } Appointments appointment = new Appointments { AgentId = model.AgentId, PropertyId = model.PropertyId, AppointmentDate = model.AppointmentDate, AppointmentDescription = model.AppointmentDescription, NonRegisteredUser = new NonRegisteredAppointmentUsers { ClientEmail = user.ClientEmail, ClientName = user.ClientName, ClientPhoneNumber = user.ClientPhoneNumber } }; var appointmentId = await CreateAppointment(appointment); //Notify Agent for the appointment if (ConfigurationManager.AppSettings["AppStatus"] != "Developement") { await SendEmailAndSmsNotificationToAgent(model.AgentId, model.PropertyId, user.ClientName, user.ClientEmail, user.ClientPhoneNumber); } return appointmentId; }
public async Task <int> CreateNonRegisteredUser(NonRegisteredUserCreateDTO userModel) { if (string.IsNullOrEmpty(userModel.ClientName)) { throw new ArgumentException("ClientName not provided!"); } if (string.IsNullOrEmpty(userModel.ClientEmail) && string.IsNullOrEmpty(userModel.ClientPhoneNumber)) { throw new ArgumentException("ClientEmail nor ClientPhoneNumber provided!"); } NonRegisteredAppointmentUsers appointmentUser = new NonRegisteredAppointmentUsers { ClientName = userModel.ClientName, ClientEmail = userModel.ClientEmail, ClientPhoneNumber = userModel.ClientPhoneNumber }; unitOfWork.UsersRepository.AddNonRegisteredUser(appointmentUser); await unitOfWork.SaveAsync(); return(appointmentUser.Id); }