public void UpdateDoctor(UpdateDoctorRequest request, int id) { var doctor = new Doctor(); doctor.IdDoctor = id; _context.Attach(doctor); var firstName = request.FirstName; var lastName = request.LastName; var email = request.Email; var entry = _context.Entry(doctor); if (firstName != null) { doctor.FirstName = firstName; entry.Property("FirstName").IsModified = true; } if (lastName != null) { doctor.LastName = lastName; entry.Property("LastName").IsModified = true; } if (email != null) { doctor.Email = email; entry.Property("Email").IsModified = true; } _context.SaveChanges(); }
public HelperRequest UpdateDoctor(UpdateDoctorRequest request) { var helper = new HelperRequest(); var countDoctor = _context.Doctors.Count(doc => doc.LastName == request.LastName && doc.FirstName == request.FirstName); if (countDoctor == 0) { helper.Number = 0; return(helper); } var doctor = new Doctor { FirstName = request.FirstName, LastName = request.LastName, Email = request.Email, }; _context.Attach(doctor); _context.Entry(doctor).Property("FirstName").IsModified = true; _context.Entry(doctor).Property("LastName").IsModified = true; _context.Entry(doctor).Property("Email").IsModified = true; _context.SaveChangesAsync(); helper.Number = 1; return(helper); }
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 async Task <IActionResult> PutAsync(UpdateDoctorRequest request, CancellationToken cancellationToken) { _logger.LogInformation("Patients/Put was requested."); var response = await unitOfWork.Doctors.UpdateAsync(_mapper.Map <DoctorDTO>(request)); unitOfWork.Save(); return(Ok(_mapper.Map <DoctorResponce>(response))); }
public Doctor Update(Doctor doctor) { var request = new UpdateDoctorRequest(); request.Doctor = doctor; var response = HttpPost <UpdateDoctorRequest>("api/doctor/update", request, MediaType.Json); return(doctor); }
public IActionResult UpdateDoctor([FromRoute] int id, [FromBody] UpdateDoctorRequest newDoctorRequest) { var modifiedEntries = _dbService.UpdateDoctor(id, newDoctorRequest); if (modifiedEntries == 0) { return(BadRequest("No entries were modified, probably wrong ID was requested.")); } return(Ok($"{modifiedEntries} entries changed.")); }
public IActionResult UpdateDoctor(int id, UpdateDoctorRequest request) { var doc = _context.Doctors.Where(d => d.IdDoctor == id).FirstOrDefault(); doc.FirstName = request.FirstName; doc.LastName = request.LastName; doc.Email = request.Email; _context.SaveChanges(); return(Ok("Updated")); }
public IActionResult UpdateDoctor(UpdateDoctorRequest request) { if (dbService.UpdateDoctor(request)) { return(Ok("DOCTOR DATA WAS UPDATED")); } else { return(BadRequest("WRONG DATA")); } }
public IActionResult UpdateDoctor(UpdateDoctorRequest req) { try { return(Ok(_service.UpdateDoctor(req))); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IActionResult UpdateDoctor(UpdateDoctorRequest updateDoctorRequest) { HelperRequest helper = _context.UpdateDoctor(updateDoctorRequest); switch (helper.Number) { case 0: return(BadRequest("Doctor with this Name and Lastname not exist")); default: return(Ok("Doctor modify")); } }
public int UpdateDoctor(int id, UpdateDoctorRequest newDoctorRequest) { var doctor = GetDoctor(id); if (doctor == null) { return(0); } doctor.FirstName = newDoctorRequest.FirstName ?? doctor.FirstName; doctor.LastName = newDoctorRequest.LastName ?? doctor.LastName; doctor.Email = newDoctorRequest.Email ?? doctor.Email; return(_context.SaveChanges()); }
public void delete(UpdateDoctorRequest request) { try { var response = new UpdateDoctorResponse(); var bc = new DoctorComponent(); bc.Update(request.Doctor); } catch (Exception ex) { var httpError = new HttpResponseMessage() { StatusCode = (HttpStatusCode)422, ReasonPhrase = ex.Message }; throw new HttpResponseException(httpError); } }
public Doctor UpdateDoctor(UpdateDoctorRequest request) { var doctor = _hospitalContext.Doctors.FirstOrDefault(d => d.IdDoctor == request.IdDoctor); if (doctor != null) { doctor.FirstName = request.FirstName; doctor.LastName = request.LastName; doctor.Email = request.Email; _hospitalContext.Update(doctor); _hospitalContext.SaveChanges(); return(doctor); } else { return(null); } }
public Doctor UpdateDoctor(UpdateDoctorRequest request) { var d = _db.Doctor.Where(e => e.IdDoctor == request.IdDoctor).FirstOrDefault(); if (d != null) { d.FirstName = request.FirstName; d.LastName = request.LastName; d.Email = request.Email; _db.Update(d); _db.SaveChanges(); return(d); } else { return(null); } }
public bool UpdateDoctor(UpdateDoctorRequest request) { try { var el = dbContext.Doctors.Where(e => e.IdDoctor == request.IdDoctor).FirstOrDefault(); if (el == null) { return(false); } el.FirstName = request.FirstName; el.LastName = request.LastName; el.Email = request.Email; dbContext.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
public IActionResult UpdateDoctor(int id, UpdateDoctorRequest request) { var doctor = _context.Doctor.SingleOrDefault(d => d.IdDoctor == id); if (doctor == null) { return(BadRequest("Doctor nie istnieje")); } _context.Attach(doctor); if (request.IdDoctor != null) { doctor.IdDoctor = request.IdDoctor.Value; _context.Entry(doctor).Property("IdDoctor").IsModified = true; } if (request.FirstName != null) { doctor.FirstName = request.FirstName; _context.Entry(doctor).Property("FirstName").IsModified = true; } if (request.LastName != null) { doctor.FirstName = request.LastName; _context.Entry(doctor).Property("LastName").IsModified = true; } if (request.Email != null) { doctor.Email = request.Email; _context.Entry(doctor).Property("Email").IsModified = true; } if (request.Prescriptions != null) { doctor.Prescriptions = request.Prescriptions; _context.Entry(doctor).Property("Prescriptions").IsModified = true; } _context.SaveChanges(); return(Ok("Aktualizacja ukończona")); }
private async Task SaveClick() { if (ToSave.DoctorId == 0) { var toCreate = new CreateDoctorRequest() { Name = ToSave.Name, }; await DoctorService.CreateAsync(toCreate); } else { var toUpdate = new UpdateDoctorRequest() { DoctorId = ToSave.DoctorId, Name = ToSave.Name, }; await DoctorService.EditAsync(toUpdate); } CancelClick(); await ReloadData(); }
public void UpdateDoctor(UpdateDoctorRequest request) { var doctor = new Doctor { IdDoctor = request.IdDoctor }; DbContext.Attach(doctor); if (request.FirstName != null) { doctor.FirstName = request.FirstName; DbContext.Entry(doctor).Property("FirstName").IsModified = true; } if (request.LastName != null) { doctor.LastName = request.LastName; DbContext.Entry(doctor).Property("LastName").IsModified = true; } if (request.Email != null) { doctor.Email = request.Email; DbContext.Entry(doctor).Property("Email").IsModified = true; } DbContext.SaveChanges(); }
public Doctor UpdateDoctor(UpdateDoctorRequest req) { var doc = _context.Doctors.Find(req.IdDoctor); if (doc == null) { throw new Exception("nie znaleziono doktora"); } if (req.FirstName != null) { doc.FirstName = req.FirstName; } if (req.LastName != null) { doc.LastName = req.LastName; } if (req.Email != null) { doc.Email = req.Email; } if (req.Prescriptions != null) { foreach (Prescription p in req.Prescriptions) { doc.Prescriptions.Add(p); } } _context.SaveChanges(); return(doc); }
public async Task <DoctorDto> EditAsync(UpdateDoctorRequest doctor) { return((await _httpService.HttpPutAsync <UpdateDoctorResponse>("doctors", doctor)).Doctor); }
public IActionResult UpdateDoctor(UpdateDoctorRequest request, int id) { _service.UpdateDoctor(request, id); return(Ok()); }
public IActionResult UpdateDoctor(UpdateDoctorRequest request) { _dbService.UpdateDoctor(request); return(Ok()); }
public IActionResult UpdateDoctor(UpdateDoctorRequest request) { return(Ok(_service.UpdateDoctor(request))); }