Пример #1
0
        public IActionResult InsertAppointment([FromBody] InsertAppointmentRequestDto request)
        {
            int recordId = 0;

            try
            {
                var identity = HttpContext.User.Identity as ClaimsIdentity;
                IEnumerable <Claim> claims = identity?.Claims;
                var profileClaim           = claims?.FirstOrDefault(x => x.Type == ClaimTypes.Name);

                if (profileClaim != null && int.TryParse(profileClaim.Value, out var profileId))
                {
                    var profile = profileService.GetProfileById(profileId);
                    request.ProfileId = profile?.Id;
                }

                recordId = appointmentService.AddAppointment(request);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            return(Ok(recordId));
        }
Пример #2
0
        public int AddAppointment(InsertAppointmentRequestDto request)
        {
            Appointment appointment;

            ValidateRequest(request);

            ConvertDtoToDbModel(request, out appointment);
            appointmentRepository.Create(appointment);
            unitOfWork.Save();
            return(appointment.Id);
        }
Пример #3
0
 private void ConvertDtoToDbModel(InsertAppointmentRequestDto dto, out Appointment dbModel)
 {
     dbModel = new Appointment()
     {
         Comment           = dto.Comment,
         CreationTime      = DateTime.UtcNow,
         StartDate         = dto.StartDate,
         ProfileId         = dto.ProfileId,
         AppointmentVisits = new List <AppointmentVisit>()
     };
     foreach (var visitDto in dto.AppointmentVisits)
     {
         AppointmentVisit visit;
         ConvertDtoToDbModel(visitDto, out visit);
         dbModel.AppointmentVisits.Add(visit);
     }
 }
Пример #4
0
        private void ValidateRequest(InsertAppointmentRequestDto request)
        {
            if (request.AppointmentVisits == null || request.AppointmentVisits.Count == 0)
            {
                throw new DomainModelException("Appointment should contain at least 1 visit");
            }

            if (request.StartDate == default)
            {
                throw new DomainModelException("Appointment should contain start date/time");
            }

            foreach (var visit in request.AppointmentVisits)
            {
                if (visit.TimeOfVisit == default)
                {
                    throw new DomainModelException("Every appointment visit should contain time of visit");
                }
            }
        }