public async Task <IActionResult> PostWarehouse(Warehouse.Models.Warehouse item)
        {
            _context.Warehouses.Add(item);
            await _context.SaveChangesAsync();

            return(StatusCode(201));
        }
Пример #2
0
        public async Task <IActionResult> PutInventory(int id, Inventory inventory)
        {
            if (id != inventory.ID)
            {
                return(BadRequest());
            }

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

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

            return(Ok(inventory));
        }
Пример #3
0
        public async Task <IActionResult> PutProduct(long 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(Ok());
        }
        public async Task <IActionResult> PostEmployee(Employee item)
        {
            _context.Employees.Add(item);
            await _context.SaveChangesAsync();

            return(StatusCode(201));
        }
Пример #5
0
        public async Task <IActionResult> PutBicycleRack(int id, BicycleRack bicycleRack)
        {
            if (id != bicycleRack.ID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Пример #6
0
        public async Task <IActionResult> PutWarehouseOrder(int id, int orderId, Order order)
        {
            if (orderId != order.ID || order.WarehouseID != id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Пример #7
0
        public async Task <IActionResult> PutCustomer(long 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(Ok());
        }
Пример #8
0
        public async Task <IActionResult> PostCity(City item)
        {
            _context.Cities.Add(item);
            await _context.SaveChangesAsync();

            return(StatusCode(201));
        }
Пример #9
0
        //Create new store
        public async Task <StoreModels> createStore(StoreModels store)
        {
            _db.StoreModels.Add(store);
            await _db.SaveChangesAsync();

            return(store);
        }
        public async Task <IActionResult> PostPosition(Position item)
        {
            _context.Positions.Add(item);
            await _context.SaveChangesAsync();

            return(StatusCode(201));
        }
Пример #11
0
        public async Task <IActionResult> PutWheelChain(int id, WheelChain wheelChain)
        {
            if (id != wheelChain.ID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Пример #12
0
        public async Task <IActionResult> PutUser(int id, User user)
        {
            if (id != user.ID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Пример #13
0
        public async Task <ReservationResultDto> ReserveAsync(ReserveDto model)
        {
            var productIds = model.Items
                             .Select(i => i.Id)
                             .ToList();

            var strategy = _context.Database.CreateExecutionStrategy();

            return(await strategy.ExecuteAsync(async() =>
            {
                await using var transaction = _context.Database.BeginTransaction();
                try
                {
                    var warehouseItems = await GetWarehouseItems(productIds);

                    var reserve = new Reserve
                    {
                        CreationDate = DateTime.Now
                    };

                    foreach (var item in model.Items)
                    {
                        var warehouseItem = warehouseItems
                                            .FirstOrDefault(i => i.ProductId == item.Id);

                        if (warehouseItem == null)
                        {
                            throw new ProductNotFoundException(item.Id);
                        }

                        if (warehouseItem.Balance < item.Quantity)
                        {
                            throw new InsufficientProductQuantityException(item.Id, warehouseItem.Balance);
                        }

                        reserve.ReserveItems.Add(new ReserveItem
                        {
                            ProductId = item.Id,
                            Quantity = item.Quantity
                        });
                    }

                    await _context.AddAsync(reserve);

                    IncreaseProductReservedQuantity(warehouseItems, reserve.ReserveItems);

                    await _context.SaveChangesAsync();
                    await transaction.CommitAsync();

                    return reserve.MapToReservationResultDto();
                }
                catch
                {
                    await transaction.RollbackAsync();
                    throw;
                }
            }));
        }
Пример #14
0
        public async Task <IActionResult> Add(Cargo cargo)
        {
            if (ModelState.IsValid)
            {
                Product product = _db.Products.Where(x => x.ID == cargo.Product.ID).FirstOrDefault();
                cargo.ProductId = product.ID;
                cargo.Product   = product;
                Order order = _db.Orders.Where(x => x.ID == cargo.OrderId).FirstOrDefault();
                cargo.OrderId = order.ID;
                cargo.Order   = order;

                Cargo existCargo = _db.Cargos.Where(x => x.Number == cargo.Number && x.Product.Name == cargo.Product.Name).FirstOrDefault();
                if (existCargo != null)
                {
                    int numPalletes = 0;
                    foreach (Cargo item in _db.Cargos.Where(x => x.OrderId == cargo.OrderId))
                    {
                        numPalletes += item.NumOfPalletes;
                    }

                    numPalletes += cargo.NumOfPalletes;
                    if (numPalletes > 22)
                    {
                        return(Content("Превышено максимальное количество паллет(22) для заказа " + cargo.OrderId));
                    }
                    else
                    {
                        existCargo.NumOfPalletes += cargo.NumOfPalletes;
                    }

                    _db.Cargos.Update(existCargo);
                    await _db.SaveChangesAsync();

                    return(RedirectToAction("Orders", "Warehouse"));
                }

                int palletes = 0;
                foreach (Cargo item in _db.Cargos.Where(x => x.OrderId == cargo.OrderId))
                {
                    palletes += item.NumOfPalletes;
                }
                palletes += cargo.NumOfPalletes;

                if (palletes > 22)
                {
                    return(Content("Превышено максимальное количество паллет(22) для заказа " + cargo.OrderId));
                }

                string newCargoNumber = UpdateCargoNumber(cargo.Number);
                cargo.Number = newCargoNumber;

                _db.Cargos.Add(cargo);
                await _db.SaveChangesAsync();
            }

            return(RedirectToAction("Orders", "Warehouse"));
        }
Пример #15
0
        public async Task <BuildingDetails> Insert(BuildingDetails details)
        {
            var building = _mapper.Map <BuildingDetails, Building>(details);

            await _context.Buildings.AddAsync(building);

            await _context.SaveChangesAsync();

            return(_mapper.Map <BuildingDetails>(building));
        }
        //Create new Computer
        public async Task <ComputerListModels> createNewComputer(FormCollection form)
        {
            computer.Name = form["Name"];;
            computer.Date = DateTime.Now;

            _db.ComputerListModels.Add(computer);
            await _db.SaveChangesAsync();

            return(computer);
        }
Пример #17
0
        public async Task <IActionResult> Create([Bind("ProductTypeId,TypeName,Description,Features")] ProductType productType)
        {
            if (ModelState.IsValid)
            {
                _context.Add(productType);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(productType));
        }
Пример #18
0
        public async Task <IActionResult> Create([Bind("wItemId,Name,Description,Manufacturer,Price,Quantity")] wItems wItems)
        {
            if (ModelState.IsValid)
            {
                _context.Add(wItems);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(wItems));
        }
Пример #19
0
        public async Task <IActionResult> Create(Item item)
        {
            if (ModelState.IsValid)
            {
                _context.Add(item);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(item));
        }
Пример #20
0
        public async Task <IActionResult> EkleveyaDuzenle([Bind("Id,Name,Code,TarihG,TarihK,Gumruk")] Warehouse warehouse)
        {
            if (ModelState.IsValid)
            {
                _context.Add(warehouse);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(warehouse));
        }
        public async Task <IActionResult> Create([Bind("CustomerId,CustomerName,CustomerAddress,TelNumber")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
Пример #22
0
        public async Task <IActionResult> Create(User user)
        {
            if (ModelState.IsValid)
            {
                user.Id = Guid.NewGuid().ToString();
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(user));
        }
        public async Task <IActionResult> Create([Bind("ProductId,ProductTypeId,ProductName,Storage,Packaging,ExpirationDate")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductTypeId"] = new SelectList(_context.ProductTypes, "ProductTypeId", "ProductTypeId", product.ProductTypeId);
            return(View(product));
        }
        public async Task <IActionResult> Create([Bind("StorageId,ReceiptDate,Volume,Cost,Employee,ProductId,DialerId")] Storage storage)
        {
            if (ModelState.IsValid)
            {
                _context.Add(storage);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DialerId"]  = new SelectList(_context.Dialers, "DialerId", "DialerId", storage.DialerId);
            ViewData["ProductId"] = new SelectList(_context.Products, "ProductId", "ProductId", storage.ProductId);
            return(View(storage));
        }
Пример #25
0
        public async Task <IActionResult> Create([Bind("OrderId,OrderDate,DispatchDate,Delivery,Volume,Cost,Employee,ProductId,CustomerId")] Order order)
        {
            if (ModelState.IsValid)
            {
                _context.Add(order);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerId"] = new SelectList(_context.Customers, "CustomerId", "CustomerId", order.CustomerId);
            ViewData["ProductId"]  = new SelectList(_context.Products, "ProductId", "ProductId", order.ProductId);
            return(View(order));
        }
Пример #26
0
        //Create some laptop

        public async Task <LaptopModels> createLaptop(LaptopModels laptop)
        {
            _db.LaptopModels.Add(laptop);
            await _db.SaveChangesAsync();

            //Last input in database
            var lastInput = await(from k in _db.LaptopModels
                                  select k)
                            .OrderByDescending(k => k.ID)
                            .FirstOrDefaultAsync();

            //Get new full price
            lastInput.FullPrice = await(from k in _db.LaptopModels where k.ID == lastInput.ID select k.Price * k.Quantity).FirstAsync();
            //Get new saving
            lastInput.Savings = await(from k in _db.LaptopModels where k.ID == lastInput.ID select k.OldPrice - k.Price).FirstAsync();
            lastInput.Date    = DateTime.Now;
            await _db.SaveChangesAsync();

            //Create new log

            LogModels log = new LogModels
            {
                Type        = "0",
                Description = "New laptop was inserted with name " + lastInput.Name + " on date " + lastInput.Date + " with quantity of " + lastInput.Quantity + ".",
                Date        = lastInput.Date
            };

            _db.LogModels.Add(log);
            await _db.SaveChangesAsync();


            return(lastInput);
        }
Пример #27
0
        //Logs

        public async Task <LogModels> log6(string userUsername, object tempdataCurrentRole)
        {
            LogModels log = new LogModels
            {
                Type        = "6",
                Description = "New change was made for user " + userUsername + " on date " + DateTime.Now + " for role " + tempdataCurrentRole + ".",
                Date        = DateTime.Now
            };

            _db.LogModels.Add(log);
            await _db.SaveChangesAsync();

            return(log);
        }
Пример #28
0
        public async Task <IActionResult> Add(Customer customer)
        {
            if (ModelState.IsValid)
            {
                if (_db.Customers.FirstOrDefault(c => c.PhoneNumber == customer.PhoneNumber) != null)
                {
                    return(Content("Заказчик с таким номером телефона уже существует."));
                }

                _db.Customers.Add(customer);
                await _db.SaveChangesAsync();
            }

            return(RedirectToAction("Customers", "Warehouse"));
        }
Пример #29
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description,Features")] ProductType productType)
        {
            if (!User.IsInRole(Areas.Identity.Roles.Admin))
            {
                return(RedirectToAction("Index", "ProductTypes"));
            }
            if (ModelState.IsValid)
            {
                _context.Add(productType);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(productType));
        }
Пример #30
0
        public async Task <IActionResult> Create([Bind("Id,Name,Address,Phone")] Supplier supplier)
        {
            if (!User.IsInRole(Areas.Identity.Roles.Admin))
            {
                return(RedirectToAction("Index", "Suppliers"));
            }
            if (ModelState.IsValid)
            {
                _context.Add(supplier);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(supplier));
        }