public IActionResult Alter(DoctorView doctor) { UpdateDoctorModel update = new UpdateDoctorModel(doctor.Id , doctor.Name , doctor.Specialty , doctor.Phone); if (update.Invalid) { ViewData["IdError"] = update.Notifications .Where(w => w.Property == "Id")? .FirstOrDefault()? .Message; ViewData["NameError"] = update.Notifications .Where(w => w.Property == "Name")? .FirstOrDefault()? .Message; ViewData["SpecialtyError"] = update.Notifications .Where(w => w.Property == "Specialty")? .FirstOrDefault()? .Message; ViewData["PhoneError"] = update.Notifications .Where(w => w.Property == "Phone")? .FirstOrDefault()? .Message; ViewData["Doctor"] = doctor ?? new DoctorView(); return(View("Edit")); } ViewData["DoctorView"] = _mapper.Map <DoctorView>(_doctorService.Update(update)); return(View()); }
public ActionResult UpdateDoctor(int id) { //Pass doctor id to view using viewbag ViewBag.doctor_id = id; //Get all departments from Dapartment table and pass it to view using viewbag ViewBag.DepartmentList = objDept.getDepartmentList(); //Get specific doctor based on the selected doctor id var objDoctor = objDoc.getDoctorByID(id); if (objDoctor == null) { return(View("NotFound")); } else { UpdateDoctorModel objUpDoc = new UpdateDoctorModel(); objUpDoc.department_name = objDoctor.department_name; objUpDoc.first_name = objDoctor.first_name; objUpDoc.last_name = objDoctor.last_name; objUpDoc.email = objDoctor.email; objUpDoc.phone = objDoctor.phone; objUpDoc.specialty = objDoctor.specialty; objUpDoc.bio = objDoctor.bio; objUpDoc.photo_path = objDoctor.photo_path; return(View(objUpDoc)); } }
public ActionResult UpdateDoctor(int id, UpdateDoctorModel udModel, HttpPostedFileBase image) { ViewBag.doctorId = id; if (ModelState.IsValid) { try { riversideLinqDataContext objLinq = new riversideLinqDataContext(); doctor objDoctor = objLinq.doctors.Single(x => x.id == id); // Update the image of doctor if (image != null) { //Delete old photo var oldImage = objDoctor.photo_path; string fullPath = Server.MapPath("~/Content/images/doctors/" + oldImage); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(Server.MapPath("~/Content/images/doctors/" + oldImage)); } //Upload new photo string doctor_photo = Path.GetFileName(image.FileName); string image_ext = Path.GetExtension(image.FileName); doctor_photo = DateTime.UtcNow.Ticks + doctor_photo; objDoctor.photo_path = doctor_photo; string path = Path.Combine(Server.MapPath("~/Content/images/doctors/"), doctor_photo); image.SaveAs(path); } objDoctor.department_name = udModel.department_name; objDoctor.first_name = udModel.first_name; objDoctor.last_name = udModel.last_name; objDoctor.email = udModel.email; objDoctor.phone = udModel.phone; objDoctor.specialty = udModel.specialty; objDoctor.bio = udModel.bio; objLinq.SubmitChanges(); return(RedirectToAction("ListDoctor")); } catch { return(View(udModel)); } } // If we got this far, something failed, redisplay form return(View(udModel)); }
private IDoctorForResponse CreateModelForPutTest() { var model = new UpdateDoctorModel { FirstName = "Create", LastName = "Test" }; return(model); }
private IDoctorForResponse CreateModelForUpdate(dynamic doctor) { int doctorId = Convert.ToInt32(doctor ["Id"].Value); var model = new UpdateDoctorModel { Id = doctorId, FirstName = "Update", LastName = "Test" }; return(model); }
public async Task <ActionResult <Doctor> > DoctorAsync([FromBody] UpdateDoctorModel updateDoctorModel) { try { var doctor = await _mediator.Send(new GetDoctorByIdQuery { Id = updateDoctorModel.Id }); if (doctor == null) { return(BadRequest($"No doctor found with the id {updateDoctorModel.Id}")); } return(await _mediator.Send(new UpdateDoctorCommand { Doctor = _mapper.Map(updateDoctorModel, doctor) })); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
private IDoctorForResponse CreateModelForUpdate(dynamic doctor) { int doctorId = Convert.ToInt32(doctor [ "Id" ].Value); var model = new UpdateDoctorModel { Id = doctorId, FirstName = "Update", LastName = "Test" }; return model; }
private IDoctorForResponse CreateModelForPutTest() { var model = new UpdateDoctorModel { FirstName = "Create", LastName = "Test" }; return model; }