示例#1
0
        public async Task <IActionResult> CreateDoctor(CreateDoctorModel doctor)
        {
            if (!ModelState.IsValid)
            {
                return(View(doctor));
            }

            var result = await _adminService
                         .RegisterDoctor(
                doctor.FirstName,
                doctor.LastName,
                doctor.EGN,
                doctor.UID,
                doctor.Gender,
                doctor.Bulstat);

            if (result.Succeeded)
            {
                var d = await _adminService.GetUserByName(doctor.UID);

                await _doctorService.CreateDoctor(d.Id, doctor.UID);

                return(RedirectToAction("Index"));
            }

            foreach (var error in result.Errors)
            {
                ModelState.AddModelError("", error);
            }

            return(View(doctor));
        }
示例#2
0
        public async Task <ActionResult <DoctorDto> > Post(DoctorDto model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var existing = await _doctorService.GetDoctorByNameAsync(model.Name);

                    if (existing != null)
                    {
                        return(BadRequest("The room is already exists!"));
                    }

                    var location = _linkGenerator.GetPathByAction(HttpContext,
                                                                  "Get", "Doctors",
                                                                  new { name = model.Name });

                    if (string.IsNullOrWhiteSpace(location))
                    {
                        return(BadRequest("Could not use current name"));
                    }

                    var doctor = _mapper.Map <Doctor>(model);

                    if (await _doctorService.CreateDoctor(doctor))
                    {
                        return(Created(location, doctor));
                    }

                    return(BadRequest("Something bad happened!"));
                }
                else
                {
                    return(BadRequest(ModelState));
                }
            }
            catch (Exception e)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Database Failure: {e}"));
            }
        }