public ActionResult CommissionSave(AgentCommissionModel model)
        {
            var data = Mapper.Map <AgentCommissionModel, AgentCommission>(model);

            InsuranceContext.AgentCommissions.Insert(data);
            return(RedirectToAction("CommissionList"));
        }
        public ActionResult EditCommission(AgentCommissionModel model)
        {
            ModelState.Remove("ManagementCommission");
            if (ModelState.IsValid)
            {
                var detials = InsuranceContext.AgentCommissions.Single(model.Id);

                if (CheckAgentExist(detials.BusinessSourceId, model.BusinessSourceId))
                {
                    detials.CommissionName   = model.CommissionName;
                    detials.CommissionAmount = model.CommissionAmount;
                    detials.BusinessSourceId = model.BusinessSourceId;

                    InsuranceContext.AgentCommissions.Update(detials);
                }
                else
                {
                    TempData["errorMsg"] = "Agent commmission alredy exist for selected source.";
                }



                ViewBag.Sources = InsuranceContext.BusinessSources.All();
            }

            return(RedirectToAction("Commission"));
        }
        public ActionResult AddCommission()
        {
            AgentCommissionModel model = new AgentCommissionModel();

            ViewBag.Sources = InsuranceContext.BusinessSources.All();
            return(View(model));
        }
        public ActionResult CommissionEdit(AgentCommissionModel model)
        {
            if (ModelState.IsValid)
            {
                var data = Mapper.Map <AgentCommissionModel, AgentCommission>(model);
                InsuranceContext.AgentCommissions.Update(data);
            }

            return(RedirectToAction("CommissionList"));
        }
        public ActionResult AddCommision(AgentCommissionModel model)
        {
            ModelState.Remove("Id");
            ModelState.Remove("ManagementCommission");

            if (ModelState.IsValid)
            {
                var agentCommission = InsuranceContext.AgentCommissions.Single(where : $"BusinessSourceId =" + model.BusinessSourceId);

                if (agentCommission == null)
                {
                    AgentCommission agentCommision = new AgentCommission {
                        BusinessSourceId = model.BusinessSourceId, CommissionName = model.CommissionName, CommissionAmount = model.CommissionAmount, CreatedOn = DateTime.Now
                    };
                    InsuranceContext.AgentCommissions.Insert(agentCommision);
                }
                else
                {
                    TempData["errorMsg"] = "Agent commmission alredy exist for selected source.";
                }
            }

            return(RedirectToAction("Commission"));
        }