コード例 #1
0
        // GET: Clothes/Create
        public IActionResult Create()
        {
            ClothesUploadPictureViewModel model = new ClothesUploadPictureViewModel();

            model.Clothes             = new Clothes();
            ViewData["ClothesTypeId"] = new SelectList(_context.ClothesType, "ClothesTypeId", "Description");
            ViewData["UserId"]        = new SelectList(_context.ApplicationUsers, "Id", "Id");
            return(View());
        }
コード例 #2
0
        public async Task <IActionResult> Create(ClothesUploadPictureViewModel model)
        {
            ModelState.Remove("UserId");

            var user = await  GetCurrentUserAsync();

            if (ModelState.IsValid)
            {
                model.Clothes.User   = user;
                model.Clothes.UserId = user.Id;
                await UploadImage(model.ImageFile);

                model.Clothes.ImagePath = model.ImageFile.FileName;
                _context.Add(model.Clothes);

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ClothesTypeId"] = new SelectList(_context.ClothesType, "ClothesTypeId", "Description", model.Clothes.ClothesTypeId);
            ViewData["UserId"]        = new SelectList(_context.ApplicationUsers, "Id", "Id", model.Clothes.UserId);
            return(View(model));
        }