예제 #1
0
        public BSEntityFramework_ResultType InsertProducts(AddProductViewModel newProduct)
        {
            try
            {
                BSEntityFramework_ResultType result;
                using (BSDBEntities EF = new BSDBEntities())
                {
                    using (var transaction = EF.Database.BeginTransaction())
                    {
                        try
                        {
                            var shopId        = newProduct.ProductDetails.ShopID;
                            var totalProducts = EF.TBL_Products.Count(x => x.ShopID == shopId) + 1;
                            newProduct.ProductDetails.ProductID
                                = CommonSafeConvert.ToInt(Convert.ToString(shopId) + Convert.ToString(totalProducts));
                            newProduct.ProductDetails.TBL_ProductImages = newProduct.ProductImages;
                            EF.TBL_Products.Add(newProduct.ProductDetails);
                            EF.SaveChanges();
                            //var resultChild = InsertProductImages(newProduct.ProductImages,
                            //    newProduct.ProductDetails.ProductID);
                            //if (resultChild.Result != BSResult.Success)
                            //{
                            //    return resultChild;
                            //}
                            transaction.Commit();
                        }
                        catch (Exception ex)
                        {
                            transaction.Rollback();
                            var logact = new LoggerActivity();
                            result = new BSEntityFramework_ResultType(BSResult.Fail, newProduct, null, "Technical issue");
                            logact.ErrorSetup("WebApp", "InsertShope Failed", "", "", "", ex.Message);
                            return(result);
                        }
                    }

                    result = new BSEntityFramework_ResultType(BSResult.Success, newProduct.ProductDetails, null,
                                                              "Created Sucessfully");
                    return(result);
                }
            }
            catch (DbEntityValidationException dbValidationEx)
            {
                return(FormatException(dbValidationEx, newProduct.ProductDetails));
            }
            catch (Exception ex)
            {
                var logact = new LoggerActivity();
                var result = new BSEntityFramework_ResultType(BSResult.Fail, newProduct.ProductDetails, null,
                                                              "Technical issue");
                logact.ErrorSetup("WebApp", "Insert Products Failed", "", "", "", ex.Message);
                return(result);
            }
        }
예제 #2
0
        public BSEntityFramework_ResultType GetProductList(int shopId, string brand, string sortColumnName, string sortOrder, int pageSize, int currentPage)
        {
            var List        = new object();
            int totalPage   = 0;
            int totalRecord = 0;

            using (BSDBEntities EF = new BSDBEntities())
            {
                var prod =
                    string.IsNullOrWhiteSpace(brand) || brand == "0"?
                    EF.TBL_Products.Where(prd => prd.ShopID == shopId && prd.IsActive)
                    :
                    EF.TBL_Products.Where(prd => prd.ShopID == shopId && prd.IsActive &&
                                          prd.ProductBrand.Equals(brand)
                                          );


                var prodListBS = prod.Select(prd => new { prd.ProductID, prd.ProductName,
                                                          prd.ProductBrand,
                                                          prd.BarCode,
                                                          prd.IsAvailable
                                                          , prd.MRP,
                                                          prd.ShopPrice,
                                                          prd.OtherJsonDetails
                                                          , prd.TBL_ProductCategories_CNFG.ProductCategoryName,
                                                          prd.TBL_ProductType_CNFG.ProductTypeName,
                                                          prd.TBL_ProductSubType_CNFG.ProductSubTypeName }).ToArray();
                totalRecord    = prodListBS.Length;
                sortColumnName = sortColumnName ?? "ProductID";
                if (pageSize > 0)
                {
                    totalPage = totalRecord / pageSize + ((totalRecord % pageSize) > 0 ? 1 : 0);
                    List      = prodListBS
                                .OrderBy(sortColumnName + " " + sortOrder)
                                .Skip(pageSize * (currentPage - 1))
                                .Take(pageSize).ToArray();
                }
                else
                {
                    var prodList = prodListBS.ToArray();
                    List = prodList;
                }
            }

            var jsonresult = new JsonResult
            {
                Data = new { List = List, totalPage = totalPage, sortColumnName = sortColumnName, sortOrder = sortOrder, currentPage = currentPage },
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };

            var result = new BSEntityFramework_ResultType(BSResult.Success, List, null, "Fetched Successfully");

            return(result);
        }
