public Customer UpdateWithSpec(int id) { IDataQuerySpecification <Customer> qrySpec = new CustomerDataQuerySpecification(cust => cust.Id == id && !cust.IsInactive); qrySpec.Includes.Add(cust => cust.DeliveryProducts); var c = qry.Find(qrySpec); c.Description = $"Customer test {c.Name} - {DateTime.Now}"; c.CommencementDate = DateTime.Today.AddMonths(-3); if (c.DeliveryProducts.Count > 0) { c.DeliveryProducts[0].Price = 11.50M; c.DeliveryProducts[0].SetDirty(); } var dp = new DeliveryProduct() { Name = $"DP {new Random().Next(1, 99)}", HasDate = true, Price = 20M, SortOrder = 20, IsNew = true }; c.DeliveryProducts.Add(dp); cmd.Update(c, cmdSpec); return(c); }
public async Task <ActionResult <DeliveryProduct> > PostDeliveryProduct(DeliveryProduct deliveryProduct) { _context.DeliveryProduct.Add(deliveryProduct); await _context.SaveChangesAsync(); return(CreatedAtAction("GetDeliveryProduct", new { id = deliveryProduct.DeliveryProductId }, deliveryProduct)); }
public Customer CreateWithSpec(string name) { var c = new Customer { Name = name, Description = $"Customer test {name}", CommencementDate = DateTime.Today }; var dp = new DeliveryProduct() { Name = $"DP {new Random().Next(1, 99)}", HasDate = false, Price = 10M, SortOrder = 10, IsNew = true }; c.DeliveryProducts.Add(dp); Action <Customer> action = delegate(Customer cust) { cust.DeliveryProducts.ToList().ForEach(prod => { cmd.SetEntityState <DeliveryProduct, int>(prod); }); }; IDataCommandSpecification <Customer> spec = new CustomerDataCommandSpecification(action); cmd.Create(c); return(c); }
public DeliveryFeeResult GetDeliveryFee(BargainUser bargainOrder, string province, string city, DeliveryFeeSumMethond sumMethod, DeliveryConfig config = null) { if (config == null) { config = DeliveryConfigBLL.SingleModel.GetConfig(new Bargain { Id = bargainOrder.BId }); } DeliveryProduct formatProduct = new DeliveryProduct { Count = 1, Name = bargainOrder.BName, TemplateId = config.Attr.DeliveryTemplateId, Weight = config.Attr.Weight, Amount = bargainOrder.CurrentPrice, }; DeliveryFeeResult result = GetDeliveryFeeCommon(new List <DeliveryProduct> { formatProduct }, province, city, sumMethod); if (result.InRange) { DeliveryDiscount discount = GetDiscount(bargainOrder.aid, bargainOrder.CurrentPrice); result.Fee = discount.HasDiscount ? discount.DiscountPrice : result.Fee; result.Message = discount.HasDiscount ? discount.DiscountInfo : result.Message; } return(result); }
public async Task <IActionResult> PutDeliveryProduct(int id, DeliveryProduct deliveryProduct) { if (id != deliveryProduct.DeliveryProductId) { return(BadRequest()); } _context.Entry(deliveryProduct).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DeliveryProductExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IActionResult CheckOutSimple(string bill) { string generateCodeCheck = RandomString(20); CheckOut checkOut = JsonConvert.DeserializeObject <CheckOut>(bill); // Create Bill Bill createdBill = CreateBill(checkOut, generateCodeCheck); // Create Delivery DeliveryProduct delivery = CreateDeliveryProduct(checkOut, createdBill); // create Bill Detail List <BillDetail> details = CreateBillDetail(createdBill); //update amount from stock // get details with category name is food List <BillDetail> foodDetails = details.Where(p => IsFood(p.ProductId)).ToList(); // get details with category name is toy List <BillDetail> toyDetails = details.Where(p => IsToy(p.ProductId)).ToList(); // get details with category name is costume List <BillDetail> cosDetails = details.Where(p => IsCostume(p.ProductId)).ToList(); // update each list details UpdateStock(foodDetails, toyDetails, cosDetails); // remove cart HttpContext.Session.Remove("cart"); return(Ok(createdBill)); }
private DeliveryProduct CreateDeliveryProduct(CheckOut checkOut, Bill bill) { DeliveryProduct delivery = new DeliveryProduct() { DeliveryProductAddress = checkOut.DeliveryProductAddress, DeliveryProductBillId = bill.BillId, DeliveryProductPhoneNumber = checkOut.DeliveryProductPhoneNumber, DeliveryProductNote = checkOut.DeliveryProductNote, DeliveryProductStateId = checkOut.DeliveryProductStateId, DeliveryProductTypeId = checkOut.DeliveryProductTypeId }; CredentialModel credential = JsonConvert.DeserializeObject <CredentialModel>(HttpContext.Session.GetString(Constants.VM)); string token = credential.JwToken; // post Delivery using (HttpClient client = Common.HelperClient.GetClient(token)) { client.BaseAddress = new Uri(Common.Constants.BASE_URI); var postTask = client.PostAsJsonAsync <DeliveryProduct>(Constants.DELIVERY_PRODUCT, delivery); postTask.Wait(); var result = postTask.Result; if (result.IsSuccessStatusCode) { return(delivery); } else { return(null); } } }
public IActionResult UpdateDeliveryState(string billCode, int stateId) { CredentialManage credential = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE)); Bill bill = GetApiBills.GetBills(credential).SingleOrDefault(p => p.GenerateCodeCheck == billCode); DeliveryProduct delivery = GetApiDeliveryProducts.GetDeliveryProducts().SingleOrDefault(p => p.DeliveryProductBillId == bill.BillId); delivery.DeliveryProductStateId = stateId; if (GetApiDeliveryStates.GetDeliveryProductStates() .SingleOrDefault(p => p.DeliveryProductStateId == stateId).DeliveryProductStateName == "Đã giao hàng") { bill.IsCompleted = true; bill.DateOfDelivered = DateTime.Now; GetApiBills.Update(bill, credential.JwToken); } GetApiDeliveryProducts.Update(delivery, credential.JwToken); // sender mail UserProfile profile = GetApiUserProfile.GetUserProfiles().SingleOrDefault(p => p.UserProfileId == bill.UserProfileId); string body = "Đơn hàng có mã #" + bill.GenerateCodeCheck + " đã cập nhật trạng thái vận chuyển mới: " + GetApiDeliveryStates.GetDeliveryProductStates() .SingleOrDefault(p => p.DeliveryProductStateId == stateId).DeliveryProductStateName; SenderEmail.SendMail(profile.UserProfileEmail, "PETSHOP: UPDATE DELIVERY STATE'S YOUR BILL", body); return(Json(bill)); }
public IActionResult BillDetail(int billId) { BillModelView bill = GetBills().SingleOrDefault(p => p.BillId == billId); DeliveryProduct delivery = GetApiDeliveryProducts.GetDeliveryProducts().SingleOrDefault(p => p.DeliveryProductBillId == bill.BillId); bill.delivery = delivery; return(View(bill)); }
public static void Update(DeliveryProduct delivery, string token) { using (var client = Common.HelperClient.GetClient(token)) { client.BaseAddress = new Uri(Common.Constants.BASE_URI); var putTask = client.PutAsJsonAsync <DeliveryProduct>(Constants.DELIVERY_PRODUCT + "/" + delivery.DeliveryProductId, delivery); putTask.Wait(); } }
public List <BillModelView> GetBills() { //get credential CredentialModel credential = HttpContext.Session.GetObject <CredentialModel>(Constants.VM); // get profile UserProfile profile = GetApiUserProfile.GetUserProfiles().SingleOrDefault(p => p.UserProfileEmail == credential.AccountUserName); // get all Bill with profileID from server List <BillModelView> bills = GetApiMyBills.GetBills(credential).Select(p => new BillModelView() { BillId = p.BillId, BillCode = p.GenerateCodeCheck, DateOfPurchase = p.DateOfPurchase, DateDelivery = Convert.ToDateTime(p.DateOfDelivered), TotalPrice = p.TotalPrice, PaymentMethodId = p.PaymentMethodTypeId, IsDelivery = p.IsDelivery, IsCancel = p.IsCancel, }).ToList(); // get payment method foreach (var bill in bills) { bill.PaymentMethodName = GetApiPaymentMethodTypes.GetPaymentMethodTypes().SingleOrDefault(p => p.PaymentMethodTypeId == bill.PaymentMethodId).PaymentMethodTypeName; } // get bill detail foreach (var item in bills) { List <BillDetailModel> details = GetApiBillDetails.GetBillDetails().Where(p => p.BillId == item.BillId) .Select(p => new BillDetailModel() { ProductId = p.ProductId, ProductName = GetApiProducts.GetProducts().SingleOrDefault(k => k.ProductId == p.ProductId).ProductName, Amount = p.ProductAmount, Price = p.ProductPriceCurrent, NoteSize = p.NoteSize, Image = GetApiProducts.GetProducts().SingleOrDefault(k => k.ProductId == p.ProductId).ProductImage, }).ToList(); item.BillDetail = details; // get delivery of bill DeliveryProduct delivery = GetApiDeliveryProducts.GetDeliveryProducts().SingleOrDefault(p => p.DeliveryProductBillId == item.BillId); // get state of bill item.DeliveryProductStateId = delivery.DeliveryProductStateId; item.DeliveryStateName = GetApiDeliveryStates.GetDeliveryProductStates().SingleOrDefault(p => p.DeliveryProductStateId == delivery.DeliveryProductStateId).DeliveryProductStateName; } return(bills); }
public IHttpActionResult CreateDeliveryProduct([FromBody] DeliveryProduct input) { using (ctx = new YwtDbContext()) { input.LastUpdateTime = DateTime.Now; input.CreateTime = DateTime.Now; input.Status = 1; ctx.DeliveryProduct.Add(input); ctx.SaveChanges(); return(Ok()); } }
public DeliveryFeeResult GetFreightInfo(PinGoods good, int buyCount, string province, string city) { PinStore store = PinStoreBLL.SingleModel.GetModelByAid_Id(good.aId, good.storeId); if (store == null) { return(new DeliveryFeeResult { InRange = true, Message = "店铺不存在" }); } if (!store.setting.freightSwitch) { return(new DeliveryFeeResult { InRange = true, Message = "未开启运费模板功能,默认零元运费" }); } DeliveryFeeSumMethond sumMethod; if (!Enum.TryParse(store.setting.freightSumRule.ToString(), out sumMethod)) { return(new DeliveryFeeResult { Message = "运费规则设置异常" }); } DeliveryProduct product = new DeliveryProduct { Count = buyCount, Id = good.id, Name = good.name, TemplateId = good.FreightTemplate, Weight = good.GetAttrbute().Weight, }; DeliveryFeeResult result = GetDeliveryFeeCommon(new List <DeliveryProduct> { product }, province, city, sumMethod); if (result.Fee > 0) { result.Message = $"[{sumMethod}]{result.Message}"; } return(result); }
public IActionResult BillDetail(int billId) { CredentialManage credential = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE)); Bill p = GetApiBills.GetBills(credential).SingleOrDefault(p => p.BillId == billId); BillModelView bill = new BillModelView() { BillId = p.BillId, BillCode = p.GenerateCodeCheck, DateOfPurchase = p.DateOfPurchase, DateDelivery = Convert.ToDateTime(p.DateOfDelivered), TotalPrice = p.TotalPrice, PaymentMethodId = p.PaymentMethodTypeId, IsDelivery = p.IsDelivery, IsCancel = p.IsCancel, IsApprove = p.IsApprove, IsCompleted = p.IsCompleted, PaymentMethodName = GetApiPaymentMethodTypes.GetPaymentMethodTypes().SingleOrDefault(k => k.PaymentMethodTypeId == p.PaymentMethodTypeId).PaymentMethodTypeName, }; List <BillDetailModel> details = GetApiBillDetails.GetBillDetails().Where(p => p.BillId == bill.BillId) .Select(p => new BillDetailModel() { ProductId = p.ProductId, ProductName = GetApiProducts.GetProducts().SingleOrDefault(k => k.ProductId == p.ProductId).ProductName, Amount = p.ProductAmount, Price = p.ProductPriceCurrent, NoteSize = p.NoteSize, Image = GetApiProducts.GetProducts().SingleOrDefault(k => k.ProductId == p.ProductId).ProductImage, }).ToList(); bill.BillDetail = details; // get delivery DeliveryProduct delivery = GetApiDeliveryProducts.GetDeliveryProducts().SingleOrDefault(p => p.DeliveryProductBillId == bill.BillId); bill.delivery = delivery; // get state of bill bill.DeliveryProductStateId = delivery.DeliveryProductStateId; bill.DeliveryStateName = GetApiDeliveryStates.GetDeliveryProductStates().SingleOrDefault(p => p.DeliveryProductStateId == delivery.DeliveryProductStateId).DeliveryProductStateName; return(Json(bill)); }