public async Task <IActionResult> Edit(int id, SalesRecord salesRecord)
        {
            if (!ModelState.IsValid)
            {
                var sellers = await _sellerService.FindAllAsync();

                var viewModel = new SalesFormViewModel {
                    SalesRecord = salesRecord, Sellers = sellers
                };
                return(View(viewModel));
            }

            if (id != salesRecord.Id)
            {
                return(RedirectToAction(nameof(Error), new { message = "Id mismatch" }));
            }
            try
            {
                await _salesRecordService.UpdateAsync(salesRecord);

                return(RedirectToAction(nameof(Records)));
            }
            catch (NotFoundException e)
            {
                return(RedirectToAction(nameof(Error), new { message = e.Message }));
            }
            catch (DbConcurrencyException e)
            {
                return(RedirectToAction(nameof(Error), new { message = e.Message }));
            }
        }
Пример #2
0
        public JsonResult SaveOrder(SalesFormViewModel viewModel)
        {
            bool status = false;

            Sale sale = new Sale()
            {
                InvoiceId = viewModel.InvoiceId,
                DateTime  = viewModel.DateTime,
                ProductId = viewModel.ProductId,
                Quantity  = viewModel.Quantity
            };

            var reduceProductStock = _context.Products.Single(p => p.ProductId == viewModel.ProductId);

            reduceProductStock.StoreQuantity -= sale.Quantity;

            var isValidModel = TryUpdateModel(sale);

            if (isValidModel)
            {
                _context.Sales.Add(sale);
                _context.SaveChanges();
            }

            status = true;

            return(new JsonResult {
                Data = new { status = status }
            });
        }
Пример #3
0
        public async Task <IActionResult> BuscaAgrupada
            (DateTime?datamin, DateTime?datamax, int?departamentoId, int?vendedorId)
        {
            if (!datamin.HasValue)
            {
                datamin = new DateTime(DateTime.Now.Year, 01, 01);
            }
            if (!datamax.HasValue)
            {
                datamax = DateTime.Now;
            }

            var vendedores = await _Seller.FindAllAsync();

            var departamentos = await _departamentoService.FindAllAsync();

            var vendas = await _SalesService.FindByDateGroupAsync(datamin, datamax, departamentoId, vendedorId);

            var viewmodel = new SalesFormViewModel
            {
                Vendas = vendas, Departamentos = departamentos, Vendedores = vendedores
            };


            ViewData["datamin"] = datamin.Value.ToString("dd/MM/yyyy");
            ViewData["datamax"] = datamin.Value.ToString("dd/MM/yyyy");
            return(View(viewmodel));
        }
        public async Task <IActionResult> Edit(int id, Sales sales)
        {
            if (!ModelState.IsValid)
            {
                var clients = await _clientService.FindAllAsync();

                var status = await _statusService.FindAllAsync();

                var viewModel = new SalesFormViewModel {
                    Sales = sales, Clients = clients, Status = status
                };
                return(View(viewModel));
            }

            if (id != sales.Id)
            {
                return(RedirectToAction(nameof(Error), new { message = "Ids não correspondem!" }));
            }
            try
            {
                await _salesService.UpdateAsync(sales);

                return(RedirectToAction(nameof(Index)));
            }
            catch (ApplicationException e)
            {
                return(RedirectToAction(nameof(Error), new { message = e.Message }));
            }
        }
        // GET: SalesRecords/Create
        public async Task <IActionResult> Create()
        {
            ViewData["SellerId"] = new SelectList(_context.Seller, "Id", "Email");
            var viewModel = new SalesFormViewModel {
                Sellers = await _context.Seller.ToListAsync()
            };

            return(View(viewModel));
        }
        public async Task <IActionResult> Create()
        {
            var sellers = await _sellerService.FindAllAsync();

            var viewModel = new SalesFormViewModel {
                Sellers = sellers
            };

            return(View(viewModel));
        }
        public async Task <IActionResult> Index()
        {
            List <Seller> sellers = await _sellerService.FindAllAsync();


            SalesFormViewModel viewModel = new SalesFormViewModel {
                Sellers = sellers
            };

            return(View(viewModel));
        }
        public async Task <IActionResult> Create()
        {
            var clients = await _clientService.FindAllAsync();

            var status = await _statusService.FindAllAsync();

            var viewModel = new SalesFormViewModel {
                Clients = clients, Status = status
            };

            return(View(viewModel));
        }
