Beispiel #1
0
        public ActionResult SendEmployeeBenefitSetting(int id)
        {
            BenefitSetting         benefitSetting = BenefitSettingsRepository.GetById(id);
            IEnumerable <Employee> employees      = EmployeeRepository.GetAll().Where(x => x.IsActive);

            return(PartialView(new SendEmployeeBenefitSettingModel(benefitSetting, employees)));
        }
        public BenefitSetting Update(BenefitSetting entity)
        {
            entity.ModifiedByDate = DateTime.Now;
            entity.ModifiedById   = Utils.GetCurrentUserId();

            foreach (var discount in entity.Discounts)
            {
                discount.ModifiedByDate = DateTime.Now;
                discount.ModifiedById   = Utils.GetCurrentUserId();

                // check if this is a newly added record by checing if create date is datetime.min.
                if (discount.CreateDate == DateTime.MinValue)
                {
                    discount.CreateDate  = DateTime.Now;
                    discount.CreatedById = Utils.GetCurrentUserId();
                }
            }

            DB.SaveChanges();

            return(DB.db.BenefitSettings
                   .Include(x => x.CreatedByUser)
                   .Include(x => x.ModifiedByUser)
                   .FirstOrDefault(x => x.Id == entity.Id));
        }
        public ActionResult Index(string token, string employeeAccessToken)
        {
            BenefitSetting entity   = BenefitSettingsRepository.GetByToken(token) ?? BenefitSettingsRepository.GetDefault();
            Employee       employee = EmployeeRepository.GetByAccessCode(employeeAccessToken);

            return(View(new IndexModel(entity, employee)));
        }
Beispiel #4
0
 public SendEmployeeBenefitSettingModel(BenefitSetting benefitSetting, IEnumerable <Employee> employees)
 {
     BenefitSettingId = benefitSetting.Id;
     Name             = benefitSetting.Name;
     Message          = "Hey check out these benefits I sent you.";
     Populate(employees);
 }
Beispiel #5
0
        public ActionResult EditBenefitSetting(int id)
        {
            IEnumerable <DiscountType>          discountTypes          = DiscountTypeRepository.GetAll();
            IEnumerable <DiscountConditionType> discountConditionTypes = DiscountConditionTypeRepository.GetAll();
            BenefitSetting benefitSetting = BenefitSettingsRepository.GetById(id);

            return(PartialView("EditBenefitSetting", new EditBenefitSettingModel(benefitSetting, discountTypes, discountConditionTypes)));
        }
Beispiel #6
0
        public ActionResult AddBenefitSetting(AddBenefitSettingModel model)
        {
            // if discounts are found then check if they are valid
            if (model.Discounts != null)
            {
                // Check if discounts all have percentages
                if (model.Discounts.Any(x => x.DiscountPercentage == null))
                {
                    ModelState.AddModelError("", "Discount % is required.");
                }

                // Check if all discounts that are no no condition have a name value.
                if (model.Discounts.Any(x => x.DiscountConditionTypeId != (int)Enums.Discount.ConditionType.NoCondition && string.IsNullOrEmpty(x.NameValueCondition)))
                {
                    ModelState.AddModelError("", "Name Condition is required.");
                }
            }

            if (ModelState.IsValid)
            {
                BenefitSetting benefitSetting = new BenefitSetting
                {
                    Name = model.Name,
                    AnnualBenefitsCost          = model.BenefitCost.Value,
                    AnnualDependentBenefitsCost = model.DependantBenefitCost.Value,
                    AnnualSalary = model.AnnualSalary.Value,
                    IsDefault    = false,
                    IsPublic     = model.IsPublic,
                    Token        = Utilities.Utils.GenerateToken(50)
                };

                if (model.Discounts != null && model.Discounts.Any())
                {
                    foreach (var discount in model.Discounts)
                    {
                        benefitSetting.Discounts.Add(new Discount
                        {
                            DiscountTypeId          = discount.DiscountTypeId,
                            DiscountConditionTypeId = discount.DiscountConditionTypeId,
                            DiscountPercentage      = discount.DiscountPercentage.Value,
                            NameValueCondition      = discount.NameValueCondition
                        });
                    }
                }

                benefitSetting = BenefitSettingsRepository.Create(benefitSetting);

                return(Json(new PostResultModel
                {
                    IsSuccess = true,
                    Message = "Benefit Setting Added",
                    Html = PartialView("BenefitSettingRow", new BenefitSettingsRowModel(benefitSetting)).RenderToString()
                }));
            }

            return(PartialView(model));
        }
 public BenefitSettingsRowModel(BenefitSetting entity)
 {
     Id = entity.Id;
     BenefitSettingsToken = entity.Token;
     Name       = entity.Name;
     CreatedBy  = entity.CreatedByUser.UserName;
     CreatedOn  = entity.CreateDate.ToShortDateString() + " " + entity.CreateDate.ToShortTimeString();
     ModifiedBy = entity.ModifiedById.HasValue ? entity.ModifiedByUser.UserName : "";
     ModifiedOn = entity.ModifiedByDate.HasValue ? entity.ModifiedByDate.Value.ToShortDateString() + " " + entity.ModifiedByDate.Value.ToShortTimeString() : "";
     CanRemove  = !entity.IsDefault && entity.CreatedById == Utilities.Utils.GetCurrentUserId();
 }
