public ActionResult EditSubmit(int?id, string name, decimal price, string about, List <HttpPostedFileBase> imgFiles)
        {
            var findProduct = db.products.Find(id);

            findProduct.Name  = name;
            findProduct.Price = price;
            findProduct.About = about;
            if (imgFiles[0] != null)
            {
                string SaveLocation = "";

                foreach (var file in imgFiles)
                {
                    string fileName = Path.GetFileName(file.FileName);
                    SaveLocation = Server.MapPath("~/Template/img/newImg/") + "\\" + fileName;
                    try
                    {
                        var newImgPath = new imageProduct();
                        newImgPath.ProductId   = findProduct.Id;
                        newImgPath.imgPath     = fileName;
                        newImgPath.CreatedDate = DateTime.Now;
                        db.imageProducts.Add(newImgPath);
                        file.SaveAs(SaveLocation);
                    }
                    catch (Exception ex)
                    {
                        Response.Write("Error: " + ex.Message);
                    }
                }
            }
            db.Entry(findProduct).State = EntityState.Modified;
            db.SaveChanges();

            return(RedirectToAction("newAddProduct", "Admin"));
        }
        // starlevel
        public ActionResult increseStarLevel(int id, int rate)
        {
            var find= db.rating.Where(w => w.DeletedDate == null && w.Product.Id == id).FirstOrDefault();

            if (find!=null)
            {
                find.starCount += 1;
                find.totalStarLevel += rate;
                find.currentStar = rate;
                int starLevel = calculatorRating.calStar(find.starCount, find.totalStarLevel);
                find.Product.starLevel = starLevel;
                db.Entry(find).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction($"itemPage/{id}");
            }
            else
            {
                Rating newRating = new Rating();
                newRating.ProductId = id;
                newRating.starCount += 1;
                newRating.currentStar = rate;
                newRating.totalStarLevel += rate;
                newRating.CreatedDate = DateTime.Now;
                db.rating.Add(newRating);
                db.SaveChanges();
            }
            return RedirectToAction($"itemPage/{id}");
        }
示例#3
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="id"></param>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task <bool> PutEntityAsync(string id, Customer entity)
        {
            if (!IsExists(id))
            {
                return(false);
            }

            _context.Entry(entity).State = EntityState.Modified;
            return(await _context.SaveChangesAsync() > 0);
        }
 public ActionResult Edit([Bind(Include = "Id,Name,About,Adress,imgPath,CreatedDate,CreatedId,ModifiedDate,ModifiedId,DeletedDate,DeletedId")] shoppingAdresses shoppingAdresses)
 {
     if (ModelState.IsValid)
     {
         db.Entry(shoppingAdresses).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(shoppingAdresses));
 }
示例#5
0
        public ActionResult deleteCategory(int?id)
        {
            var checkSession = Session[SessionKey.Admin];
            var admin        = db.Manager.Where(w => w.Email.ToString() == checkSession.ToString()).FirstOrDefault();
            var findcategory = db.categories.Where(w => w.DeletedDate == null && w.Id == id).FirstOrDefault();

            findcategory.DeletedDate     = DateTime.Now;
            findcategory.DeletedId       = admin.Id;
            db.Entry(findcategory).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            return(PartialView("~/Areas/Admin/Views/CategoryColorCompany/refleshPage.cshtml"));
        }
