public ActionResult Index(MatchGroupViewModel model)
        {
            try
            {
                ViewBag.SearchModel = model;
                var request = new FilteredModel <MatchGroup>();
                var offset  = (model.ThisPageIndex - 1) * model.ThisPageSize;

                var result = _mapper.Map <IList <MatchGroupViewModel> >(_MatchGroupService.GetPaging(_mapper.Map <MatchGroup>(model), out long totalCount, model.PageOrderBy, model.PageOrder, offset, model.ThisPageSize));
                ViewBag.OnePageOfEntries = new StaticPagedList <MatchGroupViewModel>(result, model.ThisPageIndex, model.ThisPageSize, (int)totalCount);
            }
            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());
        }
        public ActionResult Edit(int id, MatchGroupViewModel collection)
        {
            try
            {
                if (id > 0)
                {
                    if (ModelState.IsValid)
                    {
                        var model = _mapper.Map <MatchGroup>(collection);
                        if (!ModelState.IsValid)
                        {
                            ViewBag.EventsList = new SelectList(_dropDownService.GetEvents(), "id", "name", model.EventId);
                            return(View(collection));
                        }

                        _MatchGroupService.UpdateWithLog(model, AdminHelper.AdminId);
                        if (!string.IsNullOrEmpty(collection.PreviousUrl))
                        {
                            return(Redirect(collection.PreviousUrl));
                        }
                        return(RedirectToAction("Index"));
                    }
                    ModelState.AddModelError(string.Empty, GeneralMessages.DefectiveEntry);
                }
                else
                {
                    ModelState.AddModelError(string.Empty, GeneralMessages.EmptyId);
                }
                ViewBag.EventsList = new SelectList(_dropDownService.GetEvents(), "id", "name", collection.EventId);
            }
            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);
                }
                ViewBag.EventsList = new SelectList(_dropDownService.GetEvents(), "id", "name", collection.EventId);
            }
            return(View(collection));
        }
        public ActionResult List(MatchGroupViewModel collection)
        {
            try
            {
                var request = new FilteredModel <MatchGroupViewModel>
                {
                    PageIndex = collection.ThisPageIndex,
                    Order     = collection.PageOrder,
                    OrderBy   = collection.PageOrderBy,
                    PageSize  = collection.ThisPageSize
                };

                var offset = (request.PageIndex - 1) * request.PageSize;
                var result = _mapper.Map <IList <MatchGroupViewModel> >(_MatchGroupService.GetPaging(_mapper.Map <MatchGroup>(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++;
                    }
                    offset = (request.PageIndex - 1) * request.PageSize;
                    result = _mapper.Map <IList <MatchGroupViewModel> >(_MatchGroupService.GetPaging(_mapper.Map <MatchGroup>(collection), out totalCount, request.OrderBy, request.Order, (request.PageIndex - 1) * request.PageSize, request.PageSize));
                }
                ViewBag.OnePageOfEntries = new StaticPagedList <MatchGroupViewModel>(result, request.PageIndex, request.PageSize, (int)totalCount);
                ViewBag.SearchModel      = collection;
            }
            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(Request.IsAjaxRequest()
                ? (ActionResult)PartialView("_MatchGroupGrid", ViewBag.OnePageOfEntries)
                : View());
        }
 public ActionResult Details(int id, MatchGroupViewModel collection)
 {
     try
     {
         if (id > 0)
         {
             var model = _MatchGroupService.GetById(id);
             if (model != null)
             {
                 //model.UpdaterId = LogedInMatchGroup.Id;
                 _MatchGroupService.Delete(model);
                 if (!string.IsNullOrEmpty(collection.PreviousUrl))
                 {
                     return(Redirect(collection.PreviousUrl));
                 }
                 return(RedirectToAction("Index"));
             }
         }
         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));
 }