Beispiel #8
0
        public DownloadModel(BenefitSetting benefitSetting, Employee employee, List <string> dependents, string fullname = "", decimal?annualSalary = null)
        {
            FullName     = employee != null ? employee.FirstName + " " + employee.LastName : fullname;
            AnnualSalary = (employee != null ? employee.AnnualSalary : annualSalary) ?? 0;
            Discounts    = new List <string>();
            Dependents   = dependents;

            decimal employeeDiscount = 0;

            foreach (var discount in benefitSetting.Discounts)
            {
                if ((discount.DiscountTypeId == (int)Enums.Discount.Type.EmployeeAndBeneficiary ||
                     discount.DiscountTypeId == (int)Enums.Discount.Type.EmployeeOnly) &&
                    CheckDiscount(FullName, (Enums.Discount.ConditionType)discount.DiscountConditionTypeId, discount.NameValueCondition))
                {
                    if (discount.DiscountConditionTypeId == (int)Enums.Discount.ConditionType.NoCondition)
                    {
                        Discounts.Add("Discount Employee; " + (discount.DiscountPercentage * 100).ToString("f0") + " % Saved.");
                    }
                    else
                    {
                        Discounts.Add("Discount Employee Name \"" + FullName + "\" " + discount.DiscountConditionType.Name + " \"" + discount.NameValueCondition + "\"; " + (discount.DiscountPercentage * 100).ToString("f0") + "% Saved.");
                    }
                    employeeDiscount += discount.DiscountPercentage;
                }
            }
            TotalEmployeeBenefitCost = (double)(benefitSetting.AnnualBenefitsCost * (1 - Math.Min(employeeDiscount, 1)));

            foreach (var dependent in Dependents.Where(x => !string.IsNullOrEmpty(x)))
            {
                decimal dependentDiscount = 0;
                foreach (var discount in benefitSetting.Discounts)
                {
                    if ((discount.DiscountTypeId == (int)Enums.Discount.Type.EmployeeAndBeneficiary ||
                         discount.DiscountTypeId == (int)Enums.Discount.Type.BeneficiaryOnly) &&
                        CheckDiscount(dependent, (Enums.Discount.ConditionType)discount.DiscountConditionTypeId, discount.NameValueCondition))
                    {
                        if (discount.DiscountConditionTypeId == (int)Enums.Discount.ConditionType.NoCondition)
                        {
                            Discounts.Add("Discount Dependent; " + (discount.DiscountPercentage * 100).ToString("f0") + " % Saved.");
                        }
                        else
                        {
                            Discounts.Add("Discount Dependent Name \"" + dependent + "\" " + discount.DiscountConditionType.Name + " \"" + discount.NameValueCondition + "\"; " + (discount.DiscountPercentage * 100).ToString("f0") + "% Saved.");
                        }
                        dependentDiscount += discount.DiscountPercentage;
                    }
                }
                TotalDependentsBenefitCost += (double)(benefitSetting.AnnualDependentBenefitsCost * (1 - Math.Min(dependentDiscount, 1)));
            }

            Total         = (double)AnnualSalary - (TotalEmployeeBenefitCost + TotalDependentsBenefitCost);
            TotalPerCheck = Total / 26;
        }
