public async Task <IActionResult> DoctorPatientRecordConform(Guid patientId, int doctorId, DateTime date, int serviceId)
        {
            var user = await _userManager.FindByIdAsync(patientId.ToString());

            var appointmentDate = this._unitOfWork.DatesOfAppointments
                                  .Find(d => d.DoctorID == doctorId && d.Date.Date == date.Date)
                                  .FirstOrDefault();
            var service = this._unitOfWork.Services.Get(serviceId);
            var reserve = new ReservedTime
            {
                DateOfAppointmentID = appointmentDate.DateOfAppointmentID,
                DateOfAppointment   = appointmentDate,
                UserID          = user.Id,
                ApplicationUser = user,
                ServiceID       = service.ServiceID,
                Service         = service,
                Time            = date
            };

            this._unitOfWork.ReservedTimes.Add(reserve);
            this._unitOfWork.Save();
            ViewBag.Message = "Пациент успешно записан";
            return(View("Info"));
        }
        public async Task <IActionResult> RecordConfirmation(RecordConfirmViewModel model)
        {
            if (!User.Identity.IsAuthenticated)
            {
                if (!ModelState.IsValid)
                {
                    var modelDoctor   = this._unitOfWork.Doctors.Get(model.DoctorID);
                    var modelEmployee = this._unitOfWork.Employees.Get(modelDoctor.EmployeeID);
                    var modelUser     = this._unitOfWork.Users.Get(modelEmployee.UserID);
                    var modelService  = this._unitOfWork.Services.Get(model.ServiceID);
                    model.DoctorID         = modelDoctor.ID;
                    model.DoctorLastName   = modelUser.LastName;
                    model.DoctorFirstName  = modelUser.FirstName;
                    model.DoctorSpeciality = this._unitOfWork.Specialtys.Find(s => s.ID == modelDoctor.SpecialtyID).FirstOrDefault().Name;
                    model.ServiceID        = modelService.ServiceID;
                    model.ServiceName      = modelService.Name;
                    model.ServiceCost      = modelService.Price;
                    return(View(model));
                }
            }

            Patient patient = null;
            var     date    = this._unitOfWork.DatesOfAppointments.
                              Find(d => d.DoctorID == model.DoctorID && d.Date.Date == model.Date.Date).FirstOrDefault();
            ApplicationUser user = null;

            if (User.Identity.IsAuthenticated)
            {
                user = await _userManager.GetUserAsync(HttpContext.User);

                if (User.IsInRole(UserRole.Пациент.ToString()))
                {
                    patient = this._unitOfWork.Patients.Get(user.Id);
                }
                else
                {
                    ViewBag.Message = "Только пациенты могут записываться на прием";
                }
            }
            else
            {
                var userName = Guid.NewGuid().ToString();
                user = new ApplicationUser
                {
                    UserName    = userName,
                    Password    = "",
                    LastName    = model.LastName,
                    FirstName   = model.FirstName,
                    PhoneNumber = model.Phone,
                    Email       = model.Email,
                    Gender      = Gender.Мужской,
                    Role        = UserRole.Пациент,
                };

                var result = await _userManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    user = await _userManager.FindByNameAsync(userName);

                    patient = new Patient
                    {
                        UserID          = user.Id,
                        ApplicationUser = user
                    };

                    this._unitOfWork.Patients.Add(patient);
                    this._unitOfWork.Save();
                    patient = this._unitOfWork.Patients.Get(user.Id);
                }
            }


            var reserve = new ReservedTime
            {
                DateOfAppointmentID = date.DateOfAppointmentID,
                DateOfAppointment   = date,
                ApplicationUser     = user,
                UserID    = user.Id,
                Time      = model.Date,
                ServiceID = model.ServiceID
            };

            this._unitOfWork.ReservedTimes.Add(reserve);
            this._unitOfWork.Save();

            ViewBag.Message = "Пользователь успешно записан";
            return(View("Info"));
        }