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 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 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)); }
public List <BillViewModel> getBills() { CredentialManage credential = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE)); List <BillViewModel> bills = GetApiBills.GetBills(credential).Select(p => new BillViewModel() { BillId = p.BillId, UserProfileEmail = GetApiUserProfile.GetUserProfiles().SingleOrDefault(k => k.UserProfileId == p.UserProfileId).UserProfileEmail, DateOfPurchase = p.DateOfPurchase, CurrentDeliveryState = GetApiDeliveryStates.GetDeliveryProductStates().SingleOrDefault(h => h.DeliveryProductStateId == GetApiDeliveryProducts.GetDeliveryProducts().SingleOrDefault(k => k.DeliveryProductBillId == p.BillId).DeliveryProductStateId).DeliveryProductStateName, IsDelivery = p.IsDelivery, DateOfDelivered = p.DateOfDelivered, GenerateCodeCheck = p.GenerateCodeCheck, PaymentMethodName = GetApiPaymentMethodTypes.GetPaymentMethodTypes().SingleOrDefault(k => k.PaymentMethodTypeId == p.PaymentMethodTypeId).PaymentMethodTypeName, IsCancel = p.IsCancel, TotalPrice = p.TotalPrice, IsApprove = p.IsApprove, IsCompleted = p.IsCompleted, CurrentDeliveryStateId = GetApiDeliveryProducts.GetDeliveryProducts().SingleOrDefault(k => k.DeliveryProductBillId == p.BillId).DeliveryProductStateId }).ToList(); return(bills); }