Пример #9
0
        public ActionResult Create()
        {
            var invoiceIdCount = _context.Sales.ToList().LastOrDefault().Id;

            var viewModel = new SalesFormViewModel
            {
                InvoiceId = invoiceIdCount + 1,
                DateTime  = DateTime.Now
            };

            return(View("Create3", viewModel));
        }
        public void DeleteItemFromSale(SalesFormViewModel viewModel)
        {
            var itemToDelete = _context.Sales
                               .Where(s => s.InvoiceId == viewModel.InvoiceId && s.ProductId == viewModel.ProductId)
                               .SingleOrDefault();

            if (itemToDelete == null)
            {
                HttpNotFound();
            }

            _context.Sales.Remove(itemToDelete);
            _context.SaveChanges();
        }
Пример #11
0
        public async Task <IActionResult> SearchByFilter(DateTime?minDate, DateTime?maxDate, Seller seller, Department department, int selectGroup)
        {
            ViewData["MinDate"] = minDate.Value.ToString("yyyy-MM-dd");
            ViewData["MaxDate"] = maxDate.Value.ToString("yyyy-MM-dd");
            ViewBag.Group       = selectGroup;

            var result = await _salesRecordService.FindByFilterAsync(minDate, maxDate, seller, department);

            SalesFormViewModel viewModel = new SalesFormViewModel()
            {
                Departments = await _departmentService.FindAllAsync(), Sellers = await _sellerService.FindAllAsync(), Sales = result
            };

            return(View(viewModel));
        }
Пример #12
0
        public async Task <IActionResult> Index()
        {
            DateTime today       = DateTime.Today;
            DateTime yestarday   = new DateTime(today.Year, today.Month, today.Day - 1);
            DateTime dateMinSale = await _salesRecordService.MinDateSaleAsync();

            ViewData["DefaultDataMax"] = today.ToString("yyyy-MM-dd");
            ViewData["DefaultDataMin"] = dateMinSale.ToString("yyyy-MM-dd");

            SalesFormViewModel viewModel = new SalesFormViewModel()
            {
                Departments = await _departmentService.FindAllAsync(), Sellers = await _sellerService.FindAllAsync()
            };

            return(View(viewModel));
        }
Пример #13
0
        public void DeleteItemFromSale(SalesFormViewModel viewModel)
        {
            var itemToDelete = _context.Sales
                               .Where(s => s.InvoiceId == viewModel.InvoiceId && s.ProductId == viewModel.ProductId)
                               .SingleOrDefault();

            if (itemToDelete == null)
            {
                HttpNotFound();
            }

            var fixProductStock = _context.Products.Single(p => p.ProductId == viewModel.ProductId);

            fixProductStock.StoreQuantity += itemToDelete.Quantity;

            _context.Sales.Remove(itemToDelete);
            _context.SaveChanges();
        }
        public async Task <IActionResult> Create(Sales sales)
        {
            if (!ModelState.IsValid)
            {
                var clients = await _clientService.FindAllAsync();

                var status = await _statusService.FindAllAsync();

                var viewModel = new SalesFormViewModel {
                    Sales = sales, Clients = clients, Status = status
                };
                return(View(viewModel));
            }

            await _salesService.InsertAsync(sales);

            return(RedirectToAction(nameof(Index)));
        }
        // GET: SalesRecords/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var salesRecord = await _context.SalesRecord.FindAsync(id);

            if (salesRecord == null)
            {
                return(NotFound());
            }
            ViewData["SellerId"] = new SelectList(_context.Seller, "Id", "Email", salesRecord.SellerId);
            var viewModel = new SalesFormViewModel {
                Sellers = await _context.Seller.ToListAsync(), SalesRecord = salesRecord
            };

            return(View(viewModel));
        }
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction(nameof(Error), new { message = "Id not provided" }));
            }

            var obj = await _salesRecordService.FindByIdAsync(id.Value);

            if (obj == null)
            {
                return(RedirectToAction(nameof(Error), new { message = "Id not found" }));
            }

            List <Seller> sellers = await _sellerService.FindAllAsync();

            SalesFormViewModel viewModel = new SalesFormViewModel
            {
                SalesRecord = obj,
                Sellers     = sellers
            };

            return(View(viewModel));
        }
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction(nameof(Error), new { message = "Id não fornecido!" }));
            }

            var obj = await _salesService.FindByIdAsync(id.Value);

            if (obj == null)
            {
                return(RedirectToAction(nameof(Error), new { message = "Id não encontrado!" }));
            }

            List <Client> clients = await _clientService.FindAllAsync();

            List <Status> status = await _statusService.FindAllAsync();

            SalesFormViewModel viewModel = new SalesFormViewModel {
                Sales = obj, Clients = clients, Status = status
            };

            return(View(viewModel));
        }