public virtual void Delete(TEntity entityToDelete) { if (context.Entry(entityToDelete).State == EntityState.Detached) { dbSet.Attach(entityToDelete); } dbSet.Remove(entityToDelete); }
public void UpdateProfile(UserProfile user) { try { dbSet.Attach(user); Database.Entry(user).State = EntityState.Modified; } catch (Exception ex) { throw ex; } }
public void UpdateTradingLot(TradingLot tradingLot) { try { dbSet.Attach(tradingLot); Database.Entry(tradingLot).State = EntityState.Modified; } catch (Exception ex) { throw ex; } }
public void UpdateCategory(Category category) { try { dbSet.Attach(category); Database.Entry(category).State = EntityState.Modified; } catch (Exception ex) { throw ex; } }
public ActionResult IsCheckCars(int id) { var car = db.Cars.Find(id); if (car != null) { car.IsCheck = true; db.Entry(car).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("UnchecktedCars")); } return(HttpNotFound()); }
public bool UpdatePayment(Payment newPayment) { CoreValidator.ThrowIfNull(newPayment, nameof(newPayment)); CoreValidator.ThrowIfNegativeOrZero(newPayment.Id, nameof(newPayment.Id)); CoreValidator.ThrowIfNullOrEmpty(newPayment.PaymentTypeCode, nameof(newPayment.PaymentTypeCode)); CoreValidator.ThrowIfNegativeOrZero(newPayment.UserId, nameof(newPayment.UserId)); using (var db = new AuctionContext()) { var dbPayment = GetPayment(newPayment.Id); CoreValidator.ThrowIfNull(dbPayment, nameof(dbPayment)); db.Payments.Attach(dbPayment); dbPayment.PaymentTypeCode = newPayment.PaymentTypeCode; dbPayment.Type = newPayment.Type; dbPayment.UserId = newPayment.UserId; db.Entry(dbPayment).State = EntityState.Modified; db.SaveChanges(); return(true); } }
public ActionResult Edit([Bind(Include = "UserID,OldPassword,UserName,UserPassword,ConfirmPassword,Password,UserEmail,UserLevel,UserFirstName,UserLastName,UserDOB,UserAddress,UserCity")] User user) { if (ModelState.IsValid) { if (Helpers.Helpers.EncodePasswordMd5(user.OldPassword) != user.Password) { ViewBag.Errormsg = "Mật khẩu cũ nhập không đúng "; return(View(user)); } user.Password = Helpers.Helpers.EncodePasswordMd5(user.UserPassword); db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public void SubmitBid(Product product) { var vm = new PlaceBidViewModel { BidAmount = product.LastBidAmount, Title = product.Title }; _windowManager.ShowDialog(vm); if (vm.IsCancelled) { return; } using (var db = new AuctionContext()) { product.LastBidAmount = vm.BidAmount; db.Entry(product).State = EntityState.Modified; db.Bids.Add(new Bid { AccountId = _loginViewModel.Account.Id, BidAmount = vm.BidAmount, ProductId = product.Id }); db.SaveChanges(); } }
public bool UpdateUser(User newUser) { CoreValidator.ThrowIfNull(newUser, nameof(newUser)); CoreValidator.ThrowIfNull(newUser, nameof(newUser)); CoreValidator.ThrowIfNullOrEmpty(newUser.Username, nameof(newUser.Username)); CoreValidator.ThrowIfNullOrEmpty(newUser.Password, nameof(newUser.Password)); CoreValidator.ThrowIfNullOrEmpty(newUser.Name, nameof(newUser.Name)); CoreValidator.ThrowIfNullOrEmpty(newUser.Address, nameof(newUser.Address)); CoreValidator.ThrowIfNullOrEmpty(newUser.Email, nameof(newUser.Email)); CoreValidator.ThrowIfNullOrEmpty(newUser.Phone, nameof(newUser.Phone)); CoreValidator.SpecialThrowForCoinsIfValueIsNegativeOnly(newUser.Coins, nameof(newUser.Coins)); HashingSHA256.ValidateUserPassword(newUser.Password); if (newUser.DateOfBirth > DateTime.Now.AddYears(-18)) { throw new ArgumentException($"Date of birth is not valid, the customer must be adult."); } if (!ZipController.Instance().IsZipExisting(newUser.ZipId ?? 0)) { throw new ArgumentException($"Zip id doesn't exist in the system."); } using (var db = new AuctionContext()) { var dbUser = GetUserById(newUser.Id); db.Users.Attach(dbUser); dbUser.Address = newUser.Address; dbUser.Coins = newUser.Coins; dbUser.DateOfBirth = newUser.DateOfBirth; dbUser.Email = newUser.Email; dbUser.Gender = newUser.Gender; dbUser.Name = newUser.Name; if (newUser.Password != dbUser.Password) { dbUser.Password = HashingSHA256.ComputeHash(newUser.Password); } else { dbUser.Password = newUser.Password; } dbUser.Phone = newUser.Phone; dbUser.Username = newUser.Username; dbUser.ZipId = newUser.ZipId; db.Entry(dbUser).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(true); } }
public bool BidExpired(int productId) { CoreValidator.ThrowIfNegativeOrZero(productId, nameof(productId)); using (var db = new AuctionContext()) { using (var transaction = db.Database.BeginTransaction()) { try { var product = ProductController.Instance().GetProductById(productId); db.Products.Attach(product); if (!(DateTime.Now >= product.EndDate)) { throw new ArgumentException($"The product date for finish is not yet reached: {product.EndDate}"); } var bids = db.Bids.Where(b => b.ProductId == productId); if (bids.Count() == 0) { product.IsAvailable = false; db.Entry(product).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); transaction.Commit(); } else { var bid = bids.OrderByDescending(b => b.Id).FirstOrDefault(); db.Bids.Attach(bid); bid.IsWon = true; db.Entry(bid).State = System.Data.Entity.EntityState.Modified; product.IsAvailable = false; db.Entry(product).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); transaction.Commit(); } return(true); } catch (Exception) { transaction.Rollback(); throw; } } } }
public ActionResult Edit([Bind(Include = "Id,Name,EmailAddress,MobailNumber,TextDescription")] Contact contact) { if (ModelState.IsValid) { db.Entry(contact).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(contact)); }
public ActionResult Edit(User user) { if (ModelState.IsValid) { db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public ActionResult EditItem([Bind(Include = "ItemID,Name,Description,SellerID")] Item item) { if (ModelState.IsValid) { db.Entry(item).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(item)); }
public ActionResult Edit([Bind(Include = "CateparentID,CateparentName")] Cateparent cateparent) { if (ModelState.IsValid) { db.Entry(cateparent).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(cateparent)); }
public ActionResult Edit([Bind(Include = "Id,AuctionId,Timestamp,Username,Amount")] Bid bid) { if (ModelState.IsValid) { db.Entry(bid).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(bid)); }
public ActionResult Edit([Bind(Include = "Id,Name,EmailAddress,MobailNumber,Address")] PersonalInformation personalInformation) { if (ModelState.IsValid) { db.Entry(personalInformation).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(personalInformation)); }
public ActionResult Edit(Listing listing) { if (ModelState.IsValid) { db.Entry(listing).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.UserID = new SelectList(db.Users, "UserID", "Username", listing.UserID); return(View(listing)); }
public ActionResult Edit([Bind(Include = "CateID,CateName,CateparentID")] Cate cate) { if (ModelState.IsValid) { db.Entry(cate).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CateparentID = new SelectList(db.Cateparents, "CateparentID", "CateparentName", cate.CateparentID); return(View(cate)); }
public ActionResult Edit([Bind(Include = "ID,NAME,DECRIPTION,SELLER")] ITEM iTEM) { if (ModelState.IsValid) { db.Entry(iTEM).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.SELLER = new SelectList(db.SELLERs, "ID", "NAME", iTEM.SELLER); return(View(iTEM)); }
public ActionResult Edit([Bind(Include = "ID,Name,Description,Seller")] Item item) { if (ModelState.IsValid) { db.Entry(item).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Seller = new SelectList(db.Sellers, "Name", "Name", item.Seller); return(View(item)); }
public ActionResult Edit([Bind(Include = "ID,BuyerID,ItemID,Timestamp,Price")] Bid bid) { if (ModelState.IsValid) { db.Entry(bid).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.BuyerID = new SelectList(db.Buyers, "ID", "Name", bid.BuyerID); ViewBag.ItemID = new SelectList(db.Items, "ID", "Name", bid.ItemID); return(View(bid)); }
public JsonResult AcceptProduct(int id) { try { Product product = db.Products.Where(x => x.ProductID == id).FirstOrDefault(); if (product == null) { Response.StatusCode = (int)HttpStatusCode.NotFound; return(Json(new { Result = "Error" })); } //Change from database product.ProductStatus = 1; db.Entry(product).State = EntityState.Modified; db.SaveChanges(); return(Json(new { Result = "OK" })); } catch (Exception ex) { return(Json(new { Result = "ERROR", Message = ex.Message })); } }
public ActionResult Edit([Bind(Include = "ID,ITEM,BUYER,PRICE,TIME")] BID bID) { if (ModelState.IsValid) { db.Entry(bID).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.BUYER = new SelectList(db.BUYERs, "ID", "NAME", bID.BUYER); ViewBag.ITEM = new SelectList(db.ITEMs, "ID", "NAME", bID.ITEM); return(View(bID)); }
public ActionResult Edit([Bind(Include = "ITEMID,ITEMNAME,ITEMDESC,SELLERID")] Item item) { if (ModelState.IsValid) { db.Entry(item).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ITEMID = new SelectList(db.Bids, "ITEMID", "ITEMID", item.ItemID); ViewBag.SELLERID = new SelectList(db.Sellers, "SELLERID", "SELLERNAME", item.SellerID); return(View(item)); }
public async Task <ActionResult> Edit([Bind(Include = "ItemID,CategoryID,Name,Price,Description,ItemImage")] Item item) { if (ModelState.IsValid) { db.Entry(item).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "Name", item.CategoryID); return(View(item)); }
public string AddCookie(int userId) { CoreValidator.ThrowIfNegativeOrZero(userId, nameof(userId)); using (var db = new AuctionContext()) { var dbUser = GetUserById(userId); db.Users.Attach(dbUser); string guid = Guid.NewGuid().ToString(); dbUser.RememberToken = guid; db.Entry(dbUser).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(guid); } }
public bool DeletePayment(int paymentId) { CoreValidator.ThrowIfNegativeOrZero(paymentId, nameof(paymentId)); using (var db = new AuctionContext()) { var paymentNew = GetPayment(paymentId); CoreValidator.ThrowIfNull(paymentNew, nameof(paymentNew)); db.Payments.Attach(paymentNew); db.Payments.Remove(paymentNew); db.Entry(paymentNew).State = EntityState.Deleted; db.SaveChanges(); return(true); } }
public ActionResult Edit(Auction auction) { try { // TODO: Add update logic here if (ModelState.IsValid) { db.Entry(auction).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(auction)); } catch { return(View()); } }
public bool DeleteProduct(Product product) { CoreValidator.ThrowIfNegativeOrZero(product.Id, nameof(product.Id)); using (var db = new AuctionContext()) { var productNew = GetProductById(product.Id); CoreValidator.ThrowIfNull(productNew, nameof(productNew)); db.Products.Attach(productNew); db.Products.Remove(productNew); db.Entry(productNew).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); return(true); } }
public bool UpdateProduct(Product product) { CoreValidator.ThrowIfNull(product, nameof(product)); CoreValidator.ThrowIfNullOrEmpty(product.Name, nameof(product.Name)); CoreValidator.ThrowIfNegativeOrZero(product.Price, nameof(product.Price)); CoreValidator.ThrowIfNegativeOrZero(product.Id, nameof(product.Id)); CoreValidator.ThrowIfNullOrEmpty(product.Description, nameof(product.Description)); CoreValidator.ThrowIfDateIsNotCorrect(product.StartDate.ToString(), nameof(product.StartDate)); CoreValidator.ThrowIfDateIsNotCorrect(product.EndDate.ToString(), nameof(product.EndDate)); DateTime date = product.StartDate; if (date > product.EndDate) { throw new ArgumentException("Start date cannot be bigger than the end date"); } DateTime dateEnd = product.EndDate; if (dateEnd < product.StartDate) { throw new ArgumentException("End date cannot be lower than the start date"); } try { using (var db = new AuctionContext()) { db.Products.Attach(product); db.Entry(product).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(true); } } catch (DbUpdateConcurrencyException) { // throw new DbUpdateConcurrencyException("Someone has already modified this product, please refresh the page."); return(false); } }