Example #1
0
 public ControllerResponse AddNewProfession([FromBody] string professionName)
 {
     if (string.IsNullOrWhiteSpace(professionName))
     {
         return(ControllerResponse.Warning(""));
     }
     _adminServices.AddNewProfession(professionName);
     return(ControllerResponse.Ok());
 }
Example #2
0
        public ControllerResponse <string> DeleteDoctor([FromBody] DoctorForDeletingDto doctorForDeletingDto)
        {
            if (!doctorForDeletingDto.DoctorId.ValidationId() && doctorForDeletingDto.DateOfDismissal == default)
            {
                return(ControllerResponse <string> .Warning("Запрос не был правильно сформирован, повторите попытку"));
            }

            return(ControllerResponse <string> .Ok(_adminServices.DismissDoctor(doctorForDeletingDto.DoctorId, doctorForDeletingDto.DateOfDismissal).ToString("D")));
        }
Example #3
0
 public ControllerResponse DisapproveDoctor([FromBody] int doctorId)
 {
     if (!doctorId.ValidationId())
     {
         return(ControllerResponse.Warning("Запрос не был правильно сформирован, повторите попытку"));
     }
     _adminServices.DisapproveDoctor(doctorId);
     return(ControllerResponse.Ok());
 }
Example #4
0
        private Task HandleExceptionAsync(HttpContext context, Exception exception)
        {
            context.Response.ContentType = "application/json";

            var response = exception is WarningException
                ? ControllerResponse.Warning(exception.Message)
                : ControllerResponse.Exception(ExceptionMessages.Error);

            return(context.Response.WriteAsync(JsonConvert.SerializeObject(response)));
        }
Example #5
0
        public ControllerResponse ChangeDoctorSchedule([FromBody] ScheduleFullDto scheduleToRender)
        {
            if (!AdminValidator.ValidateScheduleForUpdating(scheduleToRender))
            {
                return(ControllerResponse.Warning("Данные были не введены или введены не полностью, повторите запрос"));
            }

            _adminServices.UpdateSchedule(new ScheduleWithDateTransfer(scheduleToRender));
            return(ControllerResponse.Ok());
        }
        public ControllerResponse <ProfessionDto> GetProfessionByDoctorId(int doctorId)
        {
            if (!doctorId.ValidationId())
            {
                return(ControllerResponse <ProfessionDto> .Warning(
                           "Произошел сбой. Проверьте правильность введенных данных и повторите запрос"));
            }

            return(ControllerResponse <ProfessionDto> .Ok(new ProfessionDto(_commonServices.GetProfessionByDoctorId(doctorId))));
        }
        public ControllerResponse <IEnumerable <DoctorDto> > GetAllDoctorsByProfession(int professionId)
        {
            if (!professionId.ValidationId())
            {
                return(ControllerResponse <IEnumerable <DoctorDto> > .Warning(
                           "Профессия врача указана некорректно или произошел сбой, повторите запрос"));
            }

            return(ControllerResponse <IEnumerable <DoctorDto> > .Ok(_commonServices
                                                                     .GetDoctorsByProfession(professionId).Select(d => new DoctorDto(d))));
        }
        public ControllerResponse <IEnumerable <KeyValuePair <TimeSpan, SessionViewModel> > > GetSessionsByDoctorAndDate(int doctorId, DateTime dateTime)
        {
            if (!UserValidator.ValidateDoctorAndDateToGetting(doctorId,
                                                              dateTime))
            {
                return(ControllerResponse <IEnumerable <KeyValuePair <TimeSpan, SessionViewModel> > > .Warning(
                           "Доктор или дата приема не указаны или указаны неверно, повторите запрос"));
            }

            return(ControllerResponse <IEnumerable <KeyValuePair <TimeSpan, SessionViewModel> > > .Ok(_commonServices
                                                                                                      .GetSessionsByDoctorIdAndDate(doctorId,
                                                                                                                                    dateTime)
                                                                                                      .Select(kvp => new KeyValuePair <TimeSpan, SessionViewModel>(kvp.Key, SessionViewModel.ConvertToSessionViewModel(kvp.Value)))));
        }
Example #9
0
        public ControllerResponse AddProfession([FromBody] int professionId)
        {
            var doctorId = 0;

            if (User.Identity.IsAuthenticated)
            {
                doctorId = int.Parse(User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value);
            }

            if (!professionId.ValidationId())
            {
                return(ControllerResponse.Warning("Данные не были введены, повторите запрос"));
            }
            _doctorServices.AddProfession(doctorId, professionId);
            return(ControllerResponse.Ok());
        }
Example #10
0
        public ControllerResponse AddOrUpdateSchedule([FromBody] ScheduleDto scheduleToRender)
        {
            var doctorId = 0;

            if (User.Identity.IsAuthenticated)
            {
                doctorId = int.Parse(User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value);
            }

            if (!scheduleToRender.ValidateScheduleToUpdating())
            {
                return(ControllerResponse.Warning("Данные были не введены или введены не полностью, повторите запрос"));
            }
            _doctorServices.UpdateSchedule(new ScheduleWithDateTransfer(scheduleToRender, doctorId));
            return(ControllerResponse.Ok());
        }
