Example #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,NotionId,ProductId,QtyNotionOnProduct")] ProductNotionQuantity productNotionQuantity)
        {
            if (id != productNotionQuantity.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var     user            = _userManger.GetUserName(HttpContext.User);
                    var     productName     = "";
                    var     productQuantity = 0;
                    var     notionName      = "";
                    decimal notionQuantity  = 0;
                    foreach (var item in _context.Product)
                    {
                        if (productNotionQuantity.ProductId == item.Id)
                        {
                            productName     = item.Title;
                            productQuantity = item.Quantity;
                        }
                    }
                    foreach (var item in _context.Notion)
                    {
                        if (productNotionQuantity.NotionId == item.Id)
                        {
                            notionName     = item.Title;
                            notionQuantity = item.Quantity;
                        }
                    }
                    _context.Update(productNotionQuantity);
                    await _context.SaveChangesAsync();

                    logger.Info(user + " edited to " + productName + " with quantity of " + productQuantity + " and " + notionName + " with quantity of " + notionQuantity);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductNotionQuantityExists(productNotionQuantity.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Details", "Products", new { id = productNotionQuantity.ProductId }));
            }
            ViewData["NotionId"]  = new SelectList(_context.Notion, "Id", "Id", productNotionQuantity.NotionId);
            ViewData["ProductId"] = new SelectList(_context.Product, "Id", "Id", productNotionQuantity.ProductId);
            return(View(productNotionQuantity));
        }
Example #2
0
        public async Task <IActionResult> Create([Bind("Id,NotionId,ProductId,QtyNotionOnProduct")] ProductNotionQuantity productNotionQuantity)
        {
            productNotionQuantity.ProductId = productNotionQuantity.Id;
            productNotionQuantity.Id        = 0;
            var     user            = _userManger.GetUserName(HttpContext.User);
            var     productName     = "";
            var     productQuantity = 0;
            var     notionName      = "";
            decimal notionQuantity  = 0;

            foreach (var item in _context.Product)
            {
                if (productNotionQuantity.ProductId == item.Id)
                {
                    productName     = item.Title;
                    productQuantity = item.Quantity;
                }
            }
            foreach (var item in _context.Notion)
            {
                if (productNotionQuantity.NotionId == item.Id)
                {
                    notionName     = item.Title;
                    notionQuantity = item.Quantity;
                }
            }
            if (ModelState.IsValid)
            {
                _context.Add(productNotionQuantity);
                await _context.SaveChangesAsync();

                logger.Info(user + " created " + productName + " with quantity of " + productQuantity + " and " + notionName + " with quantity of " + notionQuantity);
                return(RedirectToAction("Index"));
            }
            else
            {
                _context.Add(productNotionQuantity);
                await _context.SaveChangesAsync();

                logger.Info(user + " created " + productName + " with quantity of " + productQuantity + " and " + notionName + " with quantity of " + notionQuantity);
                return(RedirectToAction("Details", "Products", new { id = productNotionQuantity.ProductId }));
            }
            ViewData["NotionId"]  = new SelectList(_context.Notion, "Id", "Title", productNotionQuantity.NotionId);
            ViewData["ProductId"] = productNotionQuantity.ProductId;
            return(View(productNotionQuantity));
        }