Ejemplo n.º 1
0
        public ActionResult Edit(HttpPostedFileBase file, ProductViewModel productViewModel)
        {
            var product = db.Products.Find(productViewModel.Id);

            if (file != null)
            {
                string fileName  = Path.GetFileNameWithoutExtension(file.FileName);
                string extension = Path.GetExtension(file.FileName);
                fileName = fileName + extension;

                file.SaveAs(Path.Combine(Server.MapPath("~/AppFile/Images/"), fileName));

                Mapper.Map(productViewModel, product);
                product.UrlImage        = "http://localhost:55666/AppFile/Images/" + fileName;
                db.Entry(product).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            else
            {
                Mapper.Map(productViewModel, product);
                product.UrlImage        = Session["img"].ToString();
                db.Entry(product).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
        }
Ejemplo n.º 2
0
        public async Task <bool> UpdateProductAsync(ProductServiceModel serviceModel)
        {
            var oldProduct = await AllProduct.FirstOrDefaultAsync(o => o.Id == serviceModel.Product.Id);

            var productEntry = _context.Entry(oldProduct);

            serviceModel.Product.LastUpdateByUserId = serviceModel.User.Id;
            serviceModel.Product.LastUpdateDate     = DateTime.Now;

            productEntry.CurrentValues.SetValues(serviceModel.Product);

            _context.Entry(oldProduct).Property(o => o.CreateByUserId).IsModified = false;
            _context.Entry(oldProduct).Property(o => o.CreateDate).IsModified     = false;

            foreach (var newDetail in serviceModel.Product.Details)
            {
                var oldDetail = oldProduct.Details.FirstOrDefault(o => o.ForCurrentRequestLanguage());
                if (oldDetail.Language == newDetail.Language)
                {
                    newDetail.Id = oldDetail.Id;
                    _context.Entry(oldDetail).CurrentValues.SetValues(newDetail);
                }
            }

            _context.TryUpdateManyToMany(oldProduct.EntityFiles, serviceModel.Product.EntityFiles, o => o.FileEntityId);
            _context.TryUpdateManyToMany(oldProduct.EntityTaxonomies, serviceModel.Product.EntityTaxonomies, o => o.TaxonomyId);

            var updateResultCount = await _context.SaveChangesAsync();

            return(updateResultCount > 0);
        }
Ejemplo n.º 3
0
        public ActionResult GetUser(UserViewModel userViewModel)
        {
            var user = db.Users.Where(x => x.Id == userViewModel.Id).FirstOrDefault();

            try
            {
                if (user != null)
                {
                    if (userViewModel.Gender.Equals("male"))
                    {
                        user.Gender = true;
                    }
                    else
                    {
                        user.Gender = false;
                    }
                    user.FirstName       = userViewModel.FirstName;
                    user.LastName        = userViewModel.LastName;
                    user.PhoneNumber     = userViewModel.PhoneNumber;
                    user.Address         = userViewModel.Address;
                    user.Email           = userViewModel.Email;
                    db.Entry(user).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
            catch (Exception)
            {
                throw;
            }
            ViewBag.Notify = "Cập nhật thông tin thành công.";
            return(View(userViewModel));
        }
Ejemplo n.º 4
0
 public virtual void Update(T entity, bool isSave = true)
 {
     DbContext.Entry(entity).State = EntityState.Modified;
     if (isSave)
     {
         DbContext.SaveChanges();
     }
 }
        public async Task <IActionResult> PutCustomer(Guid id, Customer customer)
        {
            if (id != customer.CustomerID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> PutOrderCancel(Guid id, OrderCancel orderCancel)
        {
            if (id != orderCancel.OrderCancelID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 7
0
        public async Task UpdateAsync(T entity)
        {
            ArgumentGuard.NotNull(entity, nameof(entity));

            _dbContext.Entry <T>(entity).State = EntityState.Modified;
            await _dbContext.SaveChangesAsync();
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> PutCartProduct(Guid id, CartProduct cartProduct)
        {
            if (id != cartProduct.CartProductID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> PutAdmin(Guid id, Admin admin)
        {
            if (id != admin.AdminID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 10
0
 public void LoadProducts(Category category)
 {
     _db.Entry(category)
     .Collection(c => c.Products)
     .Query()
     .Where(c => c.IsActive)
     .Load();
 }
Ejemplo n.º 11
0
        public ActionResult SaveData(HttpPostedFileBase file, ProductViewModel productViewModel)
        {
            if (file != null)
            {
                var    product   = Mapper.Map <Product>(productViewModel);
                string fileName  = Path.GetFileNameWithoutExtension(file.FileName);
                string extension = Path.GetExtension(file.FileName);
                fileName = fileName + extension;

                file.SaveAs(Path.Combine(Server.MapPath("~/AppFile/Images/"), fileName));
                product.UrlImage        = "http://localhost:55666/AppFile/Images/" + fileName;
                db.Entry(product).State = EntityState.Added;
                db.SaveChanges();

                return(RedirectToAction("GetProductPagsing"));
            }
            return(View());
        }
Ejemplo n.º 12
0
 public ActionResult Edit(User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index", "SetRole"));
     }
     return(View(user));
 }
Ejemplo n.º 13
0
        public int UpdateProduct(Product product)
        {
            int totalChanges = 0;

            using (var context = new EcommerceDbContext())
            {
                context.Products.Attach(product);

                context.Entry(product).State = EntityState.Modified;

                totalChanges = context.SaveChanges();
            }

            return(totalChanges);
        }
Ejemplo n.º 14
0
        public ActionResult Edit(CategoryViewModel categoryViewModel)
        {
            if (ModelState.IsValid)
            {
                Category category = db.Categories.Find(categoryViewModel.Id);
                if (category == null)
                {
                    return(HttpNotFound());
                }

                Mapper.Map(categoryViewModel, category);
                db.Entry(category).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(categoryViewModel));
        }
Ejemplo n.º 15
0
        public ActionResult EditRole(UserViewModel userViewModel)
        {
            if (userViewModel == null)
            {
                return(HttpNotFound());
            }
            var user = db.Users.FirstOrDefault(m => m.Id == userViewModel.Id);

            if (user == null)
            {
                return(HttpNotFound());
            }
            user.RoleId          = userViewModel.RoleId;
            db.Entry(user).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 16
0
        public ActionResult Edit(ManufactureViewModel manufactureViewModel)
        {
            if (ModelState.IsValid)
            {
                Manufacturer manufacturer = db.Manufacturers.Find(manufactureViewModel.Id);
                if (manufacturer == null)
                {
                    return(HttpNotFound());
                }

                Mapper.Map(manufactureViewModel, manufacturer);
                db.Entry(manufacturer).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(manufactureViewModel));
        }
Ejemplo n.º 17
0
        public ActionResult Edit(SupplierViewModel supplierViewModel)
        {
            //check box space
            if (ModelState.IsValid)
            {
                Supplier supplier = db.Suppliers.Find(supplierViewModel.Id);
                if (supplier == null)
                {
                    return(HttpNotFound());
                }

                Mapper.Map(supplierViewModel, supplier);

                db.Entry(supplier).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(supplierViewModel));
        }
Ejemplo n.º 18
0
 public bool Update(Customer customer)
 {
     _db.Entry(customer).State = EntityState.Modified;
     return(_db.SaveChanges() > 0);
 }
Ejemplo n.º 19
0
 public bool Update(Product product)
 {
     _db.Entry(product).State = EntityState.Modified;
     return(_db.SaveChanges() > 0);
 }
Ejemplo n.º 20
0
 public virtual void Update(T entity)
 {
     dbSet.Attach(entity);
     dataContext.Entry(entity).State = EntityState.Modified;
 }
        public bool Update(Category category)
        {
            db.Entry(category).State = EntityState.Modified;

            return(db.SaveChanges() > 0);
        }