Example #11
0
        public ControllerResponse UnreserveSession([FromBody] int sessionId)
        {
            var userId = 0;

            if (User.Identity.IsAuthenticated)
            {
                userId = int.Parse(User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value);
            }
            if (!UserValidator.ValidateSessionToCancel(sessionId, userId))
            {
                return(ControllerResponse.Warning(
                           "Произошел сбой. Проверьте корректность введенных данных и повторите запрос"));
            }

            _userServices.CancelSession(sessionId, userId);
            return(ControllerResponse.Ok());
        }
Example #12
0
        public async Task <ControllerResponse> LogIn([FromBody] UserToLogInDto userDto)
        {
            if (!AuthorisationValidator.ValidateUserToLogIn(userDto))
            {
                return(ControllerResponse.Warning(
                           "Данные не введены полностью. Уточните данные запроса и повторите попытку"));
            }

            var user   = _authorizationServices.LogIn(userDto.Login, userDto.Password.GetPasswordHash());
            var claims = new List <Claim>
            {
                new Claim(ClaimsIdentity.DefaultNameClaimType, user.Name),
                new Claim(ClaimsIdentity.DefaultRoleClaimType, user.Role.ToString()),
                new Claim(ClaimTypes.NameIdentifier, user.Id.ToString())
            };
            var id        = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
            var principal = new ClaimsPrincipal(id);
            await HttpContext.SignInAsync(principal);

            return(ControllerResponse.Ok());
        }
Example #13
0
        public ControllerResponse <int> ReserveSession([FromBody] SessionForReservingDto sessionDto)
        {
            var userId = 0;

            if (User.Identity.IsAuthenticated)
            {
                userId = int.Parse(User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value);
            }
            if (!UserValidator.ValidateSessionToReserve(sessionDto, userId))
            {
                return(ControllerResponse <int> .Warning(
                           "Произошел сбой. Проверьте корректность введенных данных и повторите запрос"));
            }

            if (!UserValidator.ValidateTimeForReserving(sessionDto))
            {
                return(ControllerResponse <int> .Warning(
                           "Время для записи некорректно, выберете корректную дату для записи"));
            }

            return(ControllerResponse <int> .Ok(_userServices.ReserveSession(sessionDto.Date,
                                                                             TimeSpan.Parse(sessionDto.TimeOfBeginSession), sessionDto.DoctorId, userId)));
        }
        public ControllerResponse <ScheduleFullDto> GetDoctorSchedule(int doctorId)
        {
            if (!doctorId.ValidationId())
            {
                return(ControllerResponse <ScheduleFullDto> .Warning(
                           "Произошел сбой. Проверьте правильность введенных данных и повторите запрос"));
            }

            var schedule = _commonServices.GetScheduleOnDate(doctorId, DateTime.Today);

            return(ControllerResponse <ScheduleFullDto> .Ok(
                       new ScheduleFullDto
            {
                ActualisationDate = schedule.ActualisationDate,
                Monday = WorkDayDto.GetWorkDayDto(_commonServices.GetWorkDayById(schedule.MondayId)),
                Tuesday = WorkDayDto.GetWorkDayDto(_commonServices.GetWorkDayById(schedule.TuesdayId)),
                Wednesday = WorkDayDto.GetWorkDayDto(_commonServices.GetWorkDayById(schedule.WednesdayId)),
                Thursday = WorkDayDto.GetWorkDayDto(_commonServices.GetWorkDayById(schedule.ThursdayId)),
                Friday = WorkDayDto.GetWorkDayDto(_commonServices.GetWorkDayById(schedule.FridayId)),
                Saturday = WorkDayDto.GetWorkDayDto(_commonServices.GetWorkDayById(schedule.SaturdayId)),
                Sunday = WorkDayDto.GetWorkDayDto(_commonServices.GetWorkDayById(schedule.SundayId))
            }));
        }
Example #15
0
        public async Task <ControllerResponse> SignInUser([FromBody] UserToSignInDto userDto)
        {
            if (!AuthorisationValidator.ValidateUserToSignIn(userDto))
            {
                return(ControllerResponse.Warning(
                           "Введенные данные некорректны, введите все данные и повторите запрос"));
            }

            var user = userDto.IsDoctor
                ? _authorizationServices.SignInDoctor(userDto.Name, userDto.Login, userDto.Password.GetPasswordHash())
                : _authorizationServices.SignInUser(userDto.Name, userDto.Login, userDto.Password.GetPasswordHash());

            var claims = new List <Claim>
            {
                new Claim(ClaimsIdentity.DefaultNameClaimType, user.Name),
                new Claim(ClaimsIdentity.DefaultRoleClaimType, user.Role.ToString()),
                new Claim(ClaimTypes.NameIdentifier, user.Id.ToString())
            };
            var id        = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
            var principal = new ClaimsPrincipal(id);
            await HttpContext.SignInAsync(principal);

            return(ControllerResponse.Ok());
        }