public async Task <IActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var patient = new Patient
                {
                    FirstName   = model.FirstName,
                    LastName    = model.LastName,
                    Email       = model.Email,
                    Sex         = model.Sex.GetValueOrDefault(),
                    DateOfBirth = model.DateOfBirth.GetValueOrDefault(),
                    Role        = Role.Patient,
                    Password    = HashUtils.Hash(model.Password)
                };

                try
                {
                    _logger.Log(LogLevel.Debug, "User tries to register");
                    await _client.SendRequestWithBodyAsync <Patient>(HttpMethod.Post, "Account/RegisterPatient", patient);

                    _logger.Log(LogLevel.Debug, "User registered succesfully");
                    return(RedirectToAction("Login"));
                }
                catch (HttpRequestException)
                {
                    ModelState.AddModelError("EmailExist", _localizer["EmailExists"]);
                }
            }
            return(View(model));
        }
Пример #2
0
        public async Task <IActionResult> Edit(int id, [FromForm] PatientViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var patient = await _client.SendRequestAsync <Patient>(HttpMethod.Get, $"Patients/{id}");

                    model.UpdatePatient(ref patient);

                    await _client.SendRequestWithBodyAsync <Patient>(HttpMethod.Put, $"Patients/{id}", patient);

                    TempData["message"] = "Your changes has been saved.";
                    return(RedirectToAction(nameof(PatientsController.Details), new { id }));
                }
                catch (HttpRequestException)
                {
                    throw new ServerConnectionException();
                }
            }
            else
            {
                return(View(model));
            }
        }
        public async Task <IActionResult> Select(int physicianId, DateTime time, AppointmentType type)
        {
            var userNameIdentifier = HttpContext.User.Claims.FirstOrDefault(x => x.Type.Equals(ClaimTypes.NameIdentifier));

            var userId = Convert.ToInt32(userNameIdentifier.Value.ToString());

            var appointment = new Appointment
            {
                PatientId   = userId,
                PhysicianId = physicianId,
                Time        = time,
                Type        = type,
            };

            try
            {
                await _client.SendRequestWithBodyAsync <Appointment>(HttpMethod.Post, "Appointments", appointment);

                ViewBag.Message = _localizer["AppointmentSelected"];
                return(View("Index"));
            }
            catch (HttpRequestException)
            {
                ModelState.AddModelError("TryAgain", _localizer["TryAgain"]);
                return(View("Index"));
            }
        }
        public async Task <IActionResult> Edit(int id, [FromForm] PhysicianViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var physician = await _client.SendRequestAsync <Physician>(HttpMethod.Get, $"Physicians/{id}");

                    model.UpdatePhysician(ref physician);

                    await _client.SendRequestWithBodyAsync <Physician>(HttpMethod.Put, $"Physicians/{id}", physician);

                    return(RedirectToAction(nameof(PhysiciansController.Details), new { id }));
                }
                catch (HttpRequestException)
                {
                    throw new ServerConnectionException();
                }
            }
            else
            {
                return(View(model));
            }
        }