public StockMovementActionResultModel Create(string productCode, [FromBody] CreateStockmovementModel model)
        {
            if (!ModelState.IsValid)
            {
                throw new ValidationException(ModelState);
            }

            var product = _ctx.Set <ProductEntity>().SingleOrDefault(e => e.Code == productCode);

            if (product == null)
            {
                throw new NotFoundException();
            }

            var stockMovement = new StockMovementEntity {
                Price     = product.Price,
                Quantity  = model.Quantity,
                CreatedOn = DateTimeOffset.Now,
                CreatedBy = this.GetUserName(),
                Product   = product
            };

            _ctx.Add(stockMovement);

            _ctx.SaveChanges();

            return(new StockMovementActionResultModel {
                Id = stockMovement.Id
            });
        }
Exemplo n.º 2
0
        private void SeedDummyData(WarehouseContext ctx)
        {
            var dummyData = new[]
            {
                new ProductEntity
                {
                    Code           = "111",
                    Name           = "Bola",
                    Description    = "fantastico",
                    Price          = 10.5m,
                    StockMoviments =
                    {
                        new StockMovimentEntity
                        {
                            Price     = 10.5m,
                            Quantity  = 2,
                            CreatedOn = DateTimeOffset.Now.AddDays(-2),
                            CreatedBy = "ruben.ribeiro"
                        }
                    },
                    CreatedOn = DateTimeOffset.Now.AddDays(-30),
                    CreatedBy = "ruben.ribeiro",
                    UpdatedOn = DateTimeOffset.Now.AddMinutes(-32),
                    UpdatedBy = "ruben.ribeiro"
                },

                new ProductEntity
                {
                    Code           = "222",
                    Name           = "Bola de futebol",
                    Description    = "not so Awesome",
                    Price          = 50.5m,
                    StockMoviments =
                    {
                        new StockMovimentEntity
                        {
                            Price     = 50.5m,
                            Quantity  = 2,
                            CreatedOn = DateTimeOffset.Now.AddDays(-20),
                            CreatedBy = "ruben.ribeiro"
                        }
                    },
                    CreatedOn = DateTimeOffset.Now.AddDays(-30),
                    CreatedBy = "ruben.ribeiro",
                    UpdatedOn = DateTimeOffset.Now.AddHours(-50),
                    UpdatedBy = "Marcolino"
                }
            };

            foreach (var p in dummyData)
            {
                ctx.Add(p);
            }

            ctx.SaveChanges();
        }
Exemplo n.º 3
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));
        }
Exemplo n.º 4
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));
        }
        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));
        }
Exemplo n.º 6
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));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Create(Item item)
        {
            if (ModelState.IsValid)
            {
                _context.Add(item);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(item));
        }
        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));
        }
Exemplo n.º 9
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("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));
        }
Exemplo n.º 11
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));
        }
Exemplo n.º 12
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));
        }
Exemplo n.º 13
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));
        }
        public async Task <IActionResult> Create([Bind("Id,Name")] Employee employee)
        {
            if (!User.IsInRole(Areas.Identity.Roles.Admin))
            {
                return(RedirectToAction("Index", "Employees"));
            }
            if (ModelState.IsValid)
            {
                _context.Add(employee);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(employee));
        }
Exemplo n.º 15
0
        public async Task <IActionResult> Create([Bind("Name,WarehouseSector,PlacingDate")] Stock stock)
        {
            if (ModelState.IsValid)
            {
                _ = long.TryParse(TempData["Id"].ToString(), out long clientId);
                stock.ClientId = clientId;
                stock.Client   = await _context.Clients
                                 .FirstOrDefaultAsync(client => client.Id == stock.ClientId);

                _context.Add(stock);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Details", "Clients", new { id = clientId }));;
            }
            return(View(stock));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,StorageConditions,Packaging,ExpiryDate,Price,ProductTypeId,ManufacturerId")] Product product)
        {
            if (!User.IsInRole(Areas.Identity.Roles.Admin))
            {
                return(RedirectToAction("Index", "Products"));
            }
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ManufacturerId"] = new SelectList(_context.Manufacturers, "Id", "Name", product.ManufacturerId);
            ViewData["ProductTypeId"]  = new SelectList(_context.ProductTypes, "Id", "Name", product.ProductTypeId);
            return(View(product));
        }
        public async Task <IActionResult> Create([Bind("Id,OrderDate,DepartureDate,Quantity,Price,CustomerId,ProductId,DeliveryMethodId,EmployeeId")] CustomerProduct customerProduct)
        {
            if (!User.IsInRole(Areas.Identity.Roles.Admin))
            {
                return(RedirectToAction("Index", "CustomerProducts"));
            }
            if (ModelState.IsValid)
            {
                _context.Add(customerProduct);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerId"]       = new SelectList(_context.Customers, "Id", "Name", customerProduct.CustomerId);
            ViewData["DeliveryMethodId"] = new SelectList(_context.DeliveryMethods, "Id", "Name", customerProduct.DeliveryMethodId);
            ViewData["EmployeeId"]       = new SelectList(_context.Employees, "Id", "Name", customerProduct.EmployeeId);
            ViewData["ProductId"]        = new SelectList(_context.Products, "Id", "Name", customerProduct.ProductId);
            return(View(customerProduct));
        }
        public async Task <IActionResult> Create(Products product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);

                _context.Entry(product.Category).State = EntityState.Unchanged;

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                var allCategories = this._context.Category.ToList();
                this.ViewBag.Categories = allCategories;
            }

            return(View(product));
        }
Exemplo n.º 19
0
        public void AddItem(int id, int barCode, string name, string description, int stock)
        {
            WarehouseItem i = db.Stock.Find(barCode);

            if (i == null)
            {
                db.Add(new WarehouseItem()
                {
                    name        = name,
                    barcode     = barCode,
                    description = description,
                    amount      = stock,
                });
            }

            else
            {
                i.amount += stock;

                db.SaveChangesAsync();
            }
        }
Exemplo n.º 20
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,DateOfBirth,PhoneNumber,Type")] Client client)
        {
            if (ModelState.IsValid)
            {
                var clients = await _context.Clients.ToListAsync();

                foreach (var c in clients)
                {
                    if (c.FirstName == client.FirstName && c.LastName == client.LastName && c.DateOfBirth == client.DateOfBirth)
                    {
                        TempData["ErrorMessage"] = "This client already exists.";
                        _logger.LogWarning("Client not created. This client already exists.");
                        return(View(client));
                    }
                }

                _context.Add(client);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Home"));
            }
            return(View(client));
        }
Exemplo n.º 21
0
 public void Add(T entity)
 {
     warehouseContext.Add(entity);
     warehouseContext.SaveChanges();
 }