Esempio n. 1
0
        public IActionResult AddToStore(CreateBookItemViewModel model)
        {
            if (ModelState.IsValid)
            {
                var book     = _inventoryService.FindBookById(model.BookId);
                var bookItem = new BookItem
                {
                    Book          = book,
                    StockLocation = new StockLocation
                    {
                        Hall     = model.Hall.Value,
                        Corridor = model.Corridor.Value,
                        Rack     = model.Rack.Value,
                        Level    = model.Level.Value,
                        Position = model.Position.Value,
                    }
                };
                if (!string.IsNullOrWhiteSpace(model.Note))
                {
                    //TODO: add userId
                    var note = new BookItemNote
                    {
                        Text      = model.Note,
                        CreatedAt = DateTime.Now,
                    };
                    bookItem.Notes.Add(note);
                }
                _inventoryService.AddBookItem(bookItem);
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }