public async Task <ActionResult> EditDoctor(int id) { ApplicationUser user = await UserManager.FindByIdAsync(id); Doctor doctor = unitOfWork.Doctors.FindById(id); if (user != null && doctor != null) { EditDoctorViewModel editPatientViewModel = new EditDoctorViewModel() { Id = user.Id, Name = doctor.Name, Patronymic = doctor.Patronymic, Surname = doctor.Surname, SpecializationId = (int)doctor.SpecializationId, GenderId = doctor.GenderId, Email = user.Email, ImageMimeType = doctor.ImageMimeType, ImageData = doctor.ImageData }; ViewBag.Specializations = unitOfWork.Specializations.Get().ToList().OrderBy(s => s.SpecializationTitle); ViewBag.Genders = unitOfWork.Genders.Get().ToList(); return(View(editPatientViewModel)); } else { return(RedirectToAction("Index")); } }
public EditDoctorPage(Models.Doctors doctors) { var EditViewModel = new EditDoctorViewModel(); EditViewModel.TheSelectedDoctor = doctors; BindingContext = EditViewModel; InitializeComponent(); }
protected override void OnAppearing() { if (Doctor != null) { var result = JsonConvert.DeserializeObject <DoctorModel>(Doctor); if (result != null) { BindingContext = new EditDoctorViewModel(result); } } }
public IActionResult Update(string id, EditDoctorViewModel model) { if (id != null) { model.Id = id; } ViewData["Cities"] = _databaseContext.City.OrderBy(p => p.CityPbr).ToList(); var city = _databaseContext.City.FirstOrDefault(m => m.CityId == model.CityId); var country = _databaseContext.Country.FirstOrDefault(m => m.CountryId == 1); city.Country = country; if (ModelState.IsValid) { var user = _databaseContext.Doctor.FirstOrDefault(g => g.Id == id); /*if (model.Email==null) * { * TempData[Constants.Message] = $"Morate unijeti mail adresu"; * TempData[Constants.ErrorOccurred] = true; * return View("Edit", model); * }*/ user.Email = model.EMail; user.Name = model.Name; user.Surname = model.Surname; user.Address = model.Address; user.City = city; user.UserName = model.EMail; user.NormalizedUserName = model.EMail.ToUpper(); user.NormalizedEmail = model.EMail.ToUpper(); user.Biography = model.Biography; user.ImagePath = model.ImagePath; var x = _databaseContext.User.Where(g => (g.Email == user.Email && g.Id != id)).ToList(); if (x.Count > 0) { TempData[Constants.Message] = $"Korisnik s tim mailom već postoji.\n"; TempData[Constants.ErrorOccurred] = true; return(View("Edit", model)); } TempData["Success"] = true; _databaseContext.SaveChanges(); TempData[Constants.Message] = $"Ljekarnik je promijenjen"; TempData[Constants.ErrorOccurred] = false; return(RedirectToAction(nameof(Index))); } else { ViewData["Cities"] = _databaseContext.City.OrderBy(p => p.CityPbr).ToList(); return(View("Edit", model)); } }
public async Task <IActionResult> Edit(EditDoctorViewModel model) { if (!ModelState.IsValid) { model.Specializations = _doctorService.GetSpecializations(); return(View(model)); } await _doctorService.EditDoctor(model); return(RedirectToAction("Details", new { id = model.Id })); }
public async Task <ActionResult> CreateDoctor(EditDoctorViewModel model, HttpPostedFileBase imageInp) { if (ModelState.IsValid) { ApplicationUser user = new ApplicationUser { UserName = model.Email, Email = model.Email, EmailConfirmed = true }; IdentityResult result = await UserManager.CreateAsync(user, model.Password); ApplicationUser applicationUser = UserManager.FindByEmail(user.Email); if (!result.Succeeded) { return(View("Error", result.Errors)); } if (result.Succeeded) { result = await UserManager.AddToRoleAsync(applicationUser.Id, "Doctors"); Doctor doctor = new Doctor() { Id = applicationUser.Id, Name = model.Name, Surname = model.Surname, Patronymic = model.Patronymic, DoctorPhone = model.DoctorPhone, SpecializationId = model.SpecializationId, GenderId = model.GenderId }; if (imageInp != null) { doctor.ImageMimeType = imageInp.ContentType; doctor.ImageData = new byte[imageInp.ContentLength]; imageInp.InputStream.Read(doctor.ImageData, 0, imageInp.ContentLength); } unitOfWork.Doctors.Create(doctor); return(RedirectToAction("Index", "AdminDoctors")); } else { AddErrorsFromResult(result); } } return(View(model)); }
public ActionResult EditDoctor(EditDoctorViewModel model) { var existingDoctor = DoctorServices.ClassObject.GetDoctor(model.ID); existingDoctor.Nume = model.Nume; existingDoctor.Prenume = model.Prenume; existingDoctor.Email = model.Email; existingDoctor.Telefon = model.Telefon; existingDoctor.CodParafa = model.CodParafa; existingDoctor.Cabinet = model.Cabinet; existingDoctor.Parola = model.Parola; DoctorServices.ClassObject.UpdateDoctor(existingDoctor); return(RedirectToAction("DoctorsTable")); }
public ActionResult EditDoctor(int ID) { EditDoctorViewModel model = new EditDoctorViewModel(); var doctor = DoctorServices.ClassObject.GetDoctor(ID); model.ID = doctor.ID; model.Nume = doctor.Nume; model.Prenume = doctor.Prenume; model.Email = doctor.Email; model.Telefon = doctor.Telefon; model.CodParafa = doctor.CodParafa; model.Cabinet = doctor.Cabinet; model.Parola = doctor.Parola; return(PartialView(model)); }
public ViewResult Edit(string id) { var user = _databaseContext.Doctor.FirstOrDefault(g => g.Id == id); ViewData["Cities"] = _databaseContext.City.OrderBy(p => p.CityPbr).ToList(); ViewData["Success"] = TempData["Success"]; var model = new EditDoctorViewModel { Address = user.Address, Biography = user.Biography, Education = user.Education, EMail = user.Email, ImagePath = user.ImagePath, Name = user.Name, Surname = user.Surname, Id = user.Id }; return(View(model)); }
public async Task EditDoctor(EditDoctorViewModel model) { var doctor = await _dbContext.Doctors.FirstOrDefaultAsync(x => x.Id == model.Id); if (doctor == null) { throw new ClinicException(ErrorCodes.ObjectNotFound); } doctor.Name = model.Name; doctor.Surname = model.Surname; doctor.Email = model.Email; doctor.Phone = model.Phone; doctor.Specialization = (Specialization)Enum.Parse(typeof(Specialization), model.Specialization); try { await _dbContext.SaveChangesAsync(); } catch (Exception ex) { throw new ClinicException(ErrorCodes.SavingChangesError, ex); } }
public EditDoctorView(MainViewModel mainVM, Doctor doctor) { InitializeComponent(); DataContext = new EditDoctorViewModel(mainVM, doctor); }
public ActionResult Edit(EditDoctorViewModel doctorViewModel, HttpPostedFileBase photo) { var id = Convert.ToInt32(Session["Id"]); var doctors = db.Doctors.Find(id); DateTime dateTime = doctors.Birthday ?? DateTime.Now; int shortDate = dateTime.Day; int shortMonth = dateTime.Month; int shortYear = dateTime.Year; DateTime createDate = doctors.CreateDate ?? DateTime.Now; int shortCreateDate = createDate.Day; int shortCreateMonth = createDate.Month; int shortCreateYear = createDate.Year; var detailProfile = new EditDoctorViewModel() { Id = doctors.Id, Firstname = doctors.Firstname, Lastname = doctors.Lastname, Email = doctors.Email, Phone = doctors.Phone ?? default(int), Address = doctors.Address, Gender = doctors.Gender, Day = shortDate, Month = shortMonth, Year = shortYear, DayCreateDate = shortCreateDate, MonthCreateDate = shortCreateMonth, YearCreateDate = shortCreateYear, Image = doctors.Image }; //////////////////////////////////////// // Đếm số bài viết của cá nhân List <Post> listPost = db.Posts.ToList(); var listPostView = listPost.Select(x => new PostViewModel { Id = x.Id, Doctor_ID = x.Doctor_ID, }).ToList(); ViewBag.listPost = listPostView; // count số like theo Id Post List <LikePost> likePosts = db.LikePosts.ToList(); ViewBag.listLikePost = likePosts; ///////////////////////////////////////////////////////////////////////////////////// var doctor = db.Doctors.SingleOrDefault(a => a.Id.Equals(doctorViewModel.Id)); if (photo != null) { if (!isValidContentType(photo.ContentType)) { ViewBag.Error = "Only JPG, JPEG, PNG & GIF files are allowed"; return(View(detailProfile)); } else if (!isValidContentLenght(photo.ContentLength)) { ViewBag.Error = "Your file is too large"; return(View(detailProfile)); } else { if (photo.ContentLength > 0) { // detele image old if (doctorViewModel.Image != null) { var filePathDetele = Server.MapPath("~/Content/Images/" + doctorViewModel.Image); if (System.IO.File.Exists(filePathDetele)) { System.IO.File.Delete(filePathDetele); } } // add image new var fileName = Path.GetFileName(photo.FileName); var path = Path.Combine(Server.MapPath("~/Content/images"), fileName); photo.SaveAs(path); doctor.Image = photo.FileName; Session["Img"] = photo.FileName.ToString(); } } } doctor.Firstname = doctorViewModel.Firstname; doctor.Lastname = doctorViewModel.Lastname; doctor.Phone = doctorViewModel.Phone; doctor.Email = doctorViewModel.Email; doctor.Address = doctorViewModel.Address; doctor.Birthday = new DateTime(doctorViewModel.Year, doctorViewModel.Month, doctorViewModel.Day); doctor.Gender = doctorViewModel.Gender; db.SaveChanges(); return(RedirectToAction("User/" + doctor.Id)); }
public ActionResult Edit(int id) { var doc = db.Doctors.SingleOrDefault(x => x.Id.Equals(id)); var count = db.Doctors.Count(e => e.Id.Equals(id)); if (count == 1) { if (doc.Id == Convert.ToInt32(Session["Id"])) { var doctor = db.Doctors.Find(id); DateTime dateTime = doctor.Birthday ?? DateTime.Now; int shortDate = dateTime.Day; int shortMonth = dateTime.Month; int shortYear = dateTime.Year; DateTime createDate = doctor.CreateDate ?? DateTime.Now; int shortCreateDate = createDate.Day; int shortCreateMonth = createDate.Month; int shortCreateYear = createDate.Year; var detailProfile = new EditDoctorViewModel() { Id = doctor.Id, Firstname = doctor.Firstname, Lastname = doctor.Lastname, Email = doctor.Email, Phone = doctor.Phone ?? default(int), Address = doctor.Address, Gender = doctor.Gender, Day = shortDate, Month = shortMonth, Year = shortYear, DayCreateDate = shortCreateDate, MonthCreateDate = shortCreateMonth, YearCreateDate = shortCreateYear, Image = doctor.Image }; //////////////////////////////////////// // Đếm số bài viết của cá nhân List <Post> listPost = db.Posts.ToList(); var listPostView = listPost.Select(x => new PostViewModel { Id = x.Id, Doctor_ID = x.Doctor_ID, }).ToList(); ViewBag.listPost = listPostView; // count số like theo Id Post List <LikePost> likePosts = db.LikePosts.ToList(); ViewBag.listLikePost = likePosts; return(View(detailProfile)); } else { ViewBag.thongbao = "Người dùng được yêu cầu không thể được tìm thấy"; return(View("Notification")); } } else { ViewBag.thongbao = "Người dùng được yêu cầu không thể được tìm thấy"; return(View("Notification")); } }
public async Task <ActionResult> EditDoctor(EditDoctorViewModel editDoctorViewModel, HttpPostedFileBase imageInp) { ApplicationUser user = await UserManager.FindByIdAsync(editDoctorViewModel.Id); if (user != null) { user.Email = editDoctorViewModel.Email; IdentityResult validEmail = await UserManager.UserValidator.ValidateAsync(user); if (!validEmail.Succeeded) { AddErrorsFromResult(validEmail); } IdentityResult validPass = null; if (editDoctorViewModel.Password != null) { validPass = await UserManager.PasswordValidator.ValidateAsync(editDoctorViewModel.Password); if (validPass.Succeeded) { user.PasswordHash = UserManager.PasswordHasher.HashPassword(editDoctorViewModel.Password); } else { AddErrorsFromResult(validPass); } } IdentityResult result = null; if ((validEmail.Succeeded && validPass == null) || (validEmail.Succeeded && editDoctorViewModel.Password != string.Empty && validPass.Succeeded)) { user.UserName = editDoctorViewModel.Email; result = await UserManager.UpdateAsync(user); } Doctor doctor = unitOfWork.Doctors.FindById(editDoctorViewModel.Id); doctor.Name = editDoctorViewModel.Name; doctor.Surname = editDoctorViewModel.Surname; doctor.Patronymic = editDoctorViewModel.Patronymic; doctor.DoctorPhone = editDoctorViewModel.DoctorPhone; doctor.SpecializationId = editDoctorViewModel.SpecializationId; doctor.GenderId = editDoctorViewModel.GenderId; if (imageInp != null) { doctor.ImageMimeType = imageInp.ContentType; doctor.ImageData = new byte[imageInp.ContentLength]; imageInp.InputStream.Read(doctor.ImageData, 0, imageInp.ContentLength); } unitOfWork.Doctors.Update(doctor); if (result != null) { if (result.Succeeded) { return(RedirectToAction("Index")); } else { AddErrorsFromResult(result); } } } else { ModelState.AddModelError("", "Пользователь не найден"); } return(View(user)); }