public IActionResult UpdateDoctor(UpdateDoctorRequest request, int idDoctor) { var doctor = new Doctor { IdDoctor = idDoctor }; _context.Attach(doctor); if (request.FirstName != null) { doctor.FirstName = request.FirstName; _context.Entry(doctor).Property("FirstName").IsModified = true; } if (request.LastName != null) { doctor.LastName = request.LastName; _context.Entry(doctor).Property("LastName").IsModified = true; } if (request.Email != null) { doctor.Email = request.Email; _context.Entry(doctor).Property("Email").IsModified = true; } _context.SaveChanges(); string uri = $"/api/doctors/{doctor.IdDoctor}"; return(Created(uri, doctor)); }
public IActionResult updateDoctor(int id, CreateDoctorDtoRequest doctor) { if (!_db.Doctors.Any(d => d.IdDoctor == id)) { return(NotFound("Doktor o podanym numerze id nie istnieje.")); } if (string.IsNullOrEmpty(doctor.FirstName) || string.IsNullOrEmpty(doctor.LastName) || string.IsNullOrEmpty(doctor.Email)) { return(BadRequest("Jedna z przekazanych wartoĊci jest pusta.")); } Doctor d = new Doctor { IdDoctor = id, FirstName = doctor.FirstName, LastName = doctor.LastName, Email = doctor.Email }; _db.Attach(d); _db.Entry(d).Property("FirstName").IsModified = true; _db.Entry(d).Property("LastName").IsModified = true; _db.Entry(d).Property("Email").IsModified = true; _db.SaveChanges(); return(Ok()); }
public void UpdateDoctor(int id, Doctor doctor) { doctor.IdDoctor = id; _context.Doctor.Attach(doctor); _context.Entry(doctor).State = EntityState.Modified; _context.SaveChanges(); }
public string Put() { DanpheHTTPResponse <object> responseData = new DanpheHTTPResponse <object>(); RbacUser currentUser = HttpContext.Session.Get <RbacUser>("currentuser"); try { string reqType = this.ReadQueryStringData("reqType"); string ipStr = this.ReadPostData(); DoctorsDbContext dbContext = new DoctorsDbContext(connString); if (reqType == "updatePatientData") { List <VisitSummaryModel> patDataList = DanpheJSONConvert.DeserializeObject <List <VisitSummaryModel> >(ipStr); patDataList.ForEach(data => { data.ModifiedOn = DateTime.Now; data.ModifiedBy = currentUser.CreatedBy; dbContext.Entry(data).State = EntityState.Modified; dbContext.Entry(data).Property(u => u.CreatedBy).IsModified = false; dbContext.Entry(data).Property(u => u.CreatedOn).IsModified = false; }); dbContext.SaveChanges(); responseData.Results = patDataList; } responseData.Status = "OK"; } catch (Exception ex) { responseData.Status = "Failed"; responseData.ErrorMessage = ex.Message + " exception details:" + ex.ToString(); } return(DanpheJSONConvert.SerializeObject(responseData, true)); }
public Doctor UpdateDoctor(int id, Doctor doctor) { var result = _context.Doctor.Where(d => d.IdDoctor == id).FirstOrDefault(); if (result == null) { throw new DoctorNotFoundException(); } try { _context.Entry(result).CurrentValues.SetValues(doctor); _context.SaveChanges(); return(doctor); } catch (DbEntityValidationException exc) { // TODO should have details throw new DoctorValidationException(); } }