public virtual void Delete(TEntity entityToDelete)
 {
     if (context.Entry(entityToDelete).State == EntityState.Detached)
     {
         dbSet.Attach(entityToDelete);
     }
     dbSet.Remove(entityToDelete);
 }
Beispiel #2
0
 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;
     }
 }
Beispiel #4
0
 public void UpdateCategory(Category category)
 {
     try
     {
         dbSet.Attach(category);
         Database.Entry(category).State = EntityState.Modified;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #5
0
        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());
        }
Beispiel #6
0
        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();
            }
        }
Beispiel #9
0
        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;
             }
         }
     }
 }
Beispiel #11
0
 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));
 }
Beispiel #13
0
 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));
 }
Beispiel #15
0
 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));
 }
Beispiel #16
0
 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));
 }
Beispiel #17
0
 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));
 }
Beispiel #18
0
 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));
 }
Beispiel #20
0
 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));
 }
Beispiel #21
0
 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));
 }
Beispiel #22
0
 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));
 }
Beispiel #24
0
 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));
        }
Beispiel #26
0
        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);
            }
        }
Beispiel #27
0
        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);
            }
        }
Beispiel #28
0
        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());
            }
        }
Beispiel #29
0
        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);
            }
        }
Beispiel #30
0
        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);
            }
        }