예제 #3
0
        public BSEntityFramework_ResultType InsertShope(AddShopViewModel newShop)
        {
            try
            {
                BSEntityFramework_ResultType result;
                using (BSDBEntities EF = new BSDBEntities())
                {
                    using (var transaction = EF.Database.BeginTransaction())
                    {
                        try
                        {
                            newShop.ShopDetails.ShopID = -1;
                            newShop.ShopDetails.TBL_UserAssignedShops.Add(new TBL_UserAssignedShops()
                            {
                                ShopLoginDetailsID = newShop.ShopDetails.CreatedBy, CreatedBy = newShop.ShopDetails.CreatedBy, IsActive = true
                            });
                            newShop.ShopDetails.TBL_ShopsInPostalCodes.Add(newShop.ShopPostalDetails);
                            EF.TBL_Shops.Add(newShop.ShopDetails);
                            EF.SaveChanges();

                            transaction.Commit();
                        }
                        catch (Exception ex)
                        {
                            transaction.Rollback();
                            var logact = new LoggerActivity();
                            result = new BSEntityFramework_ResultType(BSResult.Fail, newShop, null, "Technical issue");
                            logact.ErrorSetup("WebApp", "InsertShope Failed", "", "", "", ex.Message);
                            return(result);
                        }
                    }
                }

                result = new BSEntityFramework_ResultType(BSResult.Success, newShop, null, "Created Sucessfully");
                return(result);
            }
            catch (DbEntityValidationException dbValidationEx)
            {
                return(FormatException(dbValidationEx, newShop));
            }
            catch (Exception ex)
            {
                var logact = new LoggerActivity();
                var result = new BSEntityFramework_ResultType(BSResult.Fail, newShop, null, "Technical issue");
                logact.ErrorSetup("WebApp", "InsertShope Failed", "", "", "", ex.Message);
                return(result);
            }
        }
예제 #4
0
        public BSEntityFramework_ResultType GetShopMapDetails(int shopId)
        {
            try
            {
                using (BSDBEntities EF = new BSDBEntities())
                {
                    var shopMapDetails = EF.TBL_ShopMapDetails.Where(x => x.ShopId == shopId)
                                         .Select(x => new
                    {
                        ShopId     = x.ShopId,
                        Latitude   = x.Latitude,
                        Longitude  = x.Longitude,
                        CreateBy   = x.CreateBy,
                        CreateDate = x.CreateDate
                    }).First();
                    var shopAddress = EF.TBL_Shops.Where(shop => shop.ShopID == shopId)
                                      .Select(
                        shop => shop.ShopAddress)
                                      .First();

                    var result = new BSEntityFramework_ResultType(BSResult.Success, new MapAddressViewModel()
                    {
                        Address        = shopAddress,
                        shopMapDetails = new TBL_ShopMapDetails()
                        {
                            ShopId     = shopMapDetails.ShopId,
                            Latitude   = shopMapDetails.Latitude,
                            Longitude  = shopMapDetails.Longitude,
                            CreateBy   = shopMapDetails.CreateBy,
                            CreateDate = shopMapDetails.CreateDate
                        }
                    }, null, "Success");
                    return(result);
                }
            }
            catch (DbEntityValidationException dbValidationEx)
            {
                return(FormatException(dbValidationEx, null));
            }
            catch (Exception ex)
            {
                var logact = new LoggerActivity();
                var result = new BSEntityFramework_ResultType(BSResult.Fail, null, null, "Technical issue");
                logact.ErrorSetup("WebApp", "Get Shop Map details Failed", "", "", "", ex.Message);
                return(result);
            }
        }
예제 #5
0
        public BSEntityFramework_ResultType GetShopAllBrands(int shopId)
        {
            try
            {
                using (BSDBEntities EF = new BSDBEntities())
                {
                    var brandList = EF.TBL_Products.Where(prod => prod.ShopID == shopId)
                                    .Select(
                        prod => new { Text = prod.ProductBrand, Value = prod.ProductBrand })
                                    .Distinct()
                                    .ToArray()
                                    .Select(
                        ptype =>
                        new SelectListItem()
                    {
                        Text = ptype.Text, Value = Convert.ToString(ptype.Value)
                    })
                                    .ToArray();


                    SelectListItem[] DefaultItem =
                    {
                        new SelectListItem()
                        {
                            Text  = "Select Brand",
                            Value = "0"
                        }
                    };
                    var finalBrands = DefaultItem.Concat(brandList).OrderBy(v => v.Value).ToArray();
                    var result      = new BSEntityFramework_ResultType(BSResult.Success, finalBrands, null, "Success");
                    return(result);
                }
            }
            catch (DbEntityValidationException dbValidationEx)
            {
                return(FormatException(dbValidationEx, null));
            }
            catch (Exception ex)
            {
                var logact = new LoggerActivity();
                var result = new BSEntityFramework_ResultType(BSResult.Fail, null, null, "Technical issue");
                logact.ErrorSetup("WebApp", "GetProductSubType Failed", "", "", "", ex.Message);
                return(result);
            }
        }
