コード例 #1
0
 // GET: Books/Create
 public IActionResult Create()
 {
     ViewData["BookConditionId"] = new SelectList(_context.BookCondition, "BookConditionId", "Condition");
     ViewData["SellerId"]        = new SelectList(_context.Set <Seller>(), "UserId", "Discriminator");
     ViewData["StudyAreaId"]     = new SelectList(_context.StudyArea, "StudyAreaId", "StudyAreaName");
     return(View());
 }
コード例 #2
0
 // GET: Orders/Create
 public IActionResult Create()
 {
     ViewData["BookId"]   = new SelectList(_context.Book, "BookId", "ISBN");
     ViewData["BuyerId"]  = new SelectList(_context.Set <Buyer>(), "UserId", "Discriminator");
     ViewData["SellerId"] = new SelectList(_context.Set <Seller>(), "UserId", "Discriminator");
     return(View());
 }
コード例 #3
0
        public async Task <IActionResult> Create(int BookId, string Title, string Description, string ISBN, string Publisher
                                                 , int Edition, int Quantity, double Price, int BookConditionId, int StudyAreaId,
                                                 IFormFile PhotoFileName)
        {
            Book book = new Book
            {
                Blocked         = false,
                BookConditionId = BookConditionId,
                CreationDate    = DateTime.Now,
                Description     = Description,
                Edition         = Edition,
                ISBN            = ISBN,
                IsWaitList      = false,
                Price           = Price,
                Publisher       = Publisher,
                Quantity        = Quantity,
                QuantitySold    = 0,
                StudyAreaId     = StudyAreaId,
                Title           = Title
            };

            string LogedUser = this.User.Identity.Name;
            var    user      = (from s in _context.User where s.UserName == LogedUser select s.UserId).ToList();
            int    UserId    = user[0];

            if (UserId > 0)
            {
                book.UserId = UserId;
                if (PhotoFileName != null)
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        await PhotoFileName.CopyToAsync(ms);

                        book.PhotoFileName = ms.ToArray();
                    }
                }
                if (ModelState.IsValid)
                {
                    _context.Add(book);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            ViewData["BookConditionId"] = new SelectList(_context.BookCondition, "BookConditionId", "Condition", book.BookConditionId);
            ViewData["SellerId"]        = new SelectList(_context.Set <Seller>(), "UserId", "Discriminator", book.UserId);
            ViewData["StudyAreaId"]     = new SelectList(_context.StudyArea, "StudyAreaId", "StudyAreaName", book.StudyAreaId);
            return(View(book));
        }