Beispiel #9
0
 public EditBenefitSettingModel(BenefitSetting entity, IEnumerable <DiscountType> types, IEnumerable <DiscountConditionType> conditionTypes)
 {
     Id                   = entity.Id;
     Name                 = entity.Name;
     AnnualSalary         = entity.AnnualSalary;
     BenefitCost          = entity.AnnualBenefitsCost;
     DependantBenefitCost = entity.AnnualDependentBenefitsCost;
     IsPublic             = entity.IsPublic;
     YesNoOptions         = Utilities.Utils.GetYesNoOptions();
     // only show this field if user created the record.
     ShowIsPublic = entity.CreatedById == HttpContext.Current.User.Identity.GetUserId <int>();
     Discounts    = entity.Discounts.Select(x => new DiscountModel(x, types, conditionTypes));
 }
        public ActionResult Download(IndexModel model)
        {
            BenefitSetting benefitSetting = BenefitSettingsRepository.GetByToken(model.BenefitSettingToken);
            Employee       employee       = EmployeeRepository.GetByAccessCode(model.EmployeeAccessCode);
            DownloadModel  downloadModel  = new DownloadModel(benefitSetting, employee, model.Dependents, model.FullName, model.AnnualSalary);

            Response.Clear();
            Response.ContentType = "application/force-download";
            Response.AddHeader("content-disposition", "attachment;    filename=Benefits" + DateTime.Now.Ticks + ".pdf");
            Response.BinaryWrite(downloadModel.Generate());
            Response.End();

            return(null);
        }
Beispiel #11
0
        public ActionResult RemoveBenefitSetting(int id)
        {
            BenefitSetting benefitSetting = BenefitSettingsRepository.GetById(id);

            if (benefitSetting.IsDefault || benefitSetting.CreatedById != User.Identity.GetUserId <int>())
            {
                return(Json(new PostResultModel {
                    IsSuccess = false, Message = "You do not have the ability to delete this Benefit Setting."
                }));
            }

            benefitSetting.IsActive = false;
            BenefitSettingsRepository.Update(benefitSetting);
            return(Json(new PostResultModel {
                IsSuccess = true, Message = "Benefit Setting Removed"
            }));
        }
Beispiel #12
0
        public IndexModel(BenefitSetting benefitSetting, Employee employee)
        {
            AnnualSalary                = employee != null ? employee.AnnualSalary : benefitSetting.AnnualSalary;
            BenefitSettingToken         = benefitSetting.Token;
            AnnualBenefitsCost          = benefitSetting.AnnualBenefitsCost;
            AnnualDependentBenefitsCost = benefitSetting.AnnualDependentBenefitsCost;
            // map discounts to collection
            Discounts = benefitSetting.Discounts.Select(x => new DiscountModel(x));

            if (employee != null)
            {
                FullName           = employee.FirstName + " " + employee.LastName;
                IsEmployee         = true;
                EmployeeAccessCode = employee.AccessCode;
                TotalDependents    = employee.Dependents.Count();
                Dependents         = employee.Dependents.Select(x => x.FirstName + " " + x.LastName).ToList();
            }
        }
