public async Task <bool> PostShopingCartAction(ShoppingCartDetailDTO model) { var item = HanomaContext.ShoppingCartDetail.Find(model.Id); if (item != null) { item.StatusCart = model.StatusCart; item.ReasonCancel = model.ReasonCancel; // Lý do hủy item.IsCancelByBuyer = model.IsCancelByBuyer; item.LastEditBy = Guid.Parse(model.UserId); item.LastEditDate = DateTime.Now; await HanomaContext.SaveChangesAsync(); } else { return(false); } return(true); }
public async Task <ShoppingCartDetailDTO> PutShopingCartAction(ShoppingCartDetailDTO model) { var output = new ShoppingCartDetailDTO(); var result = await _repoWrapper.ShoppingCart.PostShopingCartAction(model); if (result) { output.ErrorCode = "00"; output.Message = "Xử lý thành công"; var shopingCartDetail = await _repoWrapper.ShoppingCart.FirstOrDefaultAsync(x => x.Id == model.Id); var product = await _repoWrapper.Product.FirstOrDefaultAsync(x => x.Product_ID == shopingCartDetail.ProductId); string message = ""; string title = ""; FCMMessageOutputDTO notiModel = new FCMMessageOutputDTO(); if (model.StatusCart == 2) // Chờ xác nhận { title = "Xác nhận đơn hàng"; message = $"Đơn hàng {shopingCartDetail.ShopingCartCode}, đã được cửa hàng xác nhận"; notiModel.Data.formId = "CART_SELL"; notiModel.Topic = shopingCartDetail.CreateBy.ToString(); // Noti cho người mua notiModel.Data.id = shopingCartDetail.Id; notiModel.Data.notiSpecType = 0; } else if (model.StatusCart == 3) //Hoàn thành { title = "Xác nhận đơn hàng hoàn tất"; message = $"Đơn hàng {shopingCartDetail.ShopingCartCode}, đã được hoàn tất"; notiModel.Data.formId = "CART_SELL"; notiModel.Topic = shopingCartDetail.CreateBy.ToString(); // Noti cho người mua notiModel.Data.id = shopingCartDetail.Id; notiModel.Data.notiSpecType = 0; } else if (model.StatusCart == 4) // Đã hủy { if (model.IsCancelByBuyer == 1) { title = "Đơn hàng bị hủy"; message = $"Đơn hàng {shopingCartDetail.ShopingCartCode}, đã hủy bởi người mua - lý do: {model.ReasonCancel}"; notiModel.Data.formId = "CART_BUY"; notiModel.Topic = product?.CreateBy.ToString(); // Thông báo tới gian hàng notiModel.Data.id = shopingCartDetail.Id; notiModel.Data.notiSpecType = 0; } else if (model.IsCancelByBuyer == 0) { title = "Đơn hàng bị hủy"; message = $"Đơn hàng {shopingCartDetail.ShopingCartCode}, đã hủy bởi người bán - lý do: {model.ReasonCancel}"; notiModel.Data.formId = "CART_SELL"; notiModel.Topic = shopingCartDetail.CreateBy.ToString(); // Noti cho người mua notiModel.Data.id = shopingCartDetail.Id; notiModel.Data.notiSpecType = 0; } } notiModel.Notification.Title = title; notiModel.Notification.Body = message; //notiModel.Topic = product?.CreateBy.ToString(); // Thông báo tới gian hàng var pushNoti = Utils.Util.SendMessageFirebase(notiModel); FCMMessage fCMMessage = new FCMMessage(); fCMMessage.Title = notiModel.Notification.Title; fCMMessage.Body = notiModel.Notification.Body; fCMMessage.CreateBy = product?.CreateBy; fCMMessage.CreateDate = DateTime.Now; fCMMessage.LastEditBy = product?.CreateBy; fCMMessage.LastEditDate = DateTime.Now; fCMMessage.UserID = product?.CreateBy; fCMMessage.Topic = notiModel.Topic; fCMMessage.NotificationType = notiModel.Data.notifyType; fCMMessage.Form_ID = notiModel.Data.formId; fCMMessage.ParameterId = notiModel.Data.id; fCMMessage.FullUrl = notiModel.Data.fullUrl; fCMMessage.FullUrlImage = notiModel.Data.fullUrlImage; fCMMessage.NotiSpecType = 1; fCMMessage.IsPinTop = notiModel.Data.isPinTop; fCMMessage.FormNameApp = notiModel.Data.formAppName; fCMMessage.ProductTypeId = notiModel.Data.typeId; fCMMessage.CategoryId = notiModel.Data.categoryId; fCMMessage.FullUrlImage = $"https://hanoma-cdn.s3.cloud.cmctelecom.vn/DataMobile/Notify/notifyDefault.png"; fCMMessage.Content = message; fCMMessage.FullUrl = ""; fCMMessage.HasRead = 0; await _repoWrapper.FCMMessage.AddNewFCMMessage(fCMMessage); } else { output.ErrorCode = "01"; output.Message = "Có lỗi trong quá trình xử lý đơn hàng"; } return(output); }