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 Doctor AddDoctor(Doctor doctor) { db.Attach(doctor); db.Entry(doctor).State = EntityState.Added; db.SaveChanges(); return(doctor); }
public IActionResult UpdateDoctor(Doctor doctor) { try { context.Attach(doctor); context.SaveChanges(); return(Ok("Doktor został zmodyfikowany")); } catch (Exception ex) { return(BadRequest(ex.Message)); } }