public async Task <ConsultantResponse> UpdateAsync(int id, Consultant consultant) { var existingConsultant = await _consultantRepository.FindById(id); if (existingConsultant == null) { return(new ConsultantResponse("Consultant not found")); } existingConsultant.UserName = consultant.UserName; existingConsultant.Password = consultant.Password; existingConsultant.FirstName = consultant.FirstName; existingConsultant.LastName = consultant.LastName; existingConsultant.Cellphone = consultant.Cellphone; existingConsultant.Email = consultant.Email; existingConsultant.LinkedinLink = consultant.LinkedinLink; try { _consultantRepository.Update(existingConsultant); await _unitOfWork.CompleteAsync(); return(new ConsultantResponse(existingConsultant)); } catch (Exception ex) { return(new ConsultantResponse($"An error ocurred while updating consultant: {ex.Message}")); } }
public IActionResult UpdateConsultant([FromBody] Consultant model) { if (!ModelState.IsValid) { return(new OkObjectResult("Invalid Model")); } con_repo.Update(model); return(new OkObjectResult(new { ConsultantId = model.ConsultantId })); }
public async Task <ConsultantResponse> UpdateAsync(int id, Consultant consultant) { var existingConsultant = await _consultantRepository.GetById(id); if (existingConsultant == null) { return(new ConsultantResponse("was not found.")); } existingConsultant.FirstName = consultant.FirstName; existingConsultant.LastName = consultant.LastName; existingConsultant.PersonalID = consultant.PersonalID; existingConsultant.RecommendatoryID = consultant.RecommendatoryID; existingConsultant.Gender = consultant.Gender; existingConsultant.BirthDate = consultant.BirthDate; var rec = await _consultantRepository.GetById(existingConsultant.RecommendatoryID); //Check recommendatory: if (rec == null || existingConsultant.ID == existingConsultant.RecommendatoryID || rec.RecommendatoryID == existingConsultant.ID) { return(new ConsultantResponse("Recommendatory error!!!")); } try { _consultantRepository.Update(existingConsultant); await _unitOfWork.CompleteAsync(); return(new ConsultantResponse(existingConsultant)); } catch (Exception ex) { // Do some logging stuff return(new ConsultantResponse($"An error occurred when updating the Consultant: {ex.Message}")); } }