예제 #6
0
        public BSEntityFramework_ResultType UpdateProducts(AddProductViewModel Products)
        {
            try
            {
                using (BSDBEntities EF = new BSDBEntities())
                {
                    // EF.TBL_Products.AddOrUpdate(Products.ProductDetails);
                    EF.TBL_Products.Attach(Products.ProductDetails);
                    EF.Entry(Products.ProductDetails).Property(x => x.IsActive).IsModified          = true;
                    EF.Entry(Products.ProductDetails).Property(x => x.AvailableQuantity).IsModified = true;
                    EF.Entry(Products.ProductDetails).Property(x => x.BarCode).IsModified           = true;
                    EF.Entry(Products.ProductDetails).Property(x => x.IsAvailable).IsModified       = true;
                    EF.Entry(Products.ProductDetails).Property(x => x.MRP).IsModified = true;
                    EF.Entry(Products.ProductDetails).Property(x => x.OtherJsonDetails).IsModified  = true;
                    EF.Entry(Products.ProductDetails).Property(x => x.ProductBrand).IsModified      = true;
                    EF.Entry(Products.ProductDetails).Property(x => x.ProductCategoryID).IsModified = true;
                    EF.Entry(Products.ProductDetails).Property(x => x.ProductName).IsModified       = true;
                    EF.Entry(Products.ProductDetails).Property(x => x.ProductSubTypeID).IsModified  = true;
                    EF.Entry(Products.ProductDetails).Property(x => x.ProductTypeID).IsModified     = true;
                    EF.Entry(Products.ProductDetails).Property(x => x.ShopPrice).IsModified         = true;
                    EF.Entry(Products.ProductDetails).Property(x => x.ShopID).IsModified            = false;

                    if (Products.ProductImages != null && Products.ProductImages.Count > 0 && Products.ProductImages[0] != null)
                    {
                        EF.TBL_ProductImages.Attach(Products.ProductImages[0]);
                        EF.Entry(Products.ProductImages[0]).Property(x => x.ProductImage).IsModified = true;
                    }
                    EF.SaveChanges();
                    var result = new BSEntityFramework_ResultType(BSResult.Success, Products, null, "Updated Successfully");
                    return(result);
                }
            }
            catch (DbEntityValidationException dbValidationEx)
            {
                return(FormatException(dbValidationEx, Products));
            }
            catch (Exception ex)
            {
                var logact = new LoggerActivity();
                var result = new BSEntityFramework_ResultType(BSResult.Fail, Products, null, "Technical issue");
                logact.ErrorSetup("WebApp", "UpdateProducts Failed", "", "", "", ex.Message);
                return(result);
            }
        }
예제 #7
0
        public BSEntityFramework_ResultType GetShopTypes()
        {
            try
            {
                using (BSDBEntities EF = new BSDBEntities())
                {
                    var ShopTypes =
                        EF.TBL_ShopTypes_CNFG.Select(
                            shoptype => new { Text = shoptype.TypeName, Value = shoptype.ShopTypeID })
                        .ToList()
                        .Select(
                            shptype =>
                            new SelectListItem()
                    {
                        Text = shptype.Text, Value = Convert.ToString(shptype.Value)
                    })
                        .ToArray();

                    SelectListItem[] DefaultItem =
                    {
                        new SelectListItem()
                        {
                            Text  = "Select Shop Type",
                            Value = "0"
                        }
                    };

                    var finalShopTypes = DefaultItem.Concat(ShopTypes).OrderBy(v => v.Value).ToArray();
                    var result         = new BSEntityFramework_ResultType(BSResult.Success, finalShopTypes, null, "Success");
                    return(result);
                }
            }
            catch (DbEntityValidationException dbValidationEx)
            {
                return(FormatException(dbValidationEx, null));
            }
            catch (Exception ex)
            {
                var logact = new LoggerActivity();
                var result = new BSEntityFramework_ResultType(BSResult.Fail, null, null, "Technical issue");
                logact.ErrorSetup("WebApp", "GetShopTypes Failed", "", "", "", ex.Message);
                return(result);
            }
        }
