Пример #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 });
        }
Пример #2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            AssemblyRecipe = await _context.AssemblyRecipes
                             .Include(a => a.Item).FirstOrDefaultAsync(m => m.AssemblyRecipeId == RecipeId);

            var lines = from i in _context.RecipeLines
                        where i.AssemblyRecipeId == RecipeId
                        select i;

            RecipeLines = await lines.ToListAsync();

            IList <RecipeLine> recipeLines = lines.ToList();

            //I need to make sure Im also passing the item that is trying to be added to the
            //assembly into notCircular
            recipeLines.Insert(0, RecipeLine);

            //need to make sure its not adding itself
            if (notCircular(recipeLines))//.ItemId != RecipeLine.ItemId)
            {
                //need to increase count when adding items that are
                //already a part of the assembly recipe
                //instead of adding a new line
                foreach (var line in RecipeLines)
                {
                    if (RecipeLine.ItemId == line.ItemId)
                    {
                        line.RequiredItemQty += RecipeLine.RequiredItemQty;
                        _context.RecipeLines.Update(line);
                        await _context.SaveChangesAsync();

                        return(RedirectToPage("/AssemblyRecipes/Details", new { id = RecipeId }));
                    }
                }
                RecipeLine.AssemblyRecipeId = RecipeId;
                RecipeLine.LastModifiedBy   = "AlphaTech";//set to logged in user
                RecipeLine.LastModifiedDate = DateTime.Today;
                Item = await _context.Items.FirstOrDefaultAsync(m => m.ItemId == RecipeLine.ItemId);

                RecipeLine.Item = Item;
                _context.RecipeLines.Add(RecipeLine);
                await _context.SaveChangesAsync();

                return(RedirectToPage("/AssemblyRecipes/Details", new { id = RecipeLine.AssemblyRecipeId }));
            }
            return(RedirectToPage("/AssemblyRecipes/Details", new { id = RecipeId }));
        }
Пример #3
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            OrderItem.LastModifiedDate = DateTime.Today;
            OrderItem.LastModifiedBy   = "AlphaTech Team";

            _context.OrderItems.Add(OrderItem);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Пример #4
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"));
        }
Пример #5
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"));
        }
Пример #6
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 }));
        }
Пример #7
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            Item = await _context.Items.FirstOrDefaultAsync(m => m.ItemId == AssemblyRecipe.ItemId);

            Item.IsAssembled = true;

            //Item.LastModifiedBy = "AlphaTech"; //change to user
            Item.LastModifiedBy   = User.Identity.Name;
            Item.LastModifiedDate = DateTime.Today;
            _context.AssemblyRecipes.Add(AssemblyRecipe);
            await _context.SaveChangesAsync();

            Item.AssemblyRecipeId = AssemblyRecipe.AssemblyRecipeId;//this isnt set until after the context is saved
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Details", new { id = Item.AssemblyRecipeId }));
        }
Пример #8
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Assemblies.Add(Assembly);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Пример #9
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Item = await _context.Items.FindAsync(id);

            //get all recipe lines that contain this item
            var lines = from i in _context.RecipeLines
                        where i.ItemId == Item.ItemId
                        select i;

            RecipeLines = await lines.ToListAsync();

            if (Item != null)
            {
                //if its an assemble item then delete its recipe first
                if (Item.IsAssembled)
                {
                    AssemblyRecipe = await _context.AssemblyRecipes.FindAsync(Item.AssemblyRecipeId);

                    _context.AssemblyRecipes.Remove(AssemblyRecipe);
                    await _context.SaveChangesAsync();
                }
                //delete all recipe lines that contained this item
                foreach (var line in RecipeLines)
                {
                    _context.RecipeLines.Remove(line);
                    await _context.SaveChangesAsync();
                }
                //delete the item
                _context.Items.Remove(Item);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("/Inventory"));
        }
Пример #10
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            OrderItem = await _context.OrderItems.FindAsync(id);

            if (OrderItem != null)
            {
                _context.OrderItems.Remove(OrderItem);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Пример #11
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Assembly = await _context.Assemblies.FindAsync(id);

            if (Assembly != null)
            {
                _context.Assemblies.Remove(Assembly);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Пример #12
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            RecipeLine = await _context.RecipeLines.FindAsync(id);

            if (RecipeLine != null)
            {
                _context.RecipeLines.Remove(RecipeLine);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("/AssemblyRecipes/Details", new { id = RecipeLine.AssemblyRecipeId }));
        }
Пример #13
0
        public async Task<IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return Page();
            }
            //stop from adding the same item twice
            Item temp = _context.Items.FirstOrDefault(i => i.ItemName == Item.ItemName);

            if (temp != null)
            {
                return Page();
            }

            //Item.LastModifiedBy = "AlphaTech";//TODO: change this to the logged in user
            Item.LastModifiedBy = User.Identity.Name;
            Item.LastModifiedDate = DateTime.Today;
            _context.Items.Add(Item);
            await _context.SaveChangesAsync();

            return RedirectToPage("/Inventory");
        }
Пример #14
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            AssemblyRecipe = await _context.AssemblyRecipes.FindAsync(id);

            Item = await _context.Items.FirstOrDefaultAsync(m => m.ItemId == AssemblyRecipe.ItemId);

            if (AssemblyRecipe != null)
            {
                Item.AssemblyRecipeId = null;
                Item.IsAssembled      = false;
                Item.LastModifiedBy   = "AlphaTech"; //change to user
                Item.LastModifiedDate = DateTime.Today;
                _context.AssemblyRecipes.Remove(AssemblyRecipe);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("/Items/Details", new  { id = Item.ItemId }));
        }
Пример #15
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"));
        }