コード例 #1
0
        public async Task <IActionResult> OnPostEditReq()
        {
            Suppliers = _context.Suppliers.AsNoTracking().Select(n => new SelectListItem
            {
                Value = n.Id.ToString(),
                Text  = n.Name
            }).ToList();
            WarehouseStock = _context.WarehouseStock.AsNoTracking().Select(n => new SelectListItem
            {
                Value = n.Id.ToString(),
                Text  = n.StockName
            }).ToList();
            AllSuppliers      = _context.Suppliers.AsNoTracking().ToList();
            AllWarehouseStock = _context.WarehouseStock.AsNoTracking().ToList();
            ApplicationUser   = await _userManager.GetUserAsync(User);

            Supplier         = AllSuppliers.FirstOrDefault(s => s.Id == Requisitions.FirstOrDefault().SupplierId);
            SelectedSupplier = Supplier.Name;
            List <Warehouse> wStock = new List <Warehouse>();

            foreach (var req in Requisitions)
            {
                wStock.Add(AllWarehouseStock.FirstOrDefault(w => w.Id == req.StockId));
            }
            WStock = wStock;
            if (await _userManager.IsInRoleAsync(ApplicationUser, "Admin"))
            {
                try
                {
                    CreatePDF(AllSuppliers.FirstOrDefault(s => s.Id == Convert.ToInt32(SelectedSupplier)).Email, ReqNo);
                }
                catch (Exception)
                {
                    _logger.LogError("Error in creating PDF");
                }
                Requisitions = _context.Requisitions.AsNoTracking().Where(r => r.ReqNo == ReqNo).ToList();
                foreach (var req in Requisitions)
                {
                    req.Approved     = "Approved";
                    req.ApprovedDate = DateTime.Now;
                    req.Approver     = ApplicationUser.UserName;

                    _context.Requisitions.Update(req);
                }
                _context.SaveChanges();
                TempData["StatusMessage"] = "Requisition created, approved and sent to supplier.";
            }
            else
            {
                TempData["StatusMessage"] = "Requisition created and waiting approval.";
            }
            return(Redirect("~/WarehousePages/RequisitionIndex"));
        }
コード例 #2
0
        public async Task <IActionResult> OnPostAddItems()
        {
            Suppliers = _context.Suppliers.AsNoTracking().Select(n => new SelectListItem
            {
                Value = n.Id.ToString(),
                Text  = n.Name
            }).ToList();
            WarehouseStock = _context.WarehouseStock.AsNoTracking().Select(n => new SelectListItem
            {
                Value = n.Id.ToString(),
                Text  = n.StockName
            }).ToList();
            AllSuppliers      = _context.Suppliers.AsNoTracking().ToList();
            AllWarehouseStock = _context.WarehouseStock.AsNoTracking().ToList();
            Supplier          = AllSuppliers.FirstOrDefault(s => s.Id == Requisitions.FirstOrDefault().SupplierId);
            SelectedSupplier  = Supplier.Name;
            List <Warehouse> wStock = new List <Warehouse>();

            foreach (var req in Requisitions)
            {
                wStock.Add(AllWarehouseStock.FirstOrDefault(w => w.Id == req.StockId));
            }
            WStock = wStock;
            Warehouse warehouseStock = new Warehouse();

            warehouseStock = _context.WarehouseStock.AsNoTracking().AsNoTracking().FirstOrDefault(s => s.Id == Convert.ToInt32(SelectedStock));

            ApplicationUser = await _userManager.GetUserAsync(User);

            Requisition requisition = new Requisition
            {
                StockId      = warehouseStock.Id,
                Quantity     = Quantity,
                Price        = warehouseStock.Price,
                Total        = warehouseStock.Price * Quantity,
                Requester    = ApplicationUser.UserName,
                ReqDate      = DateTime.Now,
                SupplierId   = Convert.ToInt32(SelectedSupplier),
                ReqNo        = ReqNo,
                Approved     = "Waiting Approval",
                ApprovedDate = DateTime.Now
            };
            await _context.Requisitions.AddAsync(requisition);

            await _context.SaveChangesAsync();

            Requisitions = _context.Requisitions.AsNoTracking().Where(r => r.ReqNo == ReqNo).ToList();
            return(Page());
        }