public async Task <IActionResult> PutProduct([FromRoute] int id, [FromBody] Product product)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != product.PId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutCategory([FromRoute] int id, [FromBody] Category category)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            category.CId = id;

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

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

            return(NoContent());
        }
Example #3
0
        public async Task <ActionResult> PostProducts(Products products)
        {
            dbContext.Products.Add(products);
            await dbContext.SaveChangesAsync();

            return(CreatedAtAction("GetProducts", new { id = products.ProductId }, products));
        }
Example #4
0
        public async Task <IActionResult> AddDepartment(TblDepartment department)
        {
            await _practiceContext.TblDepartments.AddAsync(department);

            await _practiceContext.SaveChangesAsync();

            return(Ok(department));
        }
Example #5
0
        public async Task <IActionResult> Create([Bind("ProductId,ProductName,Category,Color,UnitPrice,AvailableQuantity")] Products products)
        {
            if (ModelState.IsValid)
            {
                _context.Add(products);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(products));
        }
Example #6
0
        public async Task <ICommandBase> CreateOrder(Order order)
        {
            var hasOrderName = practiceContext.Order.Any(c => c.Name.ToLower().Equals(order.Name.ToLower()));

            if (hasOrderName)
            {
                return(new CommandResult(false, $"Order's name {order.Name} has already exists"));
            }

            practiceContext.Add(order);
            await practiceContext.SaveChangesAsync();

            return(new CommandResult());
        }
Example #7
0
        public async Task Create(PracticeEntity model)
        {
            var userId = _httpContext.User.Identity.GetUserId();

            _context.Practice.Add(model);
            await _context.SaveChangesAsync(userId);
        }
Example #8
0
        public async Task <ICommandBase> CreateSupplier(Supplier supplier)
        {
            var hasSupplierName = practiceContext.Suppliers.Any(x => x.Name.ToLower().Equals(supplier.Name.ToLower()));

            if (hasSupplierName)
            {
                return(new CommandResult(false, $"Supplier's name '{supplier.Name}' has already exists"));
            }



            practiceContext.Suppliers.Add(supplier);
            await practiceContext.SaveChangesAsync();



            return(new CommandResult());
        }
Example #9
0
        public async Task <ICommandBase> CreateItem(Item item)
        {
            var hasItemName = practiceContext.Items.Any(c => c.Name.ToLower().Equals(item.Name.ToLower()));

            if (hasItemName)
            {
                return(new CommandResult(false, $"Item {item.Name} has already exists"));
            }

            var hasBarcode = practiceContext.Items.Any(c => c.Barcode.ToLower().Equals(item.Barcode.ToLower()));

            if (hasBarcode)
            {
                return(new CommandResult(false, $"Item's Barcode {item.Barcode} has already exists"));
            }

            practiceContext.Items.Add(item);
            await practiceContext.SaveChangesAsync();

            return(new CommandResult());
        }
        public async Task UpdateOrdertem(IEnumerable <int> itemId, int orderId)
        {
            var order = practiceContext.Order
                        .Include(x => x.OrderItems)
                        .Single(x => x.Id == orderId);

            var orderItem = practiceContext.Items
                            .Where(x => itemId.Contains(x.Id))
                            .Select(x => new OrderItem()
            {
                OrderId = order.Id,
                Order   = order,
                ItemId  = x.Id,
                Item    = x
            }).ToList();

            order.OrderItems = orderItem;

            practiceContext.Order.Update(order);
            await practiceContext.SaveChangesAsync();
        }