public async Task <OperationResult <bool> > UpdateProductById(string id, StallEntities db) { var result = new OperationResult(false); //load product var productResult = await VendProduct.GetProductByIdAsync(id, Prefix, await StallApplication.GetAccessTokenAsync(Prefix)); if (productResult?.Products == null) { result.Message = string.Format("无法获取商品[{0}]信息", id); return(result); } //set products var vProducts = productResult?.Products; foreach (var vP in vProducts) { if (vP.Id.Equals(id)) { var p = Product.ConvertFrom(vP, Id); return(p.Save(db)); } } result.Message = string.Format("无法获取商品[{0}]信息", id); return(result); }
public static IList <DeliveryAddress> FindByUserId(string id, StallEntities db) { if (string.IsNullOrEmpty(id)) { return(null); } return(db.DeliveryAddresses.Where(x => x.UserId.Equals(id)).ToList()); }
public static IList <Stall> FindByVendPrefix(string prefix, StallEntities db) { if (string.IsNullOrEmpty(prefix)) { return(null); } return(db.Stalls.Where(x => x.Prefix.Equals(prefix)).ToList()); }
public static Stall FindByName(string name, StallEntities db) { if (string.IsNullOrEmpty(name)) { return(null); } return(db.Stalls.FirstOrDefault(x => x.StallName.Equals(name))); }
public static IList <Stall> FindByUserId(string userId, StallEntities db) { if (string.IsNullOrEmpty(userId)) { return(null); } return(db.Stalls.Where(x => x.UserId.Equals(userId)).ToList()); }
public static IList <Order> FindByUserId(string id, StallEntities db) { if (string.IsNullOrEmpty(id)) { return(null); } return(db.Orders.Include(x => x.Stall).Where(x => x.UserId.Equals(id)) .OrderByDescending(x => x.CreateTime).ToList()); }
public static Stall FindByRetailerId(string id, StallEntities db) { if (string.IsNullOrEmpty(id)) { return(null); } return(db.Stalls.Include(x => x.Products).FirstOrDefault(x => x.RetailerId.Equals(id))); }
public static bool SetInventoryById(string id, int count, StallEntities db) { var p = FindById(id, db); if (p == null) { return(false); } p.Stock = count; return(db.SaveChanges() > 0); }
public static bool DeleteById(string id, StallEntities db) { var p = FindById(id, db); if (p == null) { return(false); } db.Products.Remove(p); return(db.SaveChanges() > 0); }
public static IList <User> GetByRole(StallEntities db, string roleName) { var role = db.Roles.FirstOrDefault(x => x.Name.Equals(roleName)); if (role == null) { return(new List <User>()); } return(role.Users.ToList()); }
public static Suburb Find(string name, string city, string countryCode, StallEntities db) { name = name.ToLower(); city = city.ToLower(); countryCode = countryCode.ToLower(); if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(city) || string.IsNullOrEmpty(countryCode)) { return(null); } return(db.Suburbs.FirstOrDefault(x => x.Name.ToLower().Equals(name) && x.City.ToLower().Equals(city) && x.CountryCode.ToLower().Equals(countryCode))); }
public bool Save(StallEntities db) { var result = UserManager.Update(_greenspotUser); if (!result.Succeeded) { return(false); } db.Set <User>().AddOrUpdate(this); db.SaveChanges(); return(true); }
public static int?GetDistance(string id, StallEntities db) { var rec = FindById(id, db); if (rec != null && rec.Meters != null) { return(rec.Meters); } else { return(null); } }
/// <summary> /// get recommend stall /// </summary> /// <param name="category"></param> /// <param name="area"></param> /// <param name="db"></param> /// <param name="takeAmount"></param> /// <returns></returns> public static IList <Stall> GetRecommend(string category, string area, StallEntities db, int takeAmount = 50) { var result = db.Stalls.Include(x => x.Products).Where(x => StallStatus.Online.Equals(x.Status)); if (!string.IsNullOrEmpty(area)) { result = result.Where(x => x.Area.StartsWith(area)); } if (!string.IsNullOrEmpty(category)) { result = result.Where(x => x.StallType.Equals(category)); } return(result.OrderBy(x => x.RecommendIndex).Take(takeAmount).ToList()); }
public static int?GetDistance(string depCountry, string depCity, string depSuburb, string destCountry, string destCity, string destSuburb) { //get from db using (var db = new StallEntities()) { var id = BuilId(depCountry, depCity, depSuburb, destCountry, destCity, destSuburb); var dbResult = GetDistance(id, db); if (dbResult != null) { return(dbResult); } //call google map api var glResult = GoogleMapHelper.GetSuburbDistanceFromGoogleMapApi(depCountry, depCity, depSuburb, destCountry, destCity, destSuburb, GreenspotConfiguration.AccessAccounts["google.map"].Secret); if (glResult == null) { StallApplication.SysError($"[GOOGLE DISTANCE]failed to get distance {depCountry},{depCity},{depSuburb} to {destCountry},{destCity},{destSuburb}"); return(null); } else { //save to db var distance = new SuburbDistance() { ID = id, DepartureCountryCode = depCountry, DepartureCity = depCity, DepartureSuburb = depSuburb, DestinationCountryCode = destCountry, DestinationCity = destCity, DestinationSuburb = destSuburb, Meters = glResult.Value }; db.SuburbDistances.Add(distance); db.SaveChanges(); return(glResult.Value); } } }
public bool Save() { using (var db = new StallEntities()) { try { db.Set <Stall>().AddOrUpdate(this); //db.Set<StallContact>().AddOrUpdate(Contacts.ToArray()); db.Set <Product>().AddOrUpdate(Products.ToArray()); //db.Set<VendWebhook>().AddOrUpdate(Webhooks.ToArray()); db.SaveChanges(); return(true); } catch { return(false); } } }
public static Payment CreatePayment(StallEntities db, decimal amount, string orderIds = null) { //set total price var payment = new Payment() { Amount = amount, CreateTime = DateTime.Now, OrderIds = orderIds, HasPaid = false }; db.Payments.Add(payment); if (db.SaveChanges() > 0) { return(payment); } else { return(null); } }
/// <summary> /// /// </summary> /// <param name="db"></param> /// <param name="category"></param> /// <param name="area"></param> /// <param name="keyword"></param> /// <param name="page"></param> /// <param name="pageSize"></param> /// <returns></returns> public static IList <Stall> Search(StallEntities db, string category, string area, string keyword, int page = 0, int pageSize = 10) { var result = db.Stalls.Include(x => x.Products).Where(x => StallStatus.Online.Equals(x.Status)); if (!string.IsNullOrEmpty(area)) { result = result.Where(x => x.Area.StartsWith(area)); } if (!string.IsNullOrEmpty(keyword)) { result = result.Where(x => x.StallName.ToLower().Contains(keyword.ToLower())); } if (!string.IsNullOrEmpty(category)) { result = result.Where(x => x.StallType.Equals(category)); } return(result.OrderBy(x => x.StallName).Skip(pageSize * page).Take(pageSize).ToList()); }
//public static IList<Product> GetHomepageProducts(StallEntities db) //{ // Func<Product, bool> condition = delegate (Product p) { return string.IsNullOrEmpty(p.VariantParentId) && p.Active == true; }; // return GetProducts(condition, db).Take(50).ToList(); //} public static IList <Product> Search(StallEntities db, string stallType, string area, string keyworkd, int page = 0, int pageSize = 10) { var products = db.Products.Include(x => x.Stall) .Where(x => Stall.StallStatus.Online.Equals(x.Stall.Status) && x.Active && string.IsNullOrEmpty(x.VariantParentId)); if (!string.IsNullOrEmpty(stallType)) { products = products.Where(x => x.Stall.StallType.Equals(stallType)); } if (!string.IsNullOrEmpty(area)) { products = products.Where(x => x.Stall.Area.StartsWith(area)); } if (!string.IsNullOrEmpty(keyworkd)) { products = products.Where(x => x.BaseName.ToLower().Contains(keyworkd.ToLower())); } return(products.OrderBy(p => p.RecommendIndex).Skip(pageSize * page).Take(pageSize).ToList()); }
public async Task Notify(StallEntities db, IList <string> openids) { //vend if (!HasSendToVend) { HasSendToVend = await SendToVend(); } if (!HasSendToWechat) { //wechat HasSendToWechat = await SendToWechat(openids); } if (IsPrintOrder && !HasSendToPrinter) { //print HasSendToPrinter = await SendToPrinter(); } //update db.SaveChanges(); }
public static Product FindById(string id, StallEntities db) { return(db.Products.FirstOrDefault(x => x.Id.Equals(id))); }
public OperationResult <bool> Delete(StallEntities db) { db.Products.Remove(this); return(new OperationResult <bool>(db.SaveChanges() > 0)); }
public OperationResult <bool> Save(StallEntities db) { db.Set <Product>().AddOrUpdate(this); return(new OperationResult <bool>(db.SaveChanges() > 0)); }
public static SuburbDistance FindById(string id, StallEntities db) { return(db.SuburbDistances.FirstOrDefault(x => x.ID.Equals(id))); }
public static async Task <OperationResult> InitMultiStall(int id, StallEntities db) { var result = new OperationResult(false); var baseStall = Stall.FindById(id, db); if (baseStall == null) { result.Message = $"Stall {id} is not exist"; return(result); } //load base info var infoResult = await baseStall.LoadInfo(); if (!infoResult.Succeeded) { result.Message = infoResult.Message; return(result); } //load product var productResult = await baseStall.LoadProduct(); if (!productResult.Succeeded) { result.Message = productResult.Message; return(result); } //create webhook var webhookResult = await baseStall.CreateWebhook(); if (!webhookResult.Succeeded) { result.Message = webhookResult.Message; return(result); } //load suppliers var supplierResult = await SDK.Vend.Supplier.GetSuppliersAsync(baseStall.Prefix, await StallApplication.GetAccessTokenAsync(baseStall.Prefix)); var suppliers = supplierResult.Suppliers; if (suppliers == null || suppliers.Count == 0) { // result.Message = "无法获取VEND Supplier信息"; return(result); } //seperate by supplier var unStalledProduct = new List <Product>(); var stalls = new SortedDictionary <string, Stall>(); foreach (var p in baseStall.Products) { //loop product if (string.IsNullOrEmpty(p.SupplierName)) { //no supplier product unStalledProduct.Add(p); continue; } Stall currStall; if (stalls.ContainsKey(p.SupplierName)) { //exist stall currStall = stalls[p.SupplierName]; } else { #region new stall var supplier = suppliers.FirstOrDefault(x => x.Name.Equals(p.SupplierName)); //new stall currStall = new Stall() { UserId = baseStall.UserId, Prefix = baseStall.Prefix, StallName = p.SupplierName, RetailerId = baseStall.RetailerId, RegisterId = baseStall.RegisterId, RegisterName = baseStall.RegisterName, OutletId = baseStall.OutletId, PaymentTypeId = baseStall.PaymentTypeId, DeliveryProductId = baseStall.DeliveryProductId, DiscountProductId = baseStall.DiscountProductId, ContactName = $"{supplier.Contact.FirstName} {supplier.Contact.LastName}".Trim(), Mobile = supplier.Contact.Mobile, Phone = supplier.Contact.Phone, Address1 = supplier.Contact.PhysicalAddress1, Address2 = supplier.Contact.PhysicalAddress2, City = supplier.Contact.PhysicalCity, CountryId = supplier.Contact.PhysicalCountryId, Postcode = supplier.Contact.PhysicalPostcode, StateOrRegion = supplier.Contact.PhysicalState, Suburb = supplier.Contact.PhysicalSuburb, TimeZone = baseStall.TimeZone, Status = StallStatus.Offline }; stalls.Add(p.SupplierName, currStall); #endregion } currStall.Products.Add(p); } //save to db using (var trans = db.Database.BeginTransaction()) { //save base stall try { //keep unstalled product baseStall.Products = unStalledProduct; db.Set <Stall>().AddOrUpdate(baseStall); db.SaveChanges(); } catch (Exception ex) { result.Message = $"failed to save stall {baseStall.StallName}:{ex.ToString()}"; trans.Rollback(); return(result); } foreach (var s in stalls.Values) { try { db.Set <Stall>().AddOrUpdate(s); db.SaveChanges(); } catch (Exception ex) { result.Message = $"failed to save stall {s.StallName}:{ex.ToString()}"; trans.Rollback(); return(result); } } trans.Commit(); } result.Succeeded = true; return(result); }
public bool Save(StallEntities db) { db.Payments.AddOrUpdate(this); return(db.SaveChanges() > 0); }
public bool Save(StallEntities db) { db.DeliveryAddresses.Add(this); return(db.SaveChanges() >= 0); }
public static DeliveryAddress FindByCode(string userId, string code, StallEntities db) { return(db.DeliveryAddresses.FirstOrDefault(x => x.UserId.Equals(userId) && x.Code.Equals(code))); }
public static Stall FindById(int id, StallEntities db) { return(db.Stalls.Include(x => x.Products).FirstOrDefault(x => x.Id == id)); }
public static Stall FindByRetailerIdAndSuppilerName(string retailerId, string supplierName, StallEntities db) { if (string.IsNullOrEmpty(retailerId)) { return(null); } var stalls = db.Stalls.Include(x => x.Products).Where(x => retailerId.Equals(x.RetailerId)); var isUnion = stalls.Any(x => x.IsUnion); if (!isUnion) { //normal stall return(stalls.FirstOrDefault()); } else { //is union var baseStall = stalls.FirstOrDefault(x => StallStatus.UnionMain.Equals(x.Status) && x.IsUnion); if (string.IsNullOrEmpty(supplierName)) { //not supplier infor return(baseStall); } //got stall var stall = stalls.FirstOrDefault(x => supplierName.Equals(x.StallName) && x.IsUnion); return(stall ?? baseStall); } }