public async Task <IActionResult> AddProfile(TutorProfileForAddDto model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _response = await _repo.AddProfile(model); return(Ok(_response)); }
public async Task <ServiceResponse <object> > AddProfile(TutorProfileForAddDto model) { var ToUpdate = await _context.TutorProfiles.Where(m => m.CreatedById == _LoggedIn_UserID).FirstOrDefaultAsync(); if (ToUpdate != null) { ToUpdate.About = model.About; ToUpdate.AreasToTeach = model.AreasToTeach; ToUpdate.CityId = model.CityId; ToUpdate.CommunicationSkillRate = model.CommunicationSkillRate; ToUpdate.Education = model.Education; ToUpdate.LanguageFluencyRate = model.LanguageFluencyRate; ToUpdate.WorkExperience = model.WorkExperience; ToUpdate.WorkHistory = model.WorkHistory; _context.TutorProfiles.Update(ToUpdate); await _context.SaveChangesAsync(); } else { var ToAdd = new TutorProfile { About = model.About, AreasToTeach = model.AreasToTeach, CityId = model.CityId, CommunicationSkillRate = model.CommunicationSkillRate, Education = model.Education, LanguageFluencyRate = model.LanguageFluencyRate, WorkExperience = model.WorkExperience, WorkHistory = model.WorkHistory, //GradeLevels = string.Join(',', model.GradeLevels), Active = true, SchoolBranchId = _LoggedIn_BranchID, CreatedById = _LoggedIn_UserID, CreatedDateTime = DateTime.UtcNow, }; await _context.TutorProfiles.AddAsync(ToAdd); await _context.SaveChangesAsync(); } _serviceResponse.Message = CustomMessage.Added; _serviceResponse.Success = true; return(_serviceResponse); }