public ActionResult Create(InflationRateModel model)
        {
            try
            {
                if (TypeNameExist(model.Entity.OrgID ?? 0, model.Entity.InflationYear ?? 0, model.Entity.ID))
                {
                    ModelState.AddModelError("", "Inflation Rate Already Exist");
                }



                if (ModelState.IsValid)
                {
                    var certGrade = model.Entity;
                    certGrade.ModifiedBy   = User.Identity.Name;
                    certGrade.ModifiedDate = DateTime.Now;
                    certGrade.CreatedBy    = User.Identity.Name;
                    certGrade.CreatedDate  = DateTime.Now;

                    _unitOfWork.InflationRateRepository.Insert(certGrade);
                    _unitOfWork.Save();
                    TempData["message"] = "<b>" + certGrade.InflationYear + "</b> was successfully created";
                    return(RedirectToAction("Index", new { orgId = model.Entity.OrgID }));
                }
                model.OrgLookUp = LookUps.OrganisationById(model.Entity.OrgID ?? 0);
                return(View(model));
            }
            catch (Exception ex)
            {
                // Log with Elmah
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                TempData["message"] = Settings.Default.GenericExceptionMessage;
                return(RedirectToAction("Index", "Home", new { area = "Admin" }));
            }
        }
        public ActionResult SearchModel()
        {
            try
            {
                var orgId = LookUps.GetOrgId(User.Identity.Name);
                if (orgId == 0)
                {
                    orgId = Settings.Default.DefaultOrgId;
                }
                var model = new SearchModel()
                {
                    OrgId = orgId,
                    //  ModelData = _unitOfWork.PaidDataRepository.GetResultReport(orgId)
                    OrgLookUp        = LookUps.OrganisationById(orgId),
                    CobLookUp        = LookUps.ClassOfBusiness(),
                    TypeOfLossLookUp = LookUps.TypeOfLoss(),
                };


                // ModelData = _unitOfWork.PaidDataRepository.ExecWithStoreProcedure(
                //    "rModelViewByOrg @orgId",
                //new SqlParameter("orgId", SqlDbType.Int) { Value = orgId })

                return(View(model));
            }
            catch (Exception ex)
            {
                // Log with Elmah
                ErrorSignal.FromCurrentContext().Raise(ex);
                TempData["message"] = Settings.Default.GenericExceptionMessage;
                return(RedirectToAction("Index", "Home", new { area = "Admin" }));
            }
        }
 public ActionResult Edit(int id = 0)
 {
     try
     {
         var certGrade = _unitOfWork.InflationRateRepository.GetByID(id);
         if (certGrade == null)
         {
             return(HttpNotFound());
         }
         var model = new InflationRateModel
         {
             Entity    = certGrade,
             OrgLookUp = LookUps.OrganisationById(certGrade.OrgID ?? 0),
             OrgId     = certGrade.OrgID ?? 0
         };
         return(View(model));
     }
     catch (Exception ex)
     {
         // Log with Elmah
         Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
         TempData["message"] = Settings.Default.GenericExceptionMessage;
         return(RedirectToAction("Index", "Home", new { area = "Admin" }));
     }
 }
        public ActionResult Edit(OutstandingDataModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var certGrade = model.Entity;
                    certGrade.ModifiedBy   = User.Identity.Name;
                    certGrade.ModifiedDate = DateTime.Now;
                    certGrade.LossYear     = certGrade.DateOfLoss.GetValueOrDefault().Year;

                    _unitOfWork.OutstandingDataRepository.Update(certGrade);
                    _unitOfWork.Save();
                    TempData["message"] = "<b>" + certGrade.ClaimNo + "</b> was successfully updated";
                    return(RedirectToAction("Index", new { orgId = model.Entity.ID }));
                }
                model.OrgLookUp        = LookUps.OrganisationById(model.Entity.OrgID ?? 0);
                model.CobLookUp        = LookUps.ClassOfBusiness();
                model.TypeOfLossLookUp = LookUps.TypeOfLoss();
                return(View(model));
            }
            catch (Exception ex)
            {
                // Log with Elmah
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                TempData["message"] = Settings.Default.GenericExceptionMessage;
                return(RedirectToAction("Index", "Home", new { area = "Admin" }));
            }
        }
        public ActionResult Create(int orgId)
        {
            var model = new InflationRateModel
            {
                Entity    = new InflationRate(),
                OrgLookUp = LookUps.OrganisationById(orgId),
                OrgId     = orgId
            };

            return(View(model));
        }
        public ActionResult Create(int orgId)
        {
            var model = new EarnedPremiumModel
            {
                Entity    = new EarnedPremium(),
                OrgLookUp = LookUps.OrganisationById(orgId),
                CobLookUp = LookUps.ClassOfBusiness(),
                OrgId     = orgId
            };

            return(View(model));
        }
        public ActionResult Create(int orgId)
        {
            var model = new PaidDataModel
            {
                Entity           = new PaidData(),
                OrgLookUp        = LookUps.OrganisationById(orgId),
                CobLookUp        = LookUps.ClassOfBusiness(),
                TypeOfLossLookUp = LookUps.TypeOfLoss(),
                OrgId            = orgId
            };

            return(View(model));
        }
        public ActionResult Create(TypeOfLossThresholdModel model)
        {
            try
            {
                if (model.Entity.MaxValue <= model.Entity.MinValue)
                {
                    ModelState.AddModelError("", "Please Make Sure Maximum Value is Higher than the Minimum Value");
                }

                if (ThresholdExist(model.Entity.OrgID ?? 0, model.Entity.ClassOfBusiness ?? 0, model.Entity.TypeOfLoss ?? 0, model.Entity.ID))
                {
                    ModelState.AddModelError("", "Threshold Already Exist");
                }

                if (ValuesConflict(model.Entity.OrgID ?? 0, model.Entity.ClassOfBusiness ?? 0, model.Entity.MinValue ?? 0, model.Entity.MaxValue ?? 0, model.Entity.ID))
                {
                    ModelState.AddModelError("", "Minimum and Maximum Values Conflict with existing setup for the selected Class of Business");
                }

                if (ModelState.IsValid)
                {
                    var certGrade = model.Entity;
                    certGrade.ModifiedBy   = User.Identity.Name;
                    certGrade.ModifiedDate = DateTime.Now;
                    certGrade.CreatedBy    = User.Identity.Name;
                    certGrade.CreatedDate  = DateTime.Now;



                    _unitOfWork.TypeOfLossThresholdRepository.Insert(certGrade);
                    _unitOfWork.Save();
                    TempData["message"] = "Type of Loss Threshold was successfully created";
                    return(RedirectToAction("Index", new { orgid = model.Entity.OrgID }));
                }

                model.OrgId            = model.Entity.OrgID ?? 0;
                model.OrgLookUp        = LookUps.OrganisationById(model.Entity.OrgID ?? 0);
                model.CobLookUp        = LookUps.ClassOfBusiness();
                model.TypeOfLossLookUp = LookUps.TypeOfLoss();
                return(View(model));
            }
            catch (Exception ex)
            {
                // Log with Elmah
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                TempData["message"] = Settings.Default.GenericExceptionMessage;
                return(RedirectToAction("Index", "Home", new { area = "Admin" }));
            }
        }
        public ActionResult CreateExcel(ExcelUploadModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var excelReader = new PaidDataExcelReader();
                    //upload excel file
                    var result = excelReader.UploadCpExcelFile(model.ExcelFile);
                    if (result.Key)
                    {
                        //if upload is successfull insert the record into the  the cpuploads

                        //if insert in ok process the excel file details
                        var processResult = excelReader.ProcessExcel(result.Value, model.OrgId, User.Identity.Name);
                        var sucessResult  = "";
                        if (processResult.Key)
                        {
                            sucessResult = processResult.Value;
                        }
                        else
                        {
                            TempData["ExcelSummary"] = processResult.Value;
                            return(RedirectToAction("Index", new { orgid = model.OrgId }));
                        }


                        TempData["ExcelSummary"] = sucessResult;
                        return(RedirectToAction("Index", new { orgid = model.OrgId }));
                    }
                    else
                    {
                        TempData["ExcelSummary"] = result.Value;
                        return(RedirectToAction("Index", new { orgid = model.OrgId }));
                    }
                }

                model.OrgLookUp = LookUps.OrganisationById(model.OrgId);
                return(View(model));
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                TempData["message"] = Settings.Default.GenericExceptionMessage;
                return(RedirectToAction("Index"));
            }
        }
 public ActionResult CreateExcel(int orgId)
 {
     try
     {
         var model = new ExcelUploadModel {
             OrgId = orgId, OrgLookUp = LookUps.OrganisationById(orgId)
         };
         return(View(model));
     }
     catch (Exception ex)
     {
         // Log with Elmah
         Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
         TempData["message"] = Settings.Default.GenericExceptionMessage;
         return(RedirectToAction("Index"));
     }
 }
        public ActionResult Create(PaidDataModel model)
        {
            try
            {
                if (ClaimExist(model.Entity.OrgID ?? 0, model.Entity.ClaimNo, model.Entity.ID))
                {
                    ModelState.AddModelError("", "Claim Number Already Exist");
                }

                if (ModelState.IsValid)
                {
                    var certGrade = model.Entity;
                    certGrade.ModifiedBy   = User.Identity.Name;
                    certGrade.ModifiedDate = DateTime.Now;
                    certGrade.CreatedBy    = User.Identity.Name;
                    certGrade.CreatedDate  = DateTime.Now;

                    //calcualte dev period
                    certGrade.LossYear  = certGrade.DateOfLoss.GetValueOrDefault().Year;
                    certGrade.PaidYear  = certGrade.DateOfPayment.GetValueOrDefault().Year;
                    certGrade.DevPeriod = certGrade.PaidYear - certGrade.LossYear;

                    _unitOfWork.PaidDataRepository.Insert(certGrade);
                    _unitOfWork.Save();
                    TempData["message"] = "<b>" + certGrade.ClaimNo + "</b> was successfully created";
                    return(RedirectToAction("Index", new { orgid = model.Entity.OrgID }));
                }
                model.OrgLookUp        = LookUps.OrganisationById(model.Entity.OrgID ?? 0);
                model.CobLookUp        = LookUps.ClassOfBusiness();
                model.TypeOfLossLookUp = LookUps.TypeOfLoss();
                return(View(model));
            }
            catch (Exception ex)
            {
                // Log with Elmah
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                TempData["message"] = Settings.Default.GenericExceptionMessage;
                return(RedirectToAction("Index", "Home", new { area = "Admin" }));
            }
        }
        public ActionResult SearchModel(SearchModel model)
        {
            try
            {
                if (model.EndYear <= model.StartYear)
                {
                    ModelState.AddModelError("", "Please Make End Date is Higher than Start Date");
                }
                if (ModelState.IsValid)
                {
                    //       _unitOfWork.PaidDataRepository.UpdateHierarchy("rModelCummulativeSetUp @orgId, @startYear, @endYear,@cob,@losstype",
                    //      new SqlParameter("orgId", SqlDbType.Int) { Value = model.OrgId },
                    //      new SqlParameter("startYear", SqlDbType.Int) { Value = model.StartYear },
                    //      new SqlParameter("endYear", SqlDbType.Int) { Value = model.EndYear },
                    //        new SqlParameter("cob", SqlDbType.Int) { Value = model.ClassOfBusiness },
                    //          new SqlParameter("losstype", SqlDbType.Int) { Value = model.LossType });



                    _unitOfWork.PaidDataRepository.UpdateHierarchy("GeneralSetUp @orgId, @startYear, @endYear,@cob,@losstype",
                                                                   new SqlParameter("orgId", SqlDbType.Int)
                    {
                        Value = model.OrgId
                    },
                                                                   new SqlParameter("startYear", SqlDbType.Int)
                    {
                        Value = model.StartYear
                    },
                                                                   new SqlParameter("endYear", SqlDbType.Int)
                    {
                        Value = model.EndYear
                    },
                                                                   new SqlParameter("cob", SqlDbType.Int)
                    {
                        Value = model.ClassOfBusiness
                    },
                                                                   new SqlParameter("losstype", SqlDbType.Int)
                    {
                        Value = model.LossType
                    });

                    return(RedirectToAction("Index", new { orgid = model.OrgId, startYear = model.StartYear, endYear = model.EndYear, cob = model.ClassOfBusiness, losstype = model.LossType }));
                }



                // ModelData = _unitOfWork.PaidDataRepository.ExecWithStoreProcedure(
                //    "rModelViewByOrg @orgId",
                //new SqlParameter("orgId", SqlDbType.Int) { Value = orgId })
                model.OrgLookUp        = LookUps.OrganisationById(model.OrgId);
                model.CobLookUp        = LookUps.ClassOfBusiness();
                model.TypeOfLossLookUp = LookUps.TypeOfLoss();
                return(View(model));
            }
            catch (Exception ex)
            {
                // Log with Elmah
                ErrorSignal.FromCurrentContext().Raise(ex);
                TempData["message"] = Settings.Default.GenericExceptionMessage;
                return(RedirectToAction("Index", "Home", new { area = "Admin" }));
            }
        }