public async Task <IActionResult> UpdateProfile(TutorProfileForEditDto model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _response = await _repo.UpdateProfile(model); return(Ok(_response)); }
public async Task <ServiceResponse <object> > UpdateProfile(TutorProfileForEditDto model) { try { var ObjToUpdate = _context.TutorProfiles.FirstOrDefault(s => s.Id.Equals(model.Id)); if (ObjToUpdate != null) { ObjToUpdate.About = model.About; //ObjToUpdate.GradeLevels = string.Join(',', model.GradeLevels); ObjToUpdate.AreasToTeach = model.AreasToTeach; ObjToUpdate.CityId = model.CityId; ObjToUpdate.CommunicationSkillRate = model.CommunicationSkillRate; ObjToUpdate.Education = model.Education; ObjToUpdate.LanguageFluencyRate = model.LanguageFluencyRate; ObjToUpdate.WorkExperience = model.WorkExperience; ObjToUpdate.WorkHistory = model.WorkHistory; _context.TutorProfiles.Update(ObjToUpdate); await _context.SaveChangesAsync(); _serviceResponse.Message = CustomMessage.Updated; _serviceResponse.Success = true; } } catch (DbUpdateException ex) { if (ex.InnerException.Message.Contains("Cannot insert duplicate key row")) { _serviceResponse.Success = false; _serviceResponse.Message = CustomMessage.SqlDuplicateRecord; } else { throw ex; } } return(_serviceResponse); }