// Update a doctor public bool Update(TM_Doctor entity) { try { var doctor = db.TM_Doctor.Find(entity.Id); doctor.IdentityCard = entity.IdentityCard; doctor.Major = entity.Major; doctor.UserId = entity.UserId; db.SaveChanges(); return(true); } catch (Exception) { //logging return(false); } }
// Get doctor profile detail public DoctorProfile GetDoctorProfile(int userId) { // Find patient account var user = db.TM_Users.Find(userId); if (user == null) { return(null); } var doctor = db.TM_Doctor.Where(p => p.UserId == userId).FirstOrDefault(); if (doctor == null) { doctor = new TM_Doctor() { Major = string.Empty, IdentityCard = string.Empty }; } // Find var model = new DoctorProfile(); model.Id = user.Id; model.UserName = user.UserName; model.FullName = user.FullName; model.Gender = user.Gender; model.Avatar = user.Avatar; model.DoB = user.DateOfBirth; model.Email = user.Email; model.PhoneNumber = user.PhoneNumber; model.Major = doctor.Major; model.IdentityCard = doctor.IdentityCard; model.Addresses = GetAddresses(userId); return(model); }
// Insert new doctor public int Insert(TM_Doctor doctor) { db.TM_Doctor.Add(doctor); db.SaveChanges(); return(doctor.Id); }
public ActionResult Update(DoctorProfile model, IList <AddressDetail> addr) { if (addr != null) { model.Addresses = addr; // Assign AddressDetail list to PatientProfile model } else { model.Addresses = null; } if (ModelState.IsValid) { int userid = User.Identity.GetUserId <int>(); ApplicationUser user = UserManager.FindById(userid); if (user == null) { ViewBag.Errors = "Không thấy bệnh nhân này"; return(RedirectToAction("Detail", "DoctorProfile", new { Message = ProfileMessageId.Error })); } // Update account data user.Email = model.Email; user.DateOfBirth = model.DoB; user.FullName = model.FullName; user.PhoneNumber = model.PhoneNumber; user.Gender = model.Gender; var updateacc = UserManager.Update(user); if (!updateacc.Succeeded) { ViewBag.Errors = "Không cập nhật được account"; return(View("Detail", model)); } // Update profile data TM_Doctor doctor = new DoctorDao().FindByUserId(userid); if (doctor == null) { doctor = new TM_Doctor(); doctor.UserId = userid; doctor.Major = model.Major; doctor.IdentityCard = model.IdentityCard; if (new DoctorDao().Insert(doctor) < 1) { ViewBag.Errors = "Không thêm được profile"; return(View("Detail", model)); } } else { doctor.Major = model.Major; doctor.IdentityCard = model.IdentityCard; if (!new DoctorDao().Update(doctor)) { ViewBag.Errors = "Không cập nhật được profile"; return(View("Detail", model)); } } return(RedirectToAction("Detail", new { message = ProfileMessageId.ChangeAccountSuccess })); } return(View("Detail", model)); }