public OperationResult <StallViewModel> Get(int id) { var result = new OperationResult <StallViewModel>(true); //get stall StallViewModel stallVM = null; Models.Stall stall = null; using (var db = new StallEntities()) { stall = Models.Stall.FindById(id, db); if (stall == null) { result.Succeeded = false; result.Message = "Can not load products for stall " + id; return(result); } stallVM = new StallViewModel() { Id = stall.Id, Name = stall.StallName, Categories = stall.Categories, ShowCategory = stall.ShowCategory, InitialProducts = new List <StallProductViewModel>() }; } //initial products var initProducts = stall.SellingProducts; if (stall.ShowCategory) { //recommend initProducts = initProducts.Take(stall.RecommendNumber).ToList(); } foreach (var p in initProducts) { if (p.Active == true && p.Stock > 0 && p.Price != null) { stallVM.InitialProducts.Add(new StallProductViewModel() { Id = p.Id, Name = p.BaseName, Image = p.Image, Price = p.PriceIncTax, StallId = p.StallId, StallName = p.Stall.StallName, Description = p.Description, Stock = p.Stock, TrackInventory = p.TrackInventory }); } } result.Data = stallVM; return(result); }
// GET: Manage public ActionResult Stall(int id) { var stall = Models.Stall.FindById(id, _db); if (stall == null) { stall = new Models.Stall(); } return(View(stall)); }
public void TestStoreDeliveryOptions() { var json = LoadJson(@"D:\Works\Greenspot\Greenspot.Stall\Greenspot.Stall.Tests\data\store_setting_2.json"); var stall = new Models.Stall(); stall.SettingJson = json; var delivery = stall.GetDeliveryOptions(new DateTime(2016, 10, 20, 16, 30, 0), 7, "nz:auckland:auckland:auckland-city", null, null); Assert.AreEqual(7, delivery.Count); }
public void TestPlatformDeliveryOptions() { var json = LoadJson(@"D:\Works\Greenspot\Greenspot.Stall\Greenspot.Stall.Tests\platform.setting.json"); var stall = new Models.Stall(); stall.SettingJson = json; var delivery = StallApplication.GetDeliveryOptions(stall, new DateTime(2016, 10, 20, 16, 30, 0), 7, "nz:auckland:auckland:auckland-city", null, null); Assert.AreEqual(3, delivery.Count); }
public void TestPickupOptions() { var json = LoadJson(@"D:\Works\Greenspot\Greenspot.Stall\Greenspot.Stall.Tests\data\store_setting_1.json"); var stall = new Models.Stall(); stall.SettingJson = json; var pickup = stall.GetPickupOptions(new DateTime(2016, 10, 20), 6); Assert.AreEqual(11, pickup.Count); Assert.IsTrue(pickup[0].PickUpAddress.StartsWith("1103")); Assert.IsTrue(pickup[6].PickUpAddress.StartsWith("ABC")); Assert.AreEqual(new DateTime(2016, 10, 20, 17, 0, 0), pickup[0].To); Assert.AreEqual(new DateTime(2016, 10, 21, 10, 0, 0), pickup[1].From); Assert.AreEqual(new DateTime(2016, 10, 22, 22, 0, 0), pickup[2].To); Assert.AreEqual(new DateTime(2016, 10, 24, 10, 0, 0), pickup[3].From); Assert.AreEqual(new DateTime(2016, 10, 26, 22, 0, 0), pickup[5].To); Assert.AreEqual(new DateTime(2016, 10, 20, 14, 0, 0), pickup[6].From); Assert.AreEqual(new DateTime(2016, 10, 26, 18, 0, 0), pickup[10].To); }
public OperationResult <IList <DeliveryOptionCollectionViewModel> > GetDeliveryOptions(int id, [FromUri] string country, [FromUri] string city, [FromUri] string suburb, [FromUri] string area, [FromUri] decimal orderAmount) { string areaStr = $"{country}:{city}:{area.Replace(' ', '-')}".ToLower(); var result = new OperationResult <IList <DeliveryOptionCollectionViewModel> >(true) { Data = new List <DeliveryOptionCollectionViewModel>() }; Models.Stall stall = null; //get stall using (var db = new StallEntities()) { stall = Models.Stall.FindById(id, db); if (stall == null) { result.Succeeded = false; result.Message = "Can not load delivery schedule for stall " + id; return(result); } } //minimum delivery order amount if (stall.Setting.Delivery.MinOrderAmount != null && orderAmount < stall.Setting.Delivery.MinOrderAmount) { return(result); } // var advDays = stall.Setting.MaxAdvancedOrderDays > StallApplication.Setting.MaxAdvancedOrderDays ? StallApplication.Setting.MaxAdvancedOrderDays : stall.Setting.MaxAdvancedOrderDays; var advMins = stall.Setting.MinDeliveryAdvancedMinutes < StallApplication.Setting.MinDeliveryAdvancedMinutes ? StallApplication.Setting.MinDeliveryAdvancedMinutes : stall.Setting.MinDeliveryAdvancedMinutes; //get distance var distance = stall.GetDistance(country, city, suburb); IList <DeliveryOrPickupOption> deliveryOpts; if (stall.Setting.Delivery.DeliveryType == Models.Settings.DeliveryTypes.StoreOnly) { //get store delivery deliveryOpts = stall.GetDeliveryOptions(DateTime.Now.AddMinutes(advMins), advDays, areaStr, distance, orderAmount); } else { //get platform deliveryOpts = StallApplication.GetDeliveryOptions(stall, DateTime.Now.AddMinutes(advMins), advDays, areaStr, distance, orderAmount); } DeliveryOptionCollectionViewModel collection = null; DateTime currDate = DateTime.MinValue.Date; foreach (var opt in deliveryOpts) { //free delivery if (stall.Setting.Delivery.FreeDeliveryOrderAmount != null && orderAmount >= stall.Setting.Delivery.FreeDeliveryOrderAmount) { opt.Fee = 0; } var optObjs = opt.Divide(); foreach (var optObj in optObjs) { if (!optObj.IsApplicableToArea(areaStr)) { //has suitable area = available continue; } if (opt.From.Date != currDate) { //new date group collection = new DeliveryOptionCollectionViewModel(); result.Data.Add(collection); currDate = opt.From.Date; } //add collection.Options.Add(optObj); } } return(result); }
public OperationResult <IList <StallProductViewModel> > ProductsByCategory(int id, int cateIdx = 0) { var result = new OperationResult <IList <StallProductViewModel> >(true) { Data = new List <StallProductViewModel>() }; //get stall Models.Stall stall = null; using (var db = new StallEntities()) { stall = Models.Stall.FindById(id, db); if (stall == null) { result.Succeeded = false; result.Message = "Can not load products for stall " + id; return(result); } } IList <Product> products; if (Category.Recommend.Index == cateIdx) { products = stall.SellingProducts.Take(stall.RecommendNumber).ToList(); } else { string category = null; if (Category.Others.Index == cateIdx) { category = Category.Others.Identifier; } else { foreach (var c in stall.Categories) { if (c.Index == cateIdx) { category = c.Identifier; break; } } } products = stall.GetProductsByCategory(category); } foreach (var p in products) { if (p.Active == true && p.Stock > 0 && p.Price != null) { result.Data.Add(new StallProductViewModel() { Id = p.Id, Name = p.BaseName, Image = p.Image, Price = p.PriceIncTax, StallId = p.StallId, StallName = p.Stall.StallName, Description = p.Description, Stock = p.Stock, TrackInventory = p.TrackInventory }); } } return(result); }
public OperationResult <IList <PickupOptionGroupViewModel> > GetPickUpOptions(int id) { var result = new OperationResult <IList <PickupOptionGroupViewModel> >(true) { Data = new List <PickupOptionGroupViewModel>() }; Models.Stall stall = null; //get stall using (var db = new StallEntities()) { stall = Models.Stall.FindById(id, db); if (stall == null) { result.Succeeded = false; result.Message = "Can not load delivery schedule for stall " + id; return(result); } } var advDays = stall.Setting.MaxAdvancedOrderDays > StallApplication.Setting.MaxAdvancedOrderDays ? StallApplication.Setting.MaxAdvancedOrderDays : stall.Setting.MaxAdvancedOrderDays; var advMins = stall.Setting.MinPickupAdvancedMinutes < StallApplication.Setting.MinPickupAdvancedMinutes ? StallApplication.Setting.MinPickupAdvancedMinutes : stall.Setting.MinPickupAdvancedMinutes; //get pickup delivery var pickupOptions = stall.GetPickupOptions(DateTime.Now.AddMinutes(advMins), advDays); PickupOptionGroupViewModel addrGrp = null; PickupOptionGroupViewModel dateGrp = null; string currAddr = null; DateTime currDate = DateTime.MinValue.Date; foreach (var opt in pickupOptions) { if (!opt.PickUpAddress.Equals(currAddr)) { //new address addrGrp = new PickupOptionGroupViewModel() { Groups = new List <PickupOptionGroupViewModel>() }; result.Data.Add(addrGrp); currAddr = opt.PickUpAddress; currDate = DateTime.MinValue.Date; } if (opt.From.Date != currDate) { //new date group dateGrp = new PickupOptionGroupViewModel(); addrGrp.Groups.Add(dateGrp); currDate = opt.From.Date; } //add options if (opt.DivisionType == Models.Settings.TimeDivisionTypes.Undivisible) { dateGrp.Options.Add(opt); } else { ((List <DeliveryOrPickupOption>)dateGrp.Options).AddRange(opt.Divide()); } } return(result); }