public IActionResult AddSocialServiceBenefit(AddSocialServiceBenefitModel model) { model.SocialServiceKindList = new SelectList(benefitService.GetSocialServiceKinds(), "Id", "Value"); model.BenefitTypeList = new SelectList(benefitService.GetBenefitsTypes(), "Id", "Value", 2); if (!ModelState.IsValid) { return(View(model)); } model.Relatives = relativesModel; var newBenefit = new SocialServiceBenefit() { AdditionInformation = model.AdditionInformation, BeneficiaryAddress = model.BeneficiaryAddress, BeneficiaryName = model.BeneficiaryName, BeneficiaryPhoneNumber = model.BeneficiaryPhoneNumber, AverageIncome = model.AverageIncome, BenefitStatus = dictionaryService.Get <BenefitStatus>((int)eBenefitStatus.Passed), BenefitType = dictionaryService.Get <BenefitType>((int)eBenefitType.SocialServiceBenefit), DateOfEmployment = model.DateOfEmployment.Value, OtherSocialServiceKind = model.OtherSocialServiceKind, Position = model.Position, SocialServiceKind = dictionaryService.Get <SocialServiceKind>(model.SocialServiceKind.Id), SubmittingDate = DateTime.Now, SubmittingUser = userManager.GetUserAsync(User).Result, BenefitNumber = benefitService.GenerateBenefitNumber((int)eBenefitType.SocialServiceBenefit), Year = model.Year }; try { socialServiceBenefitService.CreateBenefit(newBenefit); if (model.Relatives.Any()) { var relatives = mapper.Map <List <RelativesModel>, List <Relatives> >(model.Relatives); socialServiceBenefitService.AddRelatives(relatives, newBenefit); } TempData["BenefitAddSuccess"] = newBenefit.BenefitNumber.ToString(); TempData["BenefitNumber"] = newBenefit.BenefitNumber.ToString(); relativesModel.Clear(); return(RedirectToAction("Index")); } catch (Exception ex) { TempData["BenefitAddError"] = ex.Message; return(View(model)); } }
public IActionResult AddSocialServiceBenefit() { TempData["BenefitAddError"] = "Error"; TempData["BenefitAddSuccess"] = "Success"; relativesModel.Clear(); var model = new AddSocialServiceBenefitModel() { BenefitTypeList = new SelectList(benefitService.GetBenefitsTypes(), "Id", "Value", 2), SocialServiceKindList = new SelectList(benefitService.GetSocialServiceKinds(), "Id", "Value"), }; return(View(model)); }