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());
        }
예제 #2
0
        public async Task <ActionResult <Product> > Create(Product item)
        {
            _context.Products.Add(item);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetProduct), new { id = item.Id }, item));
        }
        public async virtual Task <T> Add(T entity)
        {
            var ent = _context.Add(entity).Entity;
            await _context.SaveChangesAsync();

            return(ent);
        }
예제 #4
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());
        }
예제 #5
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());
        }
        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()));
        }
예제 #7
0
        public async Task <Customer> CreateAsync(Customer entity)
        {
            var res = await context._Customer.AddAsync(entity);

            await context.SaveChangesAsync();

            return(res.Entity);
        }
예제 #8
0
        public async Task <Category> CreateAsync(Category entity)
        {
            var res = await context.Categories.AddAsync(entity);

            await context.SaveChangesAsync();

            return(res.Entity);
        }
예제 #9
0
        public async Task <Product> CreateAsync(Product entity)
        {
            var res = await context.products.AddAsync(entity);

            await context.SaveChangesAsync();

            return(res.Entity);
        }
예제 #10
0
        public async Task <T> CreateAsync(T model)
        {
            var result = await _dbSet.AddAsync(model);

            await _dbContext.SaveChangesAsync();

            return(result.Entity);
        }
예제 #11
0
        public void Delete(int id)
        {
            var item = db.Stores.FirstOrDefault(d => d.ID == id);

            db.Stores.Remove(item);
            db.SaveChangesAsync();
        }
예제 #12
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 bool DeleteItem(int id)
        {
            var item = db.Items.FirstOrDefault(d => d.ID == id);

            if (item != null)
            {
                db.Items.Remove(item);
                db.SaveChangesAsync();
                return(true);
            }
            return(false);
        }
        public async Task <object> updateUserData(UserViewModel model)
        {
            var user = _context.Users.Where(u => u.Email == model.email).FirstOrDefault();

            //context.Entry(appuser).State = EntityState.Modified;
            user.Email     = model.email;
            user.Firstname = model.Firstname;
            user.Lastname  = model.Lastname;
            user.UserName  = model.Firstname + "_" + model.Lastname;
            user.Gender    = model.Gender;

            await _context.SaveChangesAsync();

            try
            {
                var result = await _context.SaveChangesAsync();

                return(Ok(result));
            }
            catch (Exception e)
            {
                return(e);
            }
        }
예제 #15
0
        protected override async Task LoadShoppingTestDataAsync()
        {
            await ShoppingDbContext.Customers.AddRangeAsync(
                new Core.Domains.Customer {
                Id = 2, ContactName = "Ralph R. Rao"
            },
                new Core.Domains.Customer {
                Id = 3, ContactName = "Edward M. Clay"
            },
                new Core.Domains.Customer {
                Id = 4, ContactName = "Wendell S. Graney"
            });

            await ShoppingDbContext.SaveChangesAsync();
        }
예제 #16
0
        public async Task Should_Throws_DeleteFailure_Exception_With_Valid_Id_And_Exists_Some_Orders()
        {
            await ShoppingDbContext.Orders.AddAsync(new Order
            {
                Id = 1
            });

            await ShoppingDbContext.SaveChangesAsync();

            var validId = 1;
            var command = new DeleteCustomerCommand {
                Id = validId
            };

            await Should.ThrowAsync <DeleteFailureException>(() => _sut.Handle(command, default));
        }
예제 #17
0
 /// <summary>
 /// 新增
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 public async Task <bool> AddEntityAsync(Category entity)
 {
     _context.Attach(entity);
     _context.Category.Add(entity);
     return(await _context.SaveChangesAsync() > 0);
 }
예제 #18
0
 /// <summary>
 /// 新增
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 public async Task <bool> AddEntityAsync(Customer entity)
 {
     _context.Attach(entity);
     _context.Customer.Add(entity);
     return(await _context.SaveChangesAsync() > 0);
 }
예제 #19
0
 /// <summary>
 /// 新增
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 public async Task <bool> AddEntityAsync(Product entity)
 {
     _context.Product.Attach(entity);
     _context.Product.Add(entity);
     return(await _context.SaveChangesAsync() > 0);
 }
예제 #20
0
 /// <summary>
 /// 新增
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 public async Task <bool> AddEntityAsync(Orders entity)
 {
     _context.Orders.Attach(entity);
     _context.Orders.Add(entity);
     return(await _context.SaveChangesAsync() > 0);
 }