public BSEntityFramework_ResultType GetInfrastructureByPostal(string postalCode) { try { var pinCode = Convert.ToInt32(postalCode); using (BSDBEntities EF = new BSDBEntities()) { var Infrastructure = EF.TBL_Infrastructure_CNFG.Where(inf => inf.PostalCodeID == pinCode) .Select(inf => new { inf.InfrastructureID, inf.InfrastructureName }).ToArray(); var result = new BSEntityFramework_ResultType(BSResult.FailForValidation, Infrastructure, null, "Success"); return(result); } } catch (InvalidCastException dbValidationEx) { var result = new BSEntityFramework_ResultType(BSResult.FailForValidation, null, null, "Invalid Postal Code"); 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", "GetInfrastructure Failed", "", "", "", ex.Message); return(result); } }
public BSEntityFramework_ResultType InsertOffersonProduct(List <TBL_OfferOnProducts> offeronProducts, int offerid) { try { using (BSDBEntities EF = new BSDBEntities()) { foreach (var product in offeronProducts) { product.OfferID = offerid; EF.TBL_OfferOnProducts.Add(product); } EF.SaveChanges(); } var result = new BSEntityFramework_ResultType(BSResult.Success, offeronProducts, null, "Created Sucessfully"); return(result); } catch (DbEntityValidationException dbValidationEx) { return(FormatException(dbValidationEx, offeronProducts)); } catch (Exception ex) { var logact = new LoggerActivity(); var result = new BSEntityFramework_ResultType(BSResult.Fail, offeronProducts, null, "Technical issue"); logact.ErrorSetup("WebApp", "Insert Offers on Product Failed", "", "", "", ex.Message); return(result); } }
public BSEntityFramework_ResultType GetShopAddress(int shopId) { try { using (BSDBEntities EF = new BSDBEntities()) { var shopAddress = EF.TBL_Shops.Where(shop => shop.ShopID == shopId) .Select( shop => shop.ShopAddress) .First(); var result = new BSEntityFramework_ResultType(BSResult.Success, shopAddress, 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", "Shop Address Failed Retrived", "", "", "", ex.Message); return(result); } }
public BSEntityFramework_ResultType InsertShopTypes(TBL_ShopTypes_CNFG newShopTypes) { try { using (BSDBEntities EF = new BSDBEntities()) { EF.TBL_ShopTypes_CNFG.Add(newShopTypes); EF.SaveChanges(); } var result = new BSEntityFramework_ResultType(BSResult.Success, newShopTypes, null, "Created Sucessfully"); return(result); } catch (DbEntityValidationException dbValidationEx) { return(FormatException(dbValidationEx, newShopTypes)); } catch (Exception ex) { var logact = new LoggerActivity(); var result = new BSEntityFramework_ResultType(BSResult.Fail, newShopTypes, null, "Technical issue"); logact.ErrorSetup("WebApp", "InsertShopTypes Failed", "", "", "", ex.Message); return(result); } }
public BSEntityFramework_ResultType GetOfferImage(int shopId, int offerId) { try { using (BSDBEntities EF = new BSDBEntities()) { var offerImage = EF.TBL_ShopOffers.FirstOrDefault(p => p.OfferID == offerId); var result = new BSEntityFramework_ResultType(BSResult.Success, new ImageDetails() { ImgID = offerImage?.OfferID ?? -1, ImgData = offerImage != null ? String.Format("data:image/jpg;base64,{0}", Convert.ToBase64String(offerImage.OfferImage != null? offerImage.OfferImage : new byte[] {})) : null }, null, "Updated Successfully"); return(result); } } catch (Exception ex) { var logact = new LoggerActivity(); var result = new BSEntityFramework_ResultType(BSResult.Fail, null, null, "Technical issue"); logact.ErrorSetup("WebApp", "Fetch Product Image Failed", "", "", "", ex.Message); return(null); } }
public BSEntityFramework_ResultType InsertProductImages(List <TBL_ProductImages> productImages, long productid) { try { using (BSDBEntities EF = new BSDBEntities()) { foreach (var prodimage in productImages) { prodimage.ProductID = productid; EF.TBL_ProductImages.Add(prodimage); } EF.SaveChanges(); } var result = new BSEntityFramework_ResultType(BSResult.Success, productImages, null, "Created Sucessfully"); return(result); } catch (DbEntityValidationException dbValidationEx) { return(FormatException(dbValidationEx, productImages)); } catch (Exception ex) { var logact = new LoggerActivity(); var result = new BSEntityFramework_ResultType(BSResult.Fail, productImages, null, "Technical issue"); logact.ErrorSetup("WebApp", "Insert ProductImages Failed", "", "", "", ex.Message); return(result); } }
public BSEntityFramework_ResultType InsertTop5ProductForShop(List <TBL_Shops5TopProducts> top5List) { try { using (BSDBEntities EF = new BSDBEntities()) { foreach (TBL_Shops5TopProducts p in top5List) { EF.TBL_Shops5TopProducts.Add(p); } EF.SaveChanges(); } var result = new BSEntityFramework_ResultType(BSResult.Success, null, null, "Created Sucessfully"); return(result); } catch (DbEntityValidationException dbValidationEx) { return(FormatException(dbValidationEx, null)); } catch (Exception ex) { var logact = new LoggerActivity(); var result = new BSEntityFramework_ResultType(BSResult.Fail, top5List, null, "Technical issue"); logact.ErrorSetup("WebApp", "InsertState Failed", "", "", "", ex.Message); return(result); } }
public BSEntityFramework_ResultType InsertShopMapDetails(TBL_ShopMapDetails shopsMapDetails) { try { BSEntityFramework_ResultType result; using (BSDBEntities EF = new BSDBEntities()) { using (var transaction = EF.Database.BeginTransaction()) { try { EF.Database.CommandTimeout = 180; if (shopsMapDetails.CreateDate == DateTime.MinValue) { shopsMapDetails.CreateDate = DateTime.Now; EF.TBL_ShopMapDetails.Add(shopsMapDetails); } else { EF.TBL_ShopMapDetails.Attach(shopsMapDetails); EF.Entry(shopsMapDetails).Property(x => x.Latitude).IsModified = true; EF.Entry(shopsMapDetails).Property(x => x.Longitude).IsModified = true; EF.Entry(shopsMapDetails).Property(x => x.UpdateDate).IsModified = true; EF.Entry(shopsMapDetails).Property(x => x.UpdatedBy).IsModified = true; } EF.SaveChanges(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); var logact = new LoggerActivity(); result = new BSEntityFramework_ResultType(BSResult.Fail, shopsMapDetails, null, "Technical issue"); logact.SaveLog(logact.ErrorSetup("WebApp", "shops Map Details Failed", "", "", "", ex.Message)); return(result); } } } result = new BSEntityFramework_ResultType(BSResult.Success, shopsMapDetails, null, "Created Sucessfully"); return(result); } catch (DbEntityValidationException dbValidationEx) { return(FormatException(dbValidationEx, shopsMapDetails)); } catch (Exception ex) { var logact = new LoggerActivity(); var result = new BSEntityFramework_ResultType(BSResult.Fail, shopsMapDetails, null, "Technical issue"); logact.SaveLog(logact.ErrorSetup("WebApp", "shops Map Details Failed", "", "", "", ex.Message)); return(result); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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 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); } }
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); } }
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); } }
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); } }
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); } }
public BSEntityFramework_ResultType UpdateProductType(TBL_ProductType_CNFG ProductType) { try { using (BSDBEntities EF = new BSDBEntities()) { EF.TBL_ProductType_CNFG.AddOrUpdate(ProductType); EF.SaveChanges(); var result = new BSEntityFramework_ResultType(BSResult.Success, ProductType, null, "Updated Successfully"); return(result); } } catch (DbEntityValidationException dbValidationEx) { return(FormatException(dbValidationEx, ProductType)); } catch (Exception ex) { var logact = new LoggerActivity(); var result = new BSEntityFramework_ResultType(BSResult.Fail, ProductType, null, "Technical issue"); logact.ErrorSetup("WebApp", "UpdateProductType Failed", "", "", "", ex.Message); return(result); } }
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); } }