コード例 #1
0
        /// <summary>
        /// to get filter list with sorting and paging
        /// </summary>
        /// <param name="dataPaging">DataPagingModel</param>
        /// <returns>list of RoleModel</returns>
        public List <UsersModel> GetList(ref DataPagingModel dataPaging)
        {
            List <UsersModel> model = new List <UsersModel>();
            var list = UnitofWork.RepoUser.Where(x => 1 == 1); //x.IsActive == true

            #region Searching
            if (dataPaging.SearchParameter != null)
            {
                foreach (var item in dataPaging.SearchParameter)
                {
                    if (item.Key == "name")
                    {
                        string value = item.Value.ToString().ToLower().Trim();
                        list = list.Where(x => x.Ownername.ToLower().Contains(value));
                    }
                    if (item.Key == "email")
                    {
                        string value = item.Value.ToString().ToLower().Trim();
                        list = list.Where(x => x.Email.ToLower().Contains(value));
                    }
                    if (item.Key == "storename")
                    {
                        string value = item.Value.ToString().ToLower().Trim();
                        list = list.Where(x => x.UserStores.Where(y => y.UserID == x.UserID).FirstOrDefault().Store.Storename.ToLower().Contains(value));
                    }
                    if (item.Key == "status")
                    {
                        bool value = item.Value == "T";
                        list = list.Where(x => x.IsActive == value);
                    }
                }
            }
            #endregion

            #region Sorting of list
            switch (dataPaging.SortingColumn.Trim().ToLower())
            {
            case "userid":
                if (dataPaging.SortingOrder == SortingOrder.Ascending)
                {
                    list = list.OrderBy(U => U.UserID);
                }
                else
                {
                    list = list.OrderByDescending(U => U.UserID);
                }
                break;

            case "email":
                if (dataPaging.SortingOrder == SortingOrder.Ascending)
                {
                    list = list.OrderBy(U => U.Email);
                }
                else
                {
                    list = list.OrderByDescending(U => U.Email);
                }
                break;

            case "name":
                if (dataPaging.SortingOrder == SortingOrder.Ascending)
                {
                    list = list.OrderBy(U => U.Ownername);
                }
                else
                {
                    list = list.OrderByDescending(U => U.Ownername);
                }
                break;

            case "status":
                if (dataPaging.SortingOrder == SortingOrder.Ascending)
                {
                    list = list.OrderBy(U => U.IsActive);
                }
                else
                {
                    list = list.OrderByDescending(U => U.IsActive);
                }
                break;

            case "storename":
                if (dataPaging.SortingOrder == SortingOrder.Ascending)
                {
                    list = list.OrderBy(U => U.UserStores.Where(x => x.UserID == U.UserID).FirstOrDefault().Store.Storename);
                }
                else
                {
                    list = list.OrderByDescending(U => U.UserStores.Where(x => x.UserID == U.UserID).FirstOrDefault().Store.Storename);
                }
                break;
            }

            #endregion

            dataPaging.TotalRecords = list.Count();

            //********* Pagination of list *********//
            if (dataPaging.TotalRecords > dataPaging.PageSize && dataPaging.ShowAllRecord == false)
            {
                list = list.Skip(dataPaging.CurrentPageID.TableSkipRecord(dataPaging.PageSize)).Take(dataPaging.PageSize);
            }

            model = list.ToList().Select(x => new UsersModel
            {
                UserID      = x.UserID,
                Email       = x.Email,
                OwnerName   = x.Ownername,
                IsActive    = x.IsActive,
                IsAdmin     = x.IsAdmin,
                StoreDetail = x.UserStores.Where(y => y.UserID == x.UserID).Count() > 0 ? x.UserStores.Where(y => y.UserID == x.UserID).FirstOrDefault().Store ?? new Store() : new Store(),
            }).ToList();

            model.ForEach(x => x.EncryptedID = x.UserID.ToString().ToEnctypt());
            model.ForEach(x => x.StoreID     = x.StoreDetail.StoreID);
            return(model);
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dataPaging"></param>
        /// <returns></returns>
        public ActionResult DataGridList(DataPagingModel dataPaging)
        {
            List <StoreAdChoiceModel> list = new List <StoreAdChoiceModel>();

            if (SessionHelper.SessionForModel != null && SessionHelper.SessionForModel.GetType() == typeof(List <StoreAdChoiceModel>))
            {
                list = (List <StoreAdChoiceModel>)SessionHelper.SessionForModel;
            }
            else
            {
                var adMonth = _admonth.GetDetailByMonthId();



                if (adMonth != null)
                {
                    SessionHelper.LockOutDate = adMonth.LockOutEndDate.Date.ToString();
                    List <StoreModel> model = new List <StoreModel>();
                    if (dataPaging.SearchParameter != null && dataPaging.SearchParameter.Where(x => x.Key == "userid").Count() == 0)
                    {
                        dataPaging.SearchParameter.Add("userid", SessionHelper.UserId.ToString()); // user will be see assigned stores only.
                    }
                    model = _store.GetList(ref dataPaging);
                    ViewBag.DataPaging = dataPaging;

                    var adOptionList = _storeAdOption.GetList().Where(x => x.InActive == true && x.SpecialAdoption == null).ToList();

                    var adMonthCoupon = _common.GetCouponList(adMonth != null ? adMonth.AdMonthID : 0).ToList();

                    // get existing ad detail from DB
                    var storeChoice = new List <StoreAdChoiceModel>();

                    storeChoice = _storeadchoice.GetDetail((int)SessionHelper.UserId, adMonth.AdMonthID);

                    foreach (var item in model)
                    {
                        StoreAdChoiceModel adChoice = new StoreAdChoiceModel();
                        adChoice.StoreID = item.StoreID;

                        var dbAdChoice = storeChoice.Where(x => x.StoreID == item.StoreID).FirstOrDefault();
                        if (dbAdChoice != null)
                        {
                            adChoice = dbAdChoice;

                            if (dbAdChoice.FollowedCorporate)
                            {
                                adChoice.UserAdChoice = UserAdChoice.FollowCorporate;
                            }
                            else if (dbAdChoice.OwnDistribution)
                            {
                                adChoice.UserAdChoice = UserAdChoice.DoingOwnDistribution;
                            }
                            else if (dbAdChoice.NotPrinting)
                            {
                                adChoice.UserAdChoice = UserAdChoice.NotPrinting;
                            }
                            else
                            {
                                adChoice.UserAdChoice     = UserAdChoice.IndividualChoice;
                                adChoice.IsCouponApply    = true;
                                adChoice.SelectedAdOption = new List <int>()
                                {
                                    dbAdChoice.AdOptionID ?? 0
                                };
                                adChoice.AdOptionID = dbAdChoice.AdOptionID;
                                //adChoice.AdCouponID = dbAdChoice.AdOptionID;
                            }
                        }

                        adChoice.Storename = item.Storename;
                        adChoice.Ownername = item.Ownergroup;

                        adChoice.AdOptionList = adOptionList.Where(x => x.StoreId == item.StoreID).Select(x => new SelectListItem
                        {
                            Value = x.OptionId.ToString(),
                            Text  = x.OptionName
                        }).ToList();

                        adChoice.StoreAdOptionList = new MultiSelectList(adOptionList.Where(x => x.StoreId == item.StoreID).ToList(), "OptionId", "OptionName", adChoice.SelectedAdOption);
                        adChoice.AdMonthDetail     = adMonth ?? new AdMonthModel();
                        adChoice.AdMonthID         = adMonth != null ? adMonth.AdMonthID : 0;
                        adChoice.CouponList        = adMonthCoupon;
                        adChoice.AdCouponID        = adMonth != null ? adMonth.AdCouponID : 0;
                        adChoice.AdCouponName      = adMonth != null ? adMonth.AdCouponName : "";
                        adChoice.InHomeDate        = adMonth != null ? adMonth.CorpInHomeDate : new DateTime();
                        list.Add(adChoice);
                    }
                    SessionHelper.SessionForModel = list;
                }
            }

            return(View(list));
        }