示例#6
0
        public ActionResult deleteItemFromWaitList(int id)
        {
            var item          = db.products.Where(w => w.DeletedDate == null && w.Id == id).FirstOrDefault();
            var activeSession = Session[SessionKey.Admin];
            var findAdmin     = db.Manager.Where(w => w.DeletedDate == null && w.Email == activeSession.ToString()).FirstOrDefault();

            item.DeletedDate     = DateTime.UtcNow;
            item.DeletedId       = findAdmin.Id;
            db.Entry(item).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();

            return(PartialView("~/Areas/AdGetOn/Views/Admin/newAddProductForEach.cshtml", db.products.OrderByDescending(o => o.Id).Where(w => w.DeletedDate == null && (w.isWaitListForAdmin == true && w.isConfirm == false)).ToList()));
        }
        public ActionResult lookAtMessage(int?id)
        {
            var currentMessage = db.ContactUs.Where(w => w.DeletedDate == null && w.Id == id).FirstOrDefault();

            if (currentMessage.isRead == false)
            {
                currentMessage.isRead          = true;
                db.Entry(currentMessage).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
            var allMessages = db.ContactUs.OrderByDescending(w => w.Id).Where(w => w.DeletedDate == null).ToList();

            return(Json(currentMessage, JsonRequestBehavior.AllowGet));
        }
示例#8
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="id"></param>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task <bool> PutEntityAsync(string id, Category entity)
        {
            if (!IsExists(id))
            {
                return(false);
            }

            _context.Attach(entity);
            var entity1 = _context.Entry(entity);

            entity1.Property(y => y.CateName).IsModified = true;
            entity1.Property(y => y.ParentId).IsModified = true;
            return(await _context.SaveChangesAsync() > 0);
        }
示例#9
0
        public ActionResult clickLike(int productId)
        {
            if (Session[SessionKey.User] != null)
            {
                int currentUserId = 0;
                var users         = db.user.Where(w => w.DeletedDate == null && w.isBlock == false).ToList();
                foreach (var item in users)
                {
                    if (item.Email.ToString() == Session[SessionKey.User].ToString())
                    {
                        currentUserId = item.Id;
                    }
                }
                var product   = db.products.Where(w => w.DeletedDate == null && w.isConfirm == true && w.Id == productId).FirstOrDefault();
                var checkUser = db.Likes.Where(w => w.DeletedDate == null && w.ProductId == productId && w.UserId == currentUserId).FirstOrDefault();
                if (checkUser != null)
                {
                    if (product.LikeCount > 0)
                    {
                        product.LikeCount         = product.LikeCount - 1;
                        checkUser.DeletedDate     = DateTime.Now;
                        db.Entry(checkUser).State = System.Data.Entity.EntityState.Modified;
                    }
                    else
                    {
                        product.LikeCount = 0;
                    }
                }
                else
                {
                    var newLike = new Like();
                    newLike.ProductId   = productId;
                    newLike.UserId      = currentUserId;
                    newLike.CreatedDate = DateTime.Now;
                    db.Likes.Add(newLike);
                    product.LikeCount = product.LikeCount + 1;
                }

                db.Entry(product).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                var count = product.LikeCount;
                return(Json(count, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json("notSession", JsonRequestBehavior.AllowGet));
            }
        }
示例#10
0
        public async Task <IActionResult> PutItemDetails([FromRoute] int id, [FromBody] ItemDetails itemDetails)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != itemDetails.Item_ID)
            {
                return(BadRequest());
            }

            _context.Entry(itemDetails).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ItemDetailsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#11
0
        public async Task <IActionResult> PutOrderDetails(int id, OrderDetails orderDetails)
        {
            if (id != orderDetails.ProductId)
            {
                return(BadRequest());
            }

            _context.Entry(orderDetails).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OrderDetailsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutCoupon(int id, Coupon coupon)
        {
            if (id != coupon.code)
            {
                return(BadRequest());
            }

            _context.Entry(coupon).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CouponExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutProducts(int id, Products products)
        {
            if (id != products.Id)
            {
                return(BadRequest());
            }

            _context.Entry(products).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(new JsonResult(_context.Products.ToList()));
        }
示例#14
0
        public void Update(TEntity changedEntity)
        {
            if (DbEntities.Local.All(e => e != changedEntity))
            {
                DbEntities.Attach(changedEntity);
            }

            DbContext.Entry(changedEntity).State = EntityState.Modified;
        }
示例#15
0
 public ActionResult Edit([Bind(Include = "Id,NameVN,Name,Image,Icon")] Category category)
 {
     if (ModelState.IsValid)
     {
         db.Entry(category).State = EntityState.Modified;
         db.SaveChanges();
         return(Json(new { success = true }));
     }
     return(View(category));
 }
 public ActionResult Edit(Category category)
 {
     if (ModelState.IsValid)
     {
         db.Entry(category).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(category));
 }
示例#17
0
 public ActionResult Edit([Bind(Include = "ID,Password,FullName,Email,Address,Tel,DateRegister,Activated")] Customer customer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customer).State = EntityState.Modified;
         db.SaveChanges();
         return(Json(new { success = true }));
     }
     return(View(customer));
 }
示例#18
0
 public ActionResult Edit([Bind(Include = "Id,Name,Logo,Email,Phone")] Supplier supplier)
 {
     if (ModelState.IsValid)
     {
         db.Entry(supplier).State = EntityState.Modified;
         db.SaveChanges();
         return(Json(new { success = true }));
     }
     return(View(supplier));
 }
 public ActionResult Edit(SubCategory subcategory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(subcategory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryId = new SelectList(db.Categorys, "CategoryId", "Name", subcategory.CategoryId);
     return(View(subcategory));
 }
示例#20
0
 public ActionResult Edit([Bind(Include = "Id,CustomerId,OrderDate,RequireDate,Receiver,Address,Description,Amount,view")] Order order)
 {
     if (ModelState.IsValid)
     {
         db.Entry(order).State = EntityState.Modified;
         db.SaveChanges();
         return(Json(new { success = true }));
     }
     ViewBag.CustomerId = new SelectList(db.Customers, "ID", "Password", order.CustomerId);
     return(View(order));
 }
示例#21
0
 public ActionResult Edit([Bind(Include = "Id,Name,UnitBrief,UnitPrice,Image,ImageLarge,ProductDate,Available,Description,CategoryId,SupplierId,Quantity,Discount,Special,Latest,Views")] Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", product.CategoryId);
     ViewBag.SupplierId = new SelectList(db.Suppliers, "Id", "Name", product.SupplierId);
     return(View(product));
 }
 public ActionResult Edit(Model model)
 {
     if (ModelState.IsValid)
     {
         db.Entry(model).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryId    = new SelectList(db.Categorys, "CategoryId", "Name", model.CategoryId);
     ViewBag.SubCategoryId = new SelectList(db.SubCategories, "SubCategoryId", "SubCategoryName", model.SubCategoryId);
     return(View(model));
 }
示例#23
0
        public async Task <IActionResult> Update(Guid id, Product item)
        {
            if (id != item.Id)
            {
                return(BadRequest());
            }

            _context.Entry(item).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }
 public ActionResult Edit(Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryId    = new SelectList(db.Categorys, "CategoryId", "Name", product.CategoryId);
     ViewBag.SubCategoryId = new SelectList(db.SubCategories, "SubCategoryId", "SubCategoryName", product.SubCategoryId);
     ViewBag.ModelId       = new SelectList(db.Models, "ModelId", "ModelName", product.ModelId);
     return(View(product));
 }
示例#25
0
        public ActionResult deleteWishList(int id)
        {
            var x        = Session[SessionKey.User];
            var findUser = db.user.Where(w => w.DeletedDate == null && w.isBlock == false && w.Email.ToString() == x.ToString()).FirstOrDefault();
            var find     = db.wishListProductAndUsers.Where(w => w.DeletedDate == null && w.Id == id).FirstOrDefault();

            find.DeletedDate     = DateTime.Now;
            db.Entry(find).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            var wishlist = db.wishListProductAndUsers.Where(w => w.DeletedDate == null && w.UserId == findUser.Id).ToList();

            return(PartialView("~/Views/Shared/_PartialViews/_wishListForeach.cshtml", wishlist));
        }
示例#26
0
        public async Task <ActionResult <IEnumerable <AdminOrdersViewModel> > > PutOrders(int id, Orders orders)
        {
            if (id != orders.Id)
            {
                // return BadRequest();
            }

            _context.Entry(orders).State = EntityState.Modified;

            try
            {
                _context.SaveChanges();
                if (orders.Status == 3)
                {
                    //products id in order

                    var list = _context.OrderDetails.Where(o => o.OrderId == orders.Id).ToList();
                    //products
                    var products = _context.Products.ToList();
                    foreach (var item in list)
                    {
                        var obj = products.Find(i => i.Id == item.ProductId);
                        obj.Quantity = obj.Quantity + item.Quantity;
                    }
                }
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OrdersExists(id))
                {
                    //  return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return(await GetOrders());
        }
 public void UpdateOrder(Order order)
 {
     shoppingDbContext.Entry(order).State = EntityState.Modified;
     shoppingDbContext.SaveChanges();
 }
 public void UpdateDb(Cart cart)
 {
     shoppingDbContext.Entry(cart).State = EntityState.Modified;
     shoppingDbContext.SaveChanges();
 }
示例#29
0
 public void Update(TEntity entity)
 {
     context.Entry(entity).State = EntityState.Modified;
 }
示例#30
0
 public void EditProduct(Product product)
 {
     shoppingDbContext.Entry(product).State = EntityState.Modified;
     shoppingDbContext.SaveChanges();
 }