예제 #8
0
 public BSEntityFramework_ResultType InsertShopInPostal(TBL_ShopsInPostalCodes shopsInPostal, int shopID)
 {
     try
     {
         BSEntityFramework_ResultType result;
         using (BSDBEntities EF = new BSDBEntities())
         {
             using (var transaction = EF.Database.BeginTransaction())
             {
                 try
                 {
                     EF.Database.CommandTimeout = 180;
                     shopsInPostal.ShopID       = shopID;
                     EF.TBL_ShopsInPostalCodes.Add(shopsInPostal);
                     EF.SaveChanges();
                     transaction.Commit();
                 }
                 catch (Exception ex)
                 {
                     transaction.Rollback();
                     var logact = new LoggerActivity();
                     result = new BSEntityFramework_ResultType(BSResult.Fail, shopsInPostal, null, "Technical issue");
                     logact.SaveLog(logact.ErrorSetup("WebApp", "InsertShopPostalDetails Failed", "", "", "", ex.Message));
                     return(result);
                 }
             }
         }
         result = new BSEntityFramework_ResultType(BSResult.Success, shopsInPostal, null,
                                                   "Created Sucessfully");
         return(result);
     }
     catch (DbEntityValidationException dbValidationEx)
     {
         return(FormatException(dbValidationEx, shopsInPostal));
     }
     catch (Exception ex)
     {
         var logact = new LoggerActivity();
         var result = new BSEntityFramework_ResultType(BSResult.Fail, shopsInPostal, null, "Technical issue");
         logact.SaveLog(logact.ErrorSetup("WebApp", "InsertShopPostalDetails Failed", "", "", "", ex.Message));
         return(result);
     }
 }
 public BSEntityFramework_ResultType GetShops5TopProducts(int id)
 {
     try
     {
         using (BSDBEntities EF = new BSDBEntities())
         {
             var Top5Productlist = EF.TBL_Shops5TopProducts.Where(sht => sht.ShopID == id).ToArray();
             var result          = new BSEntityFramework_ResultType(BSResult.Success, Top5Productlist, null, "Success");
             return(result);
         }
     }
     catch (DbEntityValidationException dbValidationEx)
     {
         return(FormatException(dbValidationEx, null));
     }
     catch (Exception ex)
     {
         var logact = new LoggerActivity();
         var result = new BSEntityFramework_ResultType(BSResult.Fail, null, null, "Technical issue");
         logact.ErrorSetup("WebApp", "GetState Failed", "", "", "", ex.Message);
         return(result);
     }
 }
예제 #10
0
 public BSEntityFramework_ResultType GetALLStates()
 {
     try
     {
         using (BSDBEntities EF = new BSDBEntities())
         {
             var states = EF.TBL_States_CNFG.Select(st => st).ToArray();
             var result = new BSEntityFramework_ResultType(BSResult.Success, states, null, "Success");
             return(result);
         }
     }
     catch (DbEntityValidationException dbValidationEx)
     {
         return(FormatException(dbValidationEx, null));
     }
     catch (Exception ex)
     {
         var logact = new LoggerActivity();
         var result = new BSEntityFramework_ResultType(BSResult.Fail, null, null, "Technical issue");
         logact.ErrorSetup("WebApp", "GetState Failed", "", "", "", ex.Message);
         return(result);
     }
 }
예제 #11
0
 public BSEntityFramework_ResultType GetShopTypes(int id)
 {
     try
     {
         using (BSDBEntities EF = new BSDBEntities())
         {
             var ShopTypes = EF.TBL_ShopTypes_CNFG.Find(id);
             var result    = new BSEntityFramework_ResultType(BSResult.Success, ShopTypes, null, "Success");
             return(result);
         }
     }
     catch (DbEntityValidationException dbValidationEx)
     {
         return(FormatException(dbValidationEx, null));
     }
     catch (Exception ex)
     {
         var logact = new LoggerActivity();
         var result = new BSEntityFramework_ResultType(BSResult.Fail, null, null, "Technical issue");
         logact.ErrorSetup("WebApp", "GetShopTypes Failed", "", "", "", ex.Message);
         return(result);
     }
 }
