public async Task <DestinationVM> GetDestinationsAsync(int pageno, int pagesize, string sterm)
        {
            DestinationVM model    = new DestinationVM();
            var           parStart = new SqlParameter("@Start", (pageno - 1) * pagesize);
            var           parEnd   = new SqlParameter("@PageSize", pagesize);

            var parSearchTerm = new SqlParameter("@SearchTerm", DBNull.Value);

            if (!(sterm == null || sterm == ""))
            {
                parSearchTerm.Value = sterm;
            }
            // setting stored procedure OUTPUT value
            // This return total number of rows, and avoid two database call for data and total number of rows
            var spOutput = new SqlParameter
            {
                ParameterName = "@TotalCount",
                SqlDbType     = System.Data.SqlDbType.BigInt,
                Direction     = System.Data.ParameterDirection.Output
            };

            model.Destinations = await objDB.Database.SqlQuery <DestinationView>("udspMstDestinationPaged @Start, @PageSize,@SearchTerm, @TotalCount out",
                                                                                 parStart, parEnd, parSearchTerm, spOutput).ToListAsync();

            model.TotalRecords = int.Parse(spOutput.Value.ToString());
            return(model);
        }
    public static DestinationVM MyConvert(SourceVM vm)
    {
        DestinationVM destVm = GetDest();
        var           config = new MapperConfiguration(cfg =>
        {
            cfg.CreateMap <SourceVM, DestinationVM>()
            .ForAllMembers(opt => opt.Condition(src => src != null));
        });

        config.CreateMapper().Map(vm, destVm);
        return(destVm);
    }
Example #3
0
 //
 // GET: /Admin/Destination/
 public ActionResult Index(int PageNo = 1, int PageSize = 10, string SearchTerm = "")
 {
     try
     {
         string           query    = "PageNo=" + PageNo + "&PageSize=" + PageSize + "&SearchTerm=" + SearchTerm;
         DestinationAPIVM apiModel = objAPI.GetRecordByQueryString <DestinationAPIVM>("configuration", "destinations", query);
         DestinationVM    model    = new DestinationVM();
         model.Destinations = apiModel.Destinations;
         model.PagingInfo   = new PagingInfo {
             CurrentPage = PageNo, ItemsPerPage = PageSize, TotalItems = apiModel.TotalRecords
         };
         if (Request.IsAjaxRequest())
         {
             return(PartialView("_pvDestinationList", model));
         }
         return(View(model));
     }
     catch (AuthorizationException)
     {
         TempData["ErrMsg"] = "Your Login Session has expired. Please Login Again";
         return(RedirectToAction("Login", "Account", new { Area = "" }));
     }
 }