コード例 #1
0
        public async Task <IActionResult> PutProduct([FromRoute] int id, [FromBody] Product product)
        {
            if (id != product.Id)
            {
                return(BadRequest());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                var pdt = _context.Products.Find(id);
                if (pdt == null)
                {
                    return(NotFound());
                }

                throw;
            }


            return(NoContent());
        }
コード例 #2
0
ファイル: ConfigurationService.cs プロジェクト: muswilam/eCom
 //edit config value
 public bool EditConfig(Config config)
 {
     using (var context = new eComContext())
     {
         context.Entry(config).State = EntityState.Modified;
         return(context.SaveChanges() > 0);
     }
 }
コード例 #3
0
 //edit category
 public void UpdateCategory(Category category)
 {
     using (var context = new eComContext())
     {
         context.Entry(category).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
コード例 #4
0
ファイル: ProductService.cs プロジェクト: muswilam/eCom
 //edit product
 public void UpdateProduct(Product product)
 {
     using (var context = new eComContext())
     {
         context.Entry(product).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
コード例 #5
0
ファイル: ProductService.cs プロジェクト: muswilam/eCom
        //add product
        public void SaveProduct(Product product)
        {
            using (var context = new eComContext())
            {
                context.Entry(product.Category).State = EntityState.Unchanged; //prevent adding category again with different id

                context.Products.Add(product);
                context.SaveChanges();
            }
        }
コード例 #6
0
ファイル: OrderService.cs プロジェクト: muswilam/eCom
        //edit order status (by admin)
        public bool UpdateOrderStatus(string status, int id)
        {
            using (var context = new eComContext())
            {
                var order = context.Orders.Where(o => o.Id == id).FirstOrDefault();

                order.Status = status;

                context.Entry(order).State = EntityState.Modified;
                return(context.SaveChanges() > 0);
            }
        }
コード例 #7
0
ファイル: ConfigurationService.cs プロジェクト: muswilam/eCom
 //update main picture in home page (by admin)
 public bool UpdateMainPicture(string key, string imageUrl)
 {
     using (var context = new eComContext())
     {
         var existConfig = context.Configurations.Where(c => c.Key == key).FirstOrDefault();
         if (existConfig != null)
         {
             existConfig.Value = imageUrl;
             context.Entry(existConfig).State = EntityState.Modified;
             return(context.SaveChanges() > 0);
         }
         return(false);
     }
 }