예제 #12
0
 public BSEntityFramework_ResultType GetAllShope()
 {
     try
     {
         using (BSDBEntities EF = new BSDBEntities())
         {
             var Shop   = EF.TBL_ShopLoginDetails.Select(bs => bs).ToArray();
             var result = new BSEntityFramework_ResultType(BSResult.Success, Shop, null, "Success");
             return(result);
         }
     }
     catch (DbEntityValidationException dbValidationEx)
     {
         return(FormatException(dbValidationEx, null));
     }
     catch (Exception ex)
     {
         var logact = new LoggerActivity();
         var result = new BSEntityFramework_ResultType(BSResult.Fail, null, null, "Technical issue");
         logact.ErrorSetup("WebApp", "GetShope Failed", "", "", "", ex.Message);
         return(result);
     }
 }
예제 #13
0
 public BSEntityFramework_ResultType GetPostalCodesCNFG(string hint)
 {
     try
     {
         using (BSDBEntities EF = new BSDBEntities())
         {
             var PostalCodesCNFG =
                 EF.TBL_PostalCodes_CNFG.Where(p => p.PostCodeID.ToString().StartsWith(hint))
                 .Join(EF.TBL_Cities_CNFG, p => p.CityID, c => c.CityID, (p, c) => new
             {
                 PostalCodeId = p.PostCodeID,
                 CityName     = c.CityName,
                 StateID      = c.StateID
             }
                       ).Join(EF.TBL_States_CNFG, R => R.StateID, s => s.StateID, (R, s) => new
             {
                 PostalCodeId = R.PostalCodeId
                 , CityName   = R.CityName,
                 StateName    = s.StateName
             }).ToArray();
             var result = new BSEntityFramework_ResultType(BSResult.FailForValidation, PostalCodesCNFG, null, "Success");
             return(result);
         }
     }
     catch (DbEntityValidationException dbValidationEx)
     {
         return(FormatException(dbValidationEx, null));
     }
     catch (Exception ex)
     {
         var logact = new LoggerActivity();
         var result = new BSEntityFramework_ResultType(BSResult.Fail, null, null, "Technical issue");
         logact.ErrorSetup("WebApp", "GetPostalCodesCNFG Failed", "", "", "", ex.Message);
         return(result);
     }
 }
예제 #14
0
 public BSEntityFramework_ResultType UpdateShopTypes(TBL_ShopTypes_CNFG ShopTypes)
 {
     try
     {
         using (BSDBEntities EF = new BSDBEntities())
         {
             EF.TBL_ShopTypes_CNFG.AddOrUpdate(ShopTypes);
             EF.SaveChanges();
             var result = new BSEntityFramework_ResultType(BSResult.Success, ShopTypes, null, "Updated Successfully");
             return(result);
         }
     }
     catch (DbEntityValidationException dbValidationEx)
     {
         return(FormatException(dbValidationEx, ShopTypes));
     }
     catch (Exception ex)
     {
         var logact = new LoggerActivity();
         var result = new BSEntityFramework_ResultType(BSResult.Fail, ShopTypes, null, "Technical issue");
         logact.ErrorSetup("WebApp", "UpdateShopTypes Failed", "", "", "", ex.Message);
         return(result);
     }
 }
예제 #15
0
        public BSEntityFramework_ResultType InsertShopOffer(AddShopOffersViewModel newShopOffer)
        {
            try
            {
                using (BSDBEntities EF = new BSDBEntities())
                {
                    var shopId      = newShopOffer.ShopOffer.ShopID;
                    var totalOffers = EF.TBL_ShopOffers.Count(x => x.ShopID == shopId) + 1;
                    newShopOffer.ShopOffer.OfferID
                        = CommonSafeConvert.ToInt(Convert.ToString(shopId) + Convert.ToString(totalOffers));
                    foreach (var prod in newShopOffer.OfferonProducts)
                    {
                        prod.CreatedBy  = newShopOffer.ShopOffer.CreatedBy;
                        prod.CreateDate = DateTime.Now;
                        prod.IsActive   = true;
                    }
                    newShopOffer.ShopOffer.TBL_OfferOnProducts = (newShopOffer.OfferonProducts);
                    EF.TBL_ShopOffers.Add(newShopOffer.ShopOffer);
                    EF.SaveChanges();
                }

                var result = new BSEntityFramework_ResultType(BSResult.Success, newShopOffer.ShopOffer, null, "Created Sucessfully");
                return(result);
            }
            catch (DbEntityValidationException dbValidationEx)
            {
                return(FormatException(dbValidationEx, newShopOffer));
            }
            catch (Exception ex)
            {
                var logact = new LoggerActivity();
                var result = new BSEntityFramework_ResultType(BSResult.Fail, newShopOffer, null, "Technical issue");
                logact.ErrorSetup("WebApp", "InsertShopOffer Failed", "", "", "", ex.Message);
                return(result);
            }
        }
