public static bool UpgradePremium(Member m) { if (m == null) { throw new ArgumentNullException("Can't match a product."); } using (var db = new ShopContext()) { var mm = (from u in db.MemberShips where u.Id == m.Id select u).FirstOrDefault(); if (mm == null) { return(false); } db.MemberShips.Attach(mm); var entry = db.Entry(mm); entry.Entity.Role = Role.Premium; db.SaveChanges(); return(true); } }
/// <summary> /// /// </summary> /// <param name="p"></param> /// <returns></returns> public static bool UpdateImagePath(int id, string imagePath) { if (id <= 0) { throw new ArgumentNullException("Can't match a product."); } using (var db = new ShopContext()) { var product = (from u in db.Products where u.ProductId == id select u).FirstOrDefault(); if (product == null) { return(false); } db.Products.Attach(product); var entry = db.Entry(product); entry.Entity.ImagePath = imagePath; db.SaveChanges(); return(true); } }
/// <summary> /// /// </summary> /// <param name="id"></param> public static bool UpdateOrder(OrderDTO o) { if (o == null) { throw new ArgumentNullException("Can't match a product."); } using (var db = new ShopContext()) { var order = (from u in db.Orders where u.Id == o.OrderId select u).FirstOrDefault(); if (order == null) { return(false); } db.Orders.Attach(order); var entry = db.Entry(order); entry.Entity.OrderStatus = db.OrderStatuses.First(os => os.Name == o.Status); db.SaveChanges(); return(true); } }