public async Task <IActionResult> EditAgentProfile(string userName, EditAgent editedAgent) { if (userName == null || !ModelState.IsValid) { return(BadRequest()); } var userInaspNetTable = await aspUserManager.FindByNameAsync(userName); var agent = agentManager .GetAllWithInclude(a => a.Job, a => a.AspNetUsersId == userInaspNetTable.Id).FirstOrDefault(); if (agent.ImagePath != editedAgent.EditAgentInfo.ImagePath) { editedAgent.EditAgentInfo.ImagePath = UploadToCloudinary.UploadImageToCloudinary(editedAgent.EditAgentInfo.ImagePath); } mapper.Map(editedAgent.EditAgentInfo, agent); var agentEditedSkills = skillManager .GetAll() .Where(s => editedAgent.EditSkills.ToList().Select(a => a.Name).Contains(s.Name)) .Select(s => s.Id) .ToList(); var agentSkillsInDb = agentSkillManager .GetAll() .Where(s => s.AgentId == agent.Id) .ToList(); UpdateAgentSkills(agentEditedSkills, agentSkillsInDb); agentManager.Complete(); return(Ok()); }