Beispiel #13
0
        public ActionResult SendEmployeeBenefitSetting(SendEmployeeBenefitSettingModel model)
        {
            if (ModelState.IsValid)
            {
                BenefitSetting benefitSetting = BenefitSettingsRepository.GetById(model.BenefitSettingId);
                Employee       employee       = EmployeeRepository.GetById(model.EmployeeId.Value);
                string         url            = (Request.IsSecureConnection ? "https://" : "http://")
                                                + Request.Url.Authority + "/Client/Index?token=" + benefitSetting.Token + "&employeeAccessToken=" + employee.AccessCode;
                string body = "Hello " + employee.FirstName + " " + employee.LastName + ", <br/><br/>" +
                              model.Message + " <br/><br/>" + url;

                Utilities.Utils.SendEmail(employee.Email, "Employee Benefits", body);

                return(Json(new PostResultModel {
                    IsSuccess = true, Message = "Link Sent"
                }));
            }

            model.Populate(EmployeeRepository.GetAll().Where(x => x.IsActive));
            return(PartialView(model));
        }
        public BenefitSetting Create(BenefitSetting entity)
        {
            entity.CreateDate  = DateTime.Now;
            entity.CreatedById = Utils.GetCurrentUserId();
            entity.Token       = Utils.GenerateToken(30);
            entity.IsActive    = true;
            entity.IsDefault   = false;

            foreach (var discount in entity.Discounts)
            {
                discount.CreateDate  = DateTime.Now;
                discount.CreatedById = Utils.GetCurrentUserId();
                discount.IsActive    = true;
            }

            DB.db.BenefitSettings.Add(entity);
            DB.SaveChanges();

            return(DB.db.BenefitSettings
                   .Include(x => x.CreatedByUser)
                   .FirstOrDefault(x => x.Id == entity.Id));
        }
Beispiel #15
0
        public ActionResult EditBenefitSetting(EditBenefitSettingModel model)
        {
            // if discounts are found then check if they are valid
            if (model.Discounts != null)
            {
                // Check if discounts all have percentages
                if (model.Discounts.Any(x => x.DiscountPercentage == null))
                {
                    ModelState.AddModelError("", "Discount % is required.");
                }

                // Check if all discounts that are no no condition have a name value.
                if (model.Discounts.Any(x => x.DiscountConditionTypeId != (int)Enums.Discount.ConditionType.NoCondition && string.IsNullOrEmpty(x.NameValueCondition)))
                {
                    ModelState.AddModelError("", "Name Condition is required.");
                }
            }

            if (ModelState.IsValid)
            {
                BenefitSetting benefitSetting = BenefitSettingsRepository.GetById(model.Id);

                benefitSetting.Name                        = model.Name;
                benefitSetting.AnnualSalary                = model.AnnualSalary.Value;
                benefitSetting.AnnualBenefitsCost          = model.BenefitCost.Value;
                benefitSetting.AnnualDependentBenefitsCost = model.DependantBenefitCost.Value;

                // only allow changing this field if user created the record.
                if (benefitSetting.CreatedById == User.Identity.GetUserId <int>())
                {
                    benefitSetting.IsPublic = model.IsPublic;
                }

                if (model.Discounts != null && model.Discounts.Any())
                {
                    DiscountRepository.Delete(DiscountRepository.GetByBenefitSettingsId(benefitSetting.Id).Where(x => model.Discounts.All(m => m.DiscountId != x.Id)));

                    foreach (var discount in model.Discounts)
                    {
                        Discount discountEntity = DiscountRepository.GetById(discount.DiscountId);
                        if (discountEntity != null)
                        {
                            discountEntity.DiscountTypeId          = discount.DiscountTypeId;
                            discountEntity.DiscountConditionTypeId = discount.DiscountConditionTypeId;
                            discountEntity.NameValueCondition      = discount.NameValueCondition;
                            discountEntity.DiscountPercentage      = discount.DiscountPercentage.Value;
                            DiscountRepository.Update(discountEntity);
                        }
                        else
                        {
                            benefitSetting.Discounts.Add(new Discount
                            {
                                DiscountTypeId          = discount.DiscountTypeId,
                                DiscountConditionTypeId = discount.DiscountConditionTypeId,
                                DiscountPercentage      = discount.DiscountPercentage.Value,
                                NameValueCondition      = discount.NameValueCondition
                            });
                        }
                    }
                }
                else
                {
                    DiscountRepository.Delete(DiscountRepository.GetByBenefitSettingsId(benefitSetting.Id));
                }

                benefitSetting = BenefitSettingsRepository.Update(benefitSetting);

                return(Json(new PostResultModel
                {
                    IsSuccess = true,
                    Message = "Benefit Setting Edited",
                    ItemId = benefitSetting.Id,
                    Html = PartialView("BenefitSettingRow", new BenefitSettingsRowModel(benefitSetting)).RenderToString()
                }));
            }

            return(PartialView(model));
        }