Example #1
0
        public async Task <CategoryModel> Edit(int id, CategoryModel categoryModel)
        {
            try
            {
                _context.Category.Attach(categoryModel);
                _context.Entry(categoryModel).Property(x => x.Name).IsModified = true;
                if (categoryModel.ImageUrl != null)
                {
                    _context.Entry(categoryModel).Property(x => x.ImageUrl).IsModified = true;
                }

                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                //log ex
                if (!CategoryModelExists(categoryModel.ID))
                {
                    return(null);
                }
            }


            return(categoryModel);
        }
Example #2
0
        public async Task <ProductModel> Edit(int id, ProductModel productModel)
        {
            _context.Entry(productModel).State = EntityState.Modified;

            if (productModel.ImageUrl == null)
            {
                _context.Entry(productModel).Property(x => x.ImageUrl).IsModified = false;
            }

            await _context.SaveChangesAsync();

            return(productModel);
        }