Beispiel #1
0
        public async Task <IActionResult> OnPostAssembleAsync(int id)
        {
            var lines = from i in _context.RecipeLines
                        where i.AssemblyRecipeId == id
                        select i;

            RecipeLines = await lines.ToListAsync();

            foreach (var line in RecipeLines)
            {
                Item = await _context.Items.FirstOrDefaultAsync(m => m.ItemId == line.ItemId);

                Item.OnHandQty             -= line.RequiredItemQty;
                Item.LastModifiedBy         = "AlphaTech"; // change to user
                Item.LastModifiedDate       = DateTime.Today;
                _context.Attach(Item).State = EntityState.Modified;
                await _context.SaveChangesAsync();
            }
            Item = await _context.Items.FirstOrDefaultAsync(m => m.ItemId == itemId);

            Item.OnHandQty++;
            Item.LastModifiedBy         = "AlphaTech"; // change to user
            Item.LastModifiedDate       = DateTime.Today;
            _context.Attach(Item).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(RedirectToPage());
            // return RedirectToPage("AssemblyRecipes/Details", new { id });
        }
Beispiel #2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            Item.LastModifiedBy         = User.Identity.Name; //change to user
            Item.LastModifiedDate       = DateTime.Today;
            _context.Attach(Item).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ItemExists(Item.ItemId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("/Inventory"));
        }
Beispiel #3
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(OrderItem).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OrderItemExists(OrderItem.OrderItemId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Beispiel #4
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }


            RecipeLine.LastModifiedBy   = "AlphTech"; //change to user
            RecipeLine.LastModifiedDate = DateTime.Today;

            _context.Attach(RecipeLine).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RecipeLineExists(RecipeLine.RecipeLineId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("/AssemblyRecipes/Details", new { id = RecipeLine.AssemblyRecipeId }));
        }
Beispiel #5
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Vendor = await _context.Vendors.FindAsync(id);

            Items = await _context.Items.ToListAsync();

            Vendors = await _context.Vendors.ToListAsync();

            //if user is trying to delete the last vendor just make it again

            if (Vendor.VendorName == "Vendor Deleted")
            {
                return(RedirectToPage("./Index"));
            }

            if (Vendors.Count <= 1)
            {
                Vendor defaultVendor = new Vendor();
                defaultVendor.VendorName       = "No Preferred Vendor";
                defaultVendor.LastModifiedBy   = "Please don't delete this";
                defaultVendor.LastModifiedDate = DateTime.Today;
                Vendors.Insert(0, defaultVendor);
                _context.Attach(Vendors).State = EntityState.Modified;
                //await _context.SaveChangesAsync();
            }

            foreach (var item in Items)
            {
                if (item.VendorId == Vendor.VendorId)
                {
                    Vendor vendor = _context.Vendors.FirstOrDefault(v => v.VendorName == "Vendor Deleted");

                    if (vendor == null)
                    {
                        vendor                  = new Vendor();
                        vendor.VendorName       = "Vendor Deleted";
                        vendor.LastModifiedBy   = "AphlaTech db protection";//maybe change to user name
                        vendor.LastModifiedDate = DateTime.Today;
                        _context.Vendors.Add(vendor);
                        await _context.SaveChangesAsync();
                    }

                    item.PreferredVendor        = vendor;
                    item.VendorId               = vendor.VendorId;
                    item.LastModifiedBy         = "db change"; //change to user
                    item.LastModifiedDate       = DateTime.Today;
                    _context.Attach(item).State = EntityState.Modified;
                }
            }



            if (Vendor != null)
            {
                _context.Vendors.Remove(Vendor);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }