コード例 #1
0
ファイル: BooksController.cs プロジェクト: Elektri/Athene
        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));
        }
コード例 #2
0
ファイル: BooksController.cs プロジェクト: Elektri/Athene
        public IActionResult AddToStore(int?bookId)
        {
            if (bookId == null)
            {
                return(RedirectToAction("Index"));
            }

            var book = _inventoryService.FindBookById(bookId.Value);

            var viewModel = new CreateBookItemViewModel
            {
                BookId = book.Id,
                Book   = book,
            };

            return(View(viewModel));
        }