public PurchaseOrder OfflinePayment(string userId) { CartLogic cartLogic = new CartLogic(); PurchaseOrderLogic orderLogic = new PurchaseOrderLogic(); PurchaseOrder order = new PurchaseOrder(); try { var items = cartLogic.GetCartItems(userId); if (items.Count == 0) { return(null); } order.UserId = userId; order.CreatedDate = DateTime.Now.Date; order.PurchaseOrderNo = orderLogic.CreatePONumber(); List <PurchaseOrderItem> poItemList = new List <PurchaseOrderItem>(); var total = 0.0; foreach (var item in items) { PurchaseOrderItem poItem = new PurchaseOrderItem() { Quantity = item.Quantity, SubscriptionId = item.SubscriptionTypeId }; poItemList.Add(poItem); total += item.Price; } order.Total = total; var obj = orderLogic.CreatePurchaseOrder(order); if (obj != null && poItemList.Count > 0) { POItemLogic itemLogic = new POItemLogic(); itemLogic.CreateItem(poItemList, obj.Id); foreach (var item in items) { item.IsPurchased = true; cartLogic.UpdateCartItem(item); } } return(obj); } catch (Exception ex) { ErrorMessage = ex.Message; } return(null); }
public SubscriptionList OnlinePayment(string userId) { List <UserSubscription> subsList = new List <UserSubscription>(); CartLogic cartLogic = new CartLogic() { UserManager = UserManager, RoleManager = RoleManager }; UserSubscriptionLogic userSubLogic = new UserSubscriptionLogic() { UserManager = UserManager, RoleManager = RoleManager }; var cartItems = cartLogic.GetCartItems(userId); if (cartItems.Count > 0) { foreach (CartItem item in cartItems) { UserSubscription usersubs = new UserSubscription() { UserId = userId, SubscriptionTypeId = item.SubscriptionTypeId, ActivationDate = DateTime.Now.Date, Quantity = item.Quantity }; usersubs.ExpireDate = usersubs.ActivationDate.AddDays(item.SubType.ActiveDays).Date; subsList.Add(usersubs); } var dataList = userSubLogic.CreateUserSubscriptionList(subsList, userId); foreach (var item in cartItems) { item.IsPurchased = true; cartLogic.UpdateCartItem(item); } return(dataList); } else { ErrorMessage = cartLogic.ErrorMessage; return(null); } }