예제 #16
0
        public BSEntityFramework_ResultType GetProductListView(int shopId, string sortColumnName, string sortOrder, int pageSize, int currentPage,
                                                               string prodName       = "", string brandName = "", string barCode = "", int productType = 0,
                                                               bool isAvailable      = true,
                                                               string availableQty   = "",
                                                               bool isActive         = true,
                                                               int prodCategory      = 0,
                                                               int prodSubType       = 0,
                                                               decimal prodMrp       = 0,
                                                               decimal prodShopPrice = 0
                                                               )
        {
            var List        = new object();
            int totalPage   = 0;
            int totalRecord = 0;

            using (BSDBEntities EF = new BSDBEntities())
            {
                var prod =
                    EF.TBL_Products.Where(prd => prd.ShopID == shopId && prd.IsActive &&
                                          (brandName == null || brandName == "0" || brandName.Trim() == "" || prd.ProductBrand.Equals(brandName)) &&
                                          (prodName == null || prodName.Trim() == "" || prd.ProductName.Equals(prodName)) &&
                                          (barCode == null || barCode.Trim() == "" || prd.BarCode.Equals(barCode)) &&
                                          (productType == 0 || prd.ProductTypeID == productType) &&
                                          (prd.IsAvailable == isAvailable) &&
                                          (availableQty == null || availableQty.Trim() == "" || prd.ProductBrand.Equals(availableQty)) &&
                                          (prd.IsActive.Equals(isActive)) &&
                                          (prodCategory == 0 || prd.ProductCategoryID.Equals(prodCategory)) &&
                                          (prodSubType == 0 || prd.ProductSubTypeID.Equals(prodSubType)) &&
                                          (prodMrp == 0 || prd.MRP == prodMrp) &&
                                          (prodShopPrice == 0 || prd.ShopPrice == prodShopPrice)
                                          );

                var prodListBS = prod.Select(prd => new {
                    prd.ProductID,
                    prd.ProductName,
                    prd.ProductBrand,
                    prd.BarCode,
                    prd.IsActive,
                    IsAvailable = prd.IsActive,
                    prd.AvailableQuantity,
                    prd.MRP,
                    prd.ShopPrice,
                    prd.OtherJsonDetails,
                    prd.ProductCategoryID,
                    prd.TBL_ProductCategories_CNFG.ProductCategoryName,
                    prd.ProductTypeID,
                    prd.TBL_ProductType_CNFG.ProductTypeName,
                    prd.ProductSubTypeID,
                    prd.TBL_ProductSubType_CNFG.ProductSubTypeName,
                    prd.ShopID
                }).ToArray();


                totalRecord    = prodListBS.Length;
                sortColumnName = sortColumnName ?? "ProductID";
                if (pageSize > 0)
                {
                    totalPage = totalRecord / pageSize + ((totalRecord % pageSize) > 0 ? 1 : 0);
                    List      = prodListBS
                                .OrderBy(sortColumnName + " " + sortOrder)
                                .Skip(pageSize * (currentPage - 1))
                                .Take(pageSize).ToArray();
                }
                else
                {
                    var prodList = prodListBS.ToArray();
                    List = prodList;
                }
            }

            var jsonresult = new JsonResult
            {
                Data = new { List = List, totalPage = totalPage, sortColumnName = sortColumnName, sortOrder = sortOrder, currentPage = currentPage },
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };

            var result = new BSEntityFramework_ResultType(BSResult.Success, List, null, "Fetched Successfully");

            return(result);
        }
