예제 #1
0
 public ActionResult Edit(int id, VehicleTrimViewModel collection)
 {
     try
     {
         if (id > 0)
         {
             if (ModelState.IsValid)
             {
                 var model = _mapper.Map <VehicleTrim>(collection);
                 model.UpdaterId = LogedInAdmin.Id;
                 _vehicleTrimService.Update(model);
                 return(RedirectToAction("Index"));
             }
             ModelState.AddModelError(string.Empty, GeneralMessages.DefectiveEntry);
         }
         else
         {
             ModelState.AddModelError(string.Empty, GeneralMessages.EmptyId);
         }
     }
     catch (Exception ex)
     {
         _logger.Error(ex);
         if (ex.InnerException != null && ex.InnerException.Source.Equals(GeneralMessages.ExceptionSource))
         {
             ModelState.AddModelError(string.Empty, ex.Message);
         }
         else
         {
             ModelState.AddModelError(string.Empty, GeneralMessages.UnexpectedError);
         }
     }
     return(View(collection));
 }
예제 #2
0
        public ActionResult Index(VehicleTrimViewModel collection)
        {
            var request = new FilteredModel <VehicleTrim>
            {
                PageIndex = collection.ThisPageIndex,
                Order     = collection.PageOrder,
                OrderBy   = collection.PageOrderBy
            };
            var offset = (request.PageIndex - 1) * request.PageSize;
            var result = _mapper.Map <IList <VehicleTrimViewModel> >(_vehicleTrimService.GetPaging(_mapper.Map <VehicleTrim>(collection), out long totalCount, request.OrderBy, request.Order, offset, request.PageSize));

            if (!result.Any() && totalCount > 0 && request.PageIndex > 1)
            {
                request.PageIndex = (int)(totalCount / request.PageSize);
                if (totalCount % request.PageSize > 0)
                {
                    request.PageIndex++;
                }
                result = _mapper.Map <IList <VehicleTrimViewModel> >(_vehicleTrimService.GetPaging(_mapper.Map <VehicleTrim>(collection), out totalCount, request.OrderBy, request.Order, offset, request.PageSize));
            }
            ViewBag.OnePageOfEntries = new StaticPagedList <VehicleTrimViewModel>(result, request.PageIndex, request.PageSize, (int)totalCount);
            ViewBag.SearchModel      = collection;
            return(View());
        }