Ejemplo n.º 1
0
        public IActionResult AddToStore(CreateInventoryItemViewModel model)
        {
            if (ModelState.IsValid)
            {
                var article = _unitOfWork.Articles.FindArticleById(model.ArticleId);

                if (article == null)
                {
                    ModelState.AddModelError(string.Empty, "Artikel not found`");
                    return(View(model));
                }

                var inventoryItem = model.ToModel();
                inventoryItem.Article = article;
                if (!string.IsNullOrWhiteSpace(model.Note))
                {
                    var note = new ItemNote
                    {
                        Text      = model.Note,
                        CreatedAt = DateTime.Now,
                        UserId    = _userManager.GetUserId(User),
                    };
                    inventoryItem.Notes.Add(note);
                }
                _unitOfWork.Inventories.AddInventoryItem(inventoryItem);
                _unitOfWork.SaveChanges();
                return(RedirectToAction("Index", "Inventory"));
            }

            model.Article = _unitOfWork.Articles.FindArticleById(model.ArticleId);
            return(View(model));
        }
Ejemplo n.º 2
0
        public IActionResult AddToStore(int?articleId)
        {
            if (articleId == null)
            {
                return(RedirectToAction("Index", "Inventory"));
            }

            var article = _unitOfWork.Articles.FindArticleById(articleId.Value);

            if (article == null)
            {
                return(RedirectToAction("Index", "Inventory"));
            }

            var viewModel = new CreateInventoryItemViewModel
            {
                ArticleId = article.ArticleId,
                Article   = article,
            };

            return(View(viewModel));
        }
Ejemplo n.º 3
0
 public static InventoryItem ToModel(this CreateInventoryItemViewModel viewModel)
 {
     return(Mapper.Map <InventoryItem>(viewModel));
 }