public ActionResult Create(ReportageGroup reportageGroup) { if (ModelState.IsValid) { Product product = new Product() { Id = Guid.NewGuid(), IsDeleted = false, IsActive = reportageGroup.IsActive, CreationDate = DateTime.Now, Title = reportageGroup.Title, ProductTypeId = db.ProductTypes.FirstOrDefault(c => c.Name == "package").Id }; db.Products.Add(product); reportageGroup.ProductId = product.Id; reportageGroup.IsDeleted = false; reportageGroup.CreationDate = DateTime.Now; reportageGroup.Id = Guid.NewGuid(); db.ReportageGroups.Add(reportageGroup); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(reportageGroup)); }
public decimal GetPackagetotal(List <ProductInCart> products, string type) { decimal amount = 0; if (type == "total") { foreach (ProductInCart orderDetail in products) { ReportageGroup reportageGroup = db.ReportageGroups.FirstOrDefault(c => c.ProductId == orderDetail.Product.Id); amount = amount + (reportageGroup.Price.Value * orderDetail.Quantity); } } if (type == "subtotal") { foreach (ProductInCart orderDetail in products) { amount = amount + Convert.ToDecimal(orderDetail.RowAmount); } } return(amount); }
public ActionResult DeleteConfirmed(Guid id) { ReportageGroup reportageGroup = db.ReportageGroups.Find(id); reportageGroup.IsDeleted = true; reportageGroup.DeletionDate = DateTime.Now; db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: ReportageGroups/Edit/5 public ActionResult Edit(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ReportageGroup reportageGroup = db.ReportageGroups.Find(id); if (reportageGroup == null) { return(HttpNotFound()); } return(View(reportageGroup)); }
public ActionResult Edit(ReportageGroup reportageGroup) { if (ModelState.IsValid) { Product product = db.Products.Find(reportageGroup.ProductId); if (product != null) { product.Title = reportageGroup.Title; product.IsActive = reportageGroup.IsActive; } reportageGroup.IsDeleted = false; db.Entry(reportageGroup).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(reportageGroup)); }
public void InsertOrderDetailInfo(Order order) { List <OrderDetail> orderDetails = db.OrderDetails.Where(c => c.OrderId == order.Id).ToList(); foreach (OrderDetail orderDetail in orderDetails) { if (order.OrderType == "package") { ReportageGroup reportageGroup = db.ReportageGroups .FirstOrDefault(c => c.ProductId == orderDetail.ProductId); List <Reportage> reportages = db.Reportages.Where(c => c.ReportageGroupId == reportageGroup.Id && c.IsActive && c.IsDeleted == false).ToList(); for (int i = 0; i < orderDetail.Quantity; i++) { foreach (Reportage reportage in reportages) { OrderDetailInformation orderDetailInformation = new OrderDetailInformation() { Id = Guid.NewGuid(), OrderDetailId = orderDetail.Id, OrderDetailStatusId = db.OrderDetailStatuses.FirstOrDefault(current => current.Code == 1).Id, CreationDate = DateTime.Now, IsDeleted = false, IsActive = true, ProductId = reportage.ProductId }; db.OrderDetailInformations.Add(orderDetailInformation); } } } else if (order.OrderType == "reportage") { for (int i = 0; i < orderDetail.Quantity; i++) { OrderDetailInformation orderDetailInformation = new OrderDetailInformation() { Id = Guid.NewGuid(), OrderDetailId = orderDetail.Id, OrderDetailStatusId = db.OrderDetailStatuses.FirstOrDefault(current => current.Code == 1).Id, CreationDate = DateTime.Now, IsDeleted = false, IsActive = true, }; db.OrderDetailInformations.Add(orderDetailInformation); } } else if (order.OrderType == "backlink") { for (int i = 0; i < orderDetail.Quantity; i++) { OrderDetailInformation orderDetailInformation = new OrderDetailInformation() { Id = Guid.NewGuid(), OrderDetailId = orderDetail.Id, OrderDetailStatusId = db.OrderDetailStatuses.FirstOrDefault(current => current.Code == 1).Id, CreationDate = DateTime.Now, IsDeleted = false, IsActive = true, }; db.OrderDetailInformations.Add(orderDetailInformation); } } } }
public decimal GetAmountByProductForInsertOrderDetail(Product product) { decimal amount = 0; if (product.ProductType.Name == "reportage") { Reportage reportage = db.Reportages.FirstOrDefault(c => c.ProductId == product.Id); amount = reportage.Price; if (reportage.IsInPromotion) { if (reportage.DiscountAmount != null) { amount = reportage.DiscountAmount.Value; } } return(amount); } else if (product.ProductType.Name == "backlink") { BackLinkDetail backLinkDetail = db.BackLinkDetails.FirstOrDefault(c => c.ProductId == product.Id); if (backLinkDetail != null) { amount = backLinkDetail.Amount; } else { amount = 0; } return(amount); } else if (product.ProductType.Name == "package") { ReportageGroup reportageGroup = db.ReportageGroups.FirstOrDefault(c => c.ProductId == product.Id); if (reportageGroup != null) { if (reportageGroup.Price != null) { amount = reportageGroup.Price.Value; } else { amount = 0; } } else { amount = 0; } return(amount); } return(amount); }
public ActionResult GetSideBarBasket(string productType) { try { SidebarBasketViewModel cart = new SidebarBasketViewModel(); List <ProductInSidebar> productInCarts = GetSidebarProductInBasketByCoockie(productType); cart.Products = productInCarts; if (productType == "reportage") { decimal subTotal = GetSidebarSubtotal(productInCarts); cart.SubTotal = subTotal.ToString("n0") + " تومان"; decimal income = GetSidebarOrderIncome(productInCarts); decimal discountAmount = GetStepDiscountAmount(income); cart.DiscountAmount = discountAmount.ToString("n0") + " تومان"; cart.Total = (subTotal - discountAmount).ToString("n0"); } else if (productType == "backlink") { decimal subTotal = GetSidebarSubtotal(productInCarts); cart.SubTotal = subTotal.ToString("n0") + " تومان"; cart.DiscountAmount = "0"; cart.Total = (subTotal).ToString("n0"); } else if (productType == "package") { decimal discount = 0; decimal total = 0; decimal subTotal = 0; foreach (ProductInSidebar productInCart in productInCarts) { Guid productId = new Guid(productInCart.Id); ReportageGroup reportageGroup = db.ReportageGroups.FirstOrDefault(c => c.ProductId == productId); if (reportageGroup != null) { if (reportageGroup.Value != null && reportageGroup.Price != null) { subTotal = subTotal + reportageGroup.Value.Value; total = total + reportageGroup.Price.Value; } } } discount = subTotal - total; cart.SubTotal = subTotal.ToString("n0") + " تومان"; cart.DiscountAmount = discount.ToString("n0") + " تومان"; cart.Total = total.ToString("n0"); } return(Json(cart, JsonRequestBehavior.AllowGet)); } catch (Exception e) { return(Json("false", JsonRequestBehavior.AllowGet)); } }
public ActionResult Basket(string basketType, int?orderCode) { if (User.Identity.IsAuthenticated) { var identity = (System.Security.Claims.ClaimsIdentity)User.Identity; Guid userId = new Guid(identity.Name); User user = db.Users.FirstOrDefault(current => current.Id == userId); if (user != null) { ViewBag.FullName = user.FullName; ViewBag.CellNumber = user.CellNum; ViewBag.isAuthorize = "true"; } else { ViewBag.isAuthorize = "false"; } } else { ViewBag.isAuthorize = "false"; } CartViewModel cart = new CartViewModel(); cart.Menu = menuHelper.ReturnMenu(); cart.FooterLink = menuHelper.GetFooterLink(); List <ProductInCart> productInCarts = new List <ProductInCart>(); if (string.IsNullOrEmpty(orderCode.ToString())) { productInCarts = GetProductInBasketByCoockie(basketType); } else { Order order = db.Orders.Where(x => x.Code == orderCode.Value).FirstOrDefault(); basketType = order.OrderType; productInCarts = GetProductsInCartByOrder(orderCode.Value); } cart.Products = productInCarts; if (basketType == "reportage") { decimal subTotal = GetSubtotal(productInCarts); cart.SubTotal = subTotal.ToString("n0") + " تومان"; decimal income = GetOrderIncome(productInCarts); decimal discountAmount = GetStepDiscountAmount(income); cart.DiscountAmount = discountAmount.ToString("n0") + " تومان"; cart.Total = (subTotal - discountAmount).ToString("n0"); } else if (basketType == "backlink") { decimal subTotal = GetSubtotal(productInCarts); cart.SubTotal = subTotal.ToString("n0") + " تومان"; cart.DiscountAmount = "0"; cart.Total = (subTotal).ToString("n0"); } else if (basketType == "package") { decimal discount = 0; decimal total = 0; decimal subTotal = 0; foreach (ProductInCart productInCart in productInCarts) { Guid productId = new Guid(productInCart.Id); ReportageGroup reportageGroup = db.ReportageGroups.FirstOrDefault(c => c.ProductId == productId); if (reportageGroup != null) { if (reportageGroup.Value != null && reportageGroup.Price != null) { subTotal = subTotal + reportageGroup.Value.Value; total = total + reportageGroup.Price.Value; } } } discount = subTotal - total; cart.SubTotal = subTotal.ToString("n0") + " تومان"; cart.DiscountAmount = discount.ToString("n0") + " تومان"; cart.Total = total.ToString("n0"); } return(View(cart)); }