public IActionResult CreateOrUpdate(CandidateCreateModel model) { if (ModelState.IsValid) { if (model.Foto != null) { var uniqueFileName = GetUniqueFileName(model.Foto.FileName); var uploads = Path.Combine(appEnvironment.WebRootPath, "uploads"); var filePath = Path.Combine(uploads, uniqueFileName); model.Foto.CopyTo(new FileStream(filePath, FileMode.Create)); model.FotoURL = filePath; } var entity = mapper.Map <Candidate>(model); foreach (var item in model.SkillsId) { var skill = skillManager.Get(item); (entity.Skills as List <Skill>).Add(skill); } entity.Creator = userManager.GetByLogin(User.Identity.Name); if (entity.Id == 0) { candidateManager.Create(entity); } else { candidateManager.Update(entity); } } return(RedirectToAction("Index", "Home")); }
///<inheritdoc/> public CandidateDTO Create(CreateCandidateDTO createCandidateDTO) { var candidate = mapper.Map <Candidate>(createCandidateDTO); candidate.User = userManager.Get(createCandidateDTO.UserName); var entity = candidateManager.Create(candidate); return(mapper.Map <CandidateDTO>(entity)); }