public async Task<IActionResult> Update([FromBody] EditDoctorDto doctor) { var listError = ValidPropertiesObject.ObjIsValid(doctor); if (listError.Count > 0) return await ResponseNullOrEmpty(listError); var result = _serviceDoctor.Update(doctor); return await Response(result, _serviceDoctor.Validate()); }
public Doctor Update(EditDoctorDto doctor) { var user = _service.Get(doctor.UserId); user.ChangeNickname(doctor.Nickname); user.ChangePermission((EPermission)doctor.Permission); var doctorTmp = new Doctor(doctor.Id, doctor.Name, doctor.Specialty, doctor.CodeRegister, user, doctor.Enabled); if (doctorTmp.Valid) { _repository.Update(doctorTmp); } return(doctorTmp); }
public void Edit([FromBody] EditDoctorDto doctorDto) { using (var dbContext = new ApplicationDbContext()) { var userId = GetUserId(); Clinic_Doctor doctorToUpdate = dbContext.Clinic_Doctors.FirstOrDefault(d => d.Id == doctorDto.Id && d.UserId == userId); if (doctorToUpdate == null) { throw new BadRequestException(ExceptionMessages.BadRequest); } ValidateDoctorData(dbContext, userId, doctorDto.SpecialtyId, doctorDto.SubspecialtyId, doctorDto.WorkingHours); doctorToUpdate.FirstName = doctorDto.FirstName; doctorToUpdate.LastName = doctorDto.LastName; doctorToUpdate.Email = doctorDto.Email; doctorToUpdate.PhoneNumber = doctorDto.PhoneNumber; doctorToUpdate.SpecialtyId = doctorDto.SpecialtyId; doctorToUpdate.SubspecialtyId = doctorDto.SubspecialtyId; doctorToUpdate.ConsultationLength = doctorDto.ConsultationLength; doctorToUpdate.WorkingHours.ForEach(wh => dbContext.Entry(wh).State = EntityState.Deleted); var newWorkingHours = doctorDto.WorkingHours.Select(wh => new Clinic_WorkingHours { DayNumber = wh.DayNumber, Start = wh.Start, End = wh.End }).ToList(); doctorToUpdate.WorkingHours = newWorkingHours; dbContext.SaveChanges(); } }