Example #1
0
 public void AddRelatives(List <Relatives> relatives, SocialServiceBenefit benefit)
 {
     if (relatives.Any())
     {
         relatives.ForEach(x => x.SocialServiceBenefits = benefit);
         applicationDbContext.Relatives.AddRange(relatives);
         applicationDbContext.SaveChanges();
     }
 }
Example #2
0
        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));
            }
        }
Example #3
0
        public virtual IActionResult EditSocialServiceBenefit(SocialServiceBenefitModel model)
        {
            model.SocialServiceKindList = new SelectList(benefitService.GetSocialServiceKinds(), "Id", "Value");
            model.BenefitTypeList       = new SelectList(benefitService.GetBenefitsTypes(), "Id", "Value", 2);

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var benefit = new SocialServiceBenefit
            {
                Id = benefitId,
                BeneficiaryAddress     = model.BeneficiaryAddress,
                BeneficiaryName        = model.BeneficiaryName,
                BeneficiaryPhoneNumber = model.BeneficiaryPhoneNumber,
                DateOfEmployment       = model.DateOfEmployment,
                Position = model.Position,
                OtherSocialServiceKind = model.OtherSocialServiceKind,
                SocialServiceKind      = dictionaryService.Get <SocialServiceKind>(model.SocialServiceKind.Id),
                AverageIncome          = model.AverageIncome,
                AdditionInformation    = model.AdditionInformation,
                Year = model.Year,
            };

            try
            {
                socialServiceBenefitService.UpdateBenefitData(benefit);
                var relatives = mapper.Map <List <RelativesModel>, List <Relatives> >(relativesModel);
                if (relatives.Any())
                {
                    socialServiceBenefitService.UpdateRelatives(relatives, benefit.Id);
                    relativesModel.Clear();
                }

                TempData["Edit"]          = benefitNumber;
                TempData["BenefitNumber"] = benefitNumber;
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                TempData["Edit"] = ex.Message;
                return(View(model));
            }
        }
Example #4
0
        public void UpdateBenefitData(SocialServiceBenefit benefit)
        {
            var benefitToUpdate = GetBenefit(benefit.Id);

            benefitToUpdate.BeneficiaryAddress     = benefit.BeneficiaryAddress;
            benefitToUpdate.BeneficiaryName        = benefit.BeneficiaryName;
            benefitToUpdate.BeneficiaryPhoneNumber = benefit.BeneficiaryPhoneNumber;
            benefitToUpdate.DateOfEmployment       = benefit.DateOfEmployment;
            benefitToUpdate.Position = benefit.Position;
            benefitToUpdate.OtherSocialServiceKind = benefit.OtherSocialServiceKind;
            benefitToUpdate.SocialServiceKind      = dictionaryService.Get <SocialServiceKind>(benefit.SocialServiceKind.Id);
            benefitToUpdate.AverageIncome          = benefit.AverageIncome;
            benefitToUpdate.AdditionInformation    = benefit.AdditionInformation;
            benefitToUpdate.Year = benefit.Year;

            applicationDbContext.Entry(benefitToUpdate).State = EntityState.Modified;
            applicationDbContext.SaveChanges();
        }
Example #5
0
 public List <Relatives> GetRelatives(SocialServiceBenefit benefit)
 {
     return(applicationDbContext.Relatives.Where(x => x.SocialServiceBenefits == benefit).ToList());
 }
Example #6
0
 public void CreateBenefit(SocialServiceBenefit benefit)
 {
     applicationDbContext.SocialServiceBenefit.Add(benefit).State = EntityState.Added;
     applicationDbContext.SaveChanges();
 }