public async Task <IActionResult> PutCustomer(int id, Customer customer)
        {
            if (id != customer.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
예제 #2
0
        public async Task <IActionResult> PutShoppingDetails([FromRoute] int id, [FromBody] ShoppingDetails shoppingDetails)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != shoppingDetails.ShopId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
예제 #3
0
        public async Task <IActionResult> PutProduct(int id, Product product)
        {
            if (id != product.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
예제 #4
0
        public async Task <T> AddAsync(T entity)
        {
            await context.Set <T>().AddAsync(entity).ConfigureAwait(false);

            await context.SaveChangesAsync().ConfigureAwait(false);

            return(entity);
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Price")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
예제 #6
0
        public async Task AddViewCount(int productId)
        {
            var product = await _context.Products.FindAsync(productId);

            if (product == null)
            {
                throw new ShoppingException($"Can not find product: ${productId}");
            }
            product.ViewCount += 1;
            await _context.SaveChangesAsync();
        }
        private static async Task SeedProducts(ShoppingDBContext context)
        {
            if (!context.Products.Any())
            {
                context.AddRange(ProductSeed.PopulateProductList());
                await context.SaveChangesAsync().ConfigureAwait(false);

                {
                }
            }
        }
예제 #8
0
        public async Task <int> AddImage(int productId, ProductImageCreateRequest request)
        {
            var productImage = new ProductImage()
            {
                Caption     = request.Caption,
                DateCreated = DateTime.Now,
                IsDefault   = request.IsDefault,
                ProductId   = productId,
                SortOrder   = request.SortOrder
            };

            if (request.ImageFile != null)
            {
                productImage.ImagePath = await this.SaveFile(request.ImageFile);

                productImage.FileSize = request.ImageFile.Length;
            }
            _context.ProductImages.Add(productImage);
            await _context.SaveChangesAsync();

            return(productImage.Id);
        }
예제 #9
0
        public async Task <IActionResult> PutSales(int id, Saless saless)
        {
            if (id != saless.Id)
            {
                return(BadRequest());
            }

            var sales = new Sales();

            List <Customer> cList = await _context.Customer.ToListAsync();

            List <Store> stList = await _context.Store.ToListAsync();

            List <Product> pList = await _context.Product.ToListAsync();

            sales.Id       = id;
            sales.DateSold = Convert.ToDateTime(saless.DateSold);

            foreach (var customer in cList)
            {
                if (saless.CustomerName == customer.Name)
                {
                    sales.CustomerId = customer.Id;
                }
            }

            foreach (var store in stList)
            {
                if (saless.StoreName == store.Name)
                {
                    sales.StoreId = store.Id;
                }
            }

            foreach (var product in pList)
            {
                if (saless.ProductName == product.Name)
                {
                    sales.ProductId = product.Id;
                }
            }


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

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

            return(NoContent());
        }