public static void Insert(ProductDiscount productDiscount) { using (var db = OnlineStoreDbContext.Entity) { db.ProductDiscounts.Add(productDiscount); db.SaveChanges(); } }
public static void Update(ProductDiscount productDiscount) { using (var db = OnlineStoreDbContext.Entity) { var orgProductDiscount = db.ProductDiscounts.Where(item => item.ID == productDiscount.ID).Single(); orgProductDiscount.ProductID = productDiscount.ProductID; orgProductDiscount.GroupID = productDiscount.GroupID; orgProductDiscount.RoleID = productDiscount.RoleID; orgProductDiscount.DiscountType = productDiscount.DiscountType; orgProductDiscount.Percent = productDiscount.Percent; orgProductDiscount.Price = productDiscount.Price; orgProductDiscount.Title = productDiscount.Title; orgProductDiscount.StartDate = productDiscount.StartDate; orgProductDiscount.EndDate = productDiscount.EndDate; orgProductDiscount.ProductDiscountStatus = productDiscount.ProductDiscountStatus; orgProductDiscount.LastUpdate = productDiscount.LastUpdate; db.SaveChanges(); } }
public static ProductDiscountItem GetProductDiscount(int productID, string userID, int?productVarientID = null) { List <ProductDiscount> productDiscounts = null; if (productVarientID.HasValue) { productDiscounts = ProductDiscounts.GetByVarientID(productID, productVarientID.Value); } else { productDiscounts = ProductDiscounts.GetByProductID(productID); } List <ProductDiscount> roleDiscounts = new List <ProductDiscount>(); if (!String.IsNullOrWhiteSpace(userID)) { var roles = UserRoles.GetByUserID(userID); foreach (var item in roles) { roleDiscounts.AddRange(ProductDiscounts.GetByRoleID(item.RoleId)); } } var groups = ProductGroups.GetByProductID(productID); List <ProductDiscount> groupDiscounts = new List <ProductDiscount>(); foreach (var item in groups) { groupDiscounts.AddRange(ProductDiscounts.GetByGroupID(item.GroupID)); } var productDiscountItem = new ProductDiscountItem(); var productDiscount = new ProductDiscount(); if (roleDiscounts.Count > 0) { productDiscount = roleDiscounts.Last(); } if (groupDiscounts.Count > 0) { productDiscount = groupDiscounts.Last(); } if (productDiscounts.Count > 0) { productDiscount = productDiscounts.Last(); } if (productDiscount != null) { productDiscountItem.ID = productDiscount.ID; productDiscountItem.DiscountType = productDiscount.DiscountType; switch (productDiscountItem.DiscountType) { case DiscountType.Percent: productDiscountItem.Value = productDiscount.Percent; break; case DiscountType.PriceAfter: productDiscountItem.Value = productDiscount.Price; break; case DiscountType.PriceBefore: productDiscountItem.Value = productDiscount.Price; break; case DiscountType.PriceBeforeAfter: productDiscountItem.Value = productDiscount.Price; productDiscountItem.Price_01 = productDiscount.Price_01; break; default: productDiscountItem.Value = 0; break; } } else { productDiscountItem.Value = 0; } return(productDiscountItem); }