public ActionResult Create(EarnedPremiumModel model)
        {
            try
            {
                if (TypeNameExist(model.Entity.OrgID ?? 0, model.Entity.PremiumYear ?? 0))
                {
                    ModelState.AddModelError("", "Earned Premium 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.EarnedPremiumRepository.Insert(certGrade);
                    _unitOfWork.Save();
                    TempData["message"] = "<b>" + certGrade.PremiumYear + "</b> was successfully created";
                    return(RedirectToAction("Index", new { orgId = model.Entity.OrgID }));
                }
                model.OrgLookUp = LookUps.OrganisationById(model.Entity.OrgID ?? 0);
                model.CobLookUp = LookUps.ClassOfBusiness();
                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(int id = 0)
 {
     try
     {
         var certGrade = _unitOfWork.EarnedPremiumRepository.GetByID(id);
         if (certGrade == null)
         {
             return(HttpNotFound());
         }
         var model = new EarnedPremiumModel
         {
             Entity    = certGrade,
             OrgLookUp = LookUps.OrganisationById(certGrade.OrgID ?? 0),
             CobLookUp = LookUps.ClassOfBusiness(),
             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 Create(int orgId)
        {
            var model = new EarnedPremiumModel
            {
                Entity    = new EarnedPremium(),
                OrgLookUp = LookUps.OrganisationById(orgId),
                CobLookUp = LookUps.ClassOfBusiness(),
                OrgId     = orgId
            };

            return(View(model));
        }
        public ActionResult Index([DefaultValue(1)] int page, string keywords, [DefaultValue(10)] int pgsize)
        {
            try
            {
                var orgId = LookUps.GetOrgId(User.Identity.Name);
                if (orgId == 0)
                {
                    orgId = Settings.Default.DefaultOrgId;
                }

                List <EarnedPremium> rowsToShow;
                int totalRecords;


                if (!string.IsNullOrEmpty(keywords))
                {
                    rowsToShow   = _unitOfWork.EarnedPremiumRepository.Get(filter: x => x.Organisation.Name.ToUpper().Contains(keywords.Trim().ToUpper()) || x.ClassOfBusiness1.ClassType.Contains(keywords.Trim().ToUpper()), orderBy: q => q.OrderBy(x => x.PremiumYear)).Skip((page - 1) * pgsize).Take(pgsize).ToList();
                    totalRecords = _unitOfWork.EarnedPremiumRepository.Get(filter: x => x.Organisation.Name.ToUpper().Contains(keywords.Trim().ToUpper()) || x.ClassOfBusiness1.ClassType.Contains(keywords.Trim().ToUpper())).Count();
                }
                else
                {
                    rowsToShow   = _unitOfWork.EarnedPremiumRepository.Get(orderBy: q => q.OrderBy(x => x.PremiumYear)).Skip((page - 1) * pgsize).Take(pgsize).ToList();
                    totalRecords = _unitOfWork.EarnedPremiumRepository.Get(orderBy: q => q.OrderBy(x => x.ID)).Count();
                }

                var model = new EarnedPremiumModel()
                {
                    Rows       = rowsToShow,
                    OrgId      = orgId,
                    PagingInfo = new PagingInfo
                    {
                        FirstItem    = ((page - 1) * pgsize) + 1,
                        LastItem     = page * pgsize,
                        CurrentPage  = page,
                        ItemsPerPage = pgsize,
                        TotalItems   = totalRecords
                    },
                    CurrentKeywords = keywords,
                    PageSize        = pgsize
                };
                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" }));
            }
        }