예제 #17
0
        public BSEntityFramework_ResultType GetShopOfferListView(int shopId, string sortColumnName, string sortOrder, int pageSize, int currentPage,
                                                                 string offerShortDetails = "",
                                                                 DateTime?offerStartDate  = null,
                                                                 DateTime?offerEndDate    = null,
                                                                 string offerOnBrand      = "",
                                                                 bool?isOfferOnProduct    = null,
                                                                 bool?isActive            = null
                                                                 )
        {
            var List        = new object();
            int totalPage   = 0;
            int totalRecord = 0;

            using (BSDBEntities EF = new BSDBEntities())
            {
                var offers =
                    EF.TBL_ShopOffers.Where(shopoffer => shopoffer.ShopID == shopId &&
                                            (offerShortDetails == null || offerShortDetails.Trim() == "" || shopoffer.OfferShortText.Contains(offerShortDetails)) &&
                                            (offerStartDate == null || offerStartDate == DateTime.MinValue || shopoffer.OfferStartDate.Equals(offerStartDate)) &&
                                            (offerEndDate == null || offerEndDate == DateTime.MinValue || shopoffer.OfferEndDate.Equals(offerEndDate)) &&
                                            (offerOnBrand == null || offerOnBrand.Trim() == "" || shopoffer.OfferOnBrand == offerOnBrand) &&
                                            (isOfferOnProduct == null || isOfferOnProduct == shopoffer.IsOfferOnProducts) &&
                                            (isActive == null || isActive == shopoffer.IsActive)
                                            );

                var offlistBS = offers.Join(EF.TBL_ShopLoginDetails, off => off.CreatedBy
                                            , CrdUser => CrdUser.ShopLoginDetailsID
                                            , (off, CrdUser) => new {
                    // .Select(off => new {
                    off.OfferShortText,
                    off.OfferStartDate,
                    off.OfferEndDate,
                    off.ShopID,
                    off.OfferID,
                    off.IsActive,
                    off.OfferOnBrand,
                    off.OfferDetailText,
                    off.IsOfferOnProducts,
                    off.CreateDate,
                    CreatedBy = CrdUser.LoginName,
                    off.UpdateDate,
                    off.UpdatedBy
                }).GroupJoin(EF.TBL_ShopLoginDetails
                             , off => off.UpdatedBy
                             , updtUser => updtUser.ShopLoginDetailsID
                             , (offersinfo, updateuserDetails) => new {
                    offersinfo        = offersinfo,
                    updateuserDetails = updateuserDetails
                })
                                .SelectMany(
                    Gj => Gj.updateuserDetails.DefaultIfEmpty(),
                    (off, updtUser) => new {
                    offersinfo        = off,
                    updateuserDetails = updtUser
                })
                                .Select(ofd => new {
                    ofd.offersinfo.offersinfo.OfferShortText,
                    ofd.offersinfo.offersinfo.OfferStartDate,
                    ofd.offersinfo.offersinfo.OfferEndDate,
                    ofd.offersinfo.offersinfo.ShopID,
                    ofd.offersinfo.offersinfo.OfferID,
                    ofd.offersinfo.offersinfo.IsActive,
                    ofd.offersinfo.offersinfo.OfferOnBrand,
                    ofd.offersinfo.offersinfo.OfferDetailText,
                    ofd.offersinfo.offersinfo.IsOfferOnProducts,
                    ofd.offersinfo.offersinfo.CreateDate,
                    ofd.offersinfo.offersinfo.CreatedBy,
                    ofd.offersinfo.offersinfo.UpdateDate,
                    UpdatedBy = ofd.updateuserDetails.LoginName
                })
                                .ToArray();


                totalRecord    = offlistBS.Length;
                sortColumnName = sortColumnName ?? "OfferID";
                if (pageSize > 0)
                {
                    totalPage = totalRecord / pageSize + ((totalRecord % pageSize) > 0 ? 1 : 0);
                    List      = offlistBS
                                .OrderBy(sortColumnName + " " + sortOrder)
                                .Skip(pageSize * (currentPage - 1))
                                .Take(pageSize).ToArray();
                }
                else
                {
                    var prodList = offlistBS.ToArray();
                    List = prodList;
                }
            }

            var jsonresult = new JsonResult
            {
                Data = new { List = List, totalPage = totalPage, sortColumnName = sortColumnName, sortOrder = sortOrder, currentPage = currentPage },
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };

            var result = new BSEntityFramework_ResultType(BSResult.Success, List, null, "Fetched Successfully");

            return(result);
        }