public IActionResult AddpointFieldToExperienceView(string expGrpId) { var activeUserId = _userManager.GetUserId(User); var userInfoId = _userInfoRepo.Read(activeUserId).UserInformationId; if (!ModelState.IsValid) { return(ViewComponent("ExperienceEditDisplay", new { userInfoId = userInfoId })); } var exp = _experienceRepo.Read(expGrpId); if (exp.UserInformationId != userInfoId) { Response.StatusCode = 403; ViewBag.ErrorTitle = "Wrong user"; ViewBag.ErrorMessage = "Unauthorized edit attempt was made"; return(View("Error")); } var expPointCount = exp.ExperiencePoints.Count; var maxLimit = _config.GetValue <int>("ExperienceDBLimits:ExperienceHighLightMaxLimit"); if (expPointCount >= maxLimit) { ModelState.AddModelError("", $"You have exceeded the maximum({maxLimit}) amount of experience point sections you can make."); return(ViewComponent("ExperienceEditDisplay", new { userInfoId = userInfoId })); } var newExpPoint = new ExperiencePoint { Id = Guid.NewGuid().ToString(), Index = expPointCount, Title = "" }; newExpPoint.Descriptions = new List <ExperiencePointDescription>(); newExpPoint.Descriptions.Add(new ExperiencePointDescription { Id = Guid.NewGuid().ToString(), Index = 0, Discription = "" }); exp.ExperiencePoints.Add(newExpPoint); _experienceRepo.Update(exp); return(ViewComponent("ExperienceEditDisplay", new { userInfoId = userInfoId })); }
public ActionResult Edit(ExperienceVM model) { try { if (!ModelState.IsValid) { return(View(model)); } var experience = _mapper.Map <Experience>(model); var updated = _repo.Update(experience); if (!updated) { ModelState.AddModelError("", "Something went wrong"); return(View()); } return(RedirectToAction(nameof(Index))); } catch { ModelState.AddModelError("", "Something went wrong"); return(View()); } }