예제 #1
0
        public async Task <IActionResult> GoodsCreate([Bind("Id,Name,Price,Detail,picture")] Goods goods)
        {
            if (HttpContext.User.Identity.IsAuthenticated)
            {
                var u     = HttpContext.User.Claims.First().Value;
                var users = _context.ApplicationUsers.Find(Guid.Parse(u));
                ViewBag.User = users;
                var files = Request.Form.Files;
                if (ModelState.IsValid)
                {
                    goods.Id = Guid.NewGuid();
                    string webRootPath = _hostingEnvironment.WebRootPath;
                    if (files.Count > 0)
                    {
                        int    g           = files[0].FileName.LastIndexOf(".");
                        string newFileName = goods.Id.ToString() + files[0].FileName.Substring(g);
                        var    filePath    = webRootPath + "/Images/" + newFileName;
                        goods.picture = "/Images/" + newFileName;
                        using (var stream = new FileStream(filePath, FileMode.Create))
                        {
                            await files[0].CopyToAsync(stream);
                        }
                    }
                    _context.Add(goods);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(GoodsIndex)));
                }
                return(View(goods));
            }
            return(RedirectToAction("Login"));
        }
예제 #2
0
 public async Task<IActionResult> Create([Bind("Id,Name,Price,Detail,SaleState,picture")] Food food)
 {
     if (ModelState.IsValid)
     {
         food.Id = Guid.NewGuid();
         _context.Add(food);
         await _context.SaveChangesAsync();
         return RedirectToAction(nameof(Index));
     }
     return View(food);
 }
        public async Task <IActionResult> Create([Bind("Id,Name,Position,Date,Detail,picture")] Scenic scenic)
        {
            if (ModelState.IsValid)
            {
                scenic.Id = Guid.NewGuid();
                _context.Add(scenic);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(scenic));
        }
예제 #4
0
        public async Task <IActionResult> Create([Bind("Id,Name,Price,Detail,SaleState,picture")] Commodity commodity)
        {
            if (ModelState.IsValid)
            {
                commodity.Id = Guid.NewGuid();
                _context.Add(commodity);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(commodity));
        }
예제 #5
0
        public async Task <IActionResult> Create([Bind("Id,Grade,Lng,Lat,Addr,Type,Opentime,Tel,Url")] ScenicSpot scenicSpot)
        {
            if (ModelState.IsValid)
            {
                scenicSpot.Id = Guid.NewGuid();
                _context.Add(scenicSpot);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(scenicSpot));
        }
예제 #6
0
        public async Task <IActionResult> Create([Bind("Id,CityName")] City city)
        {
            if (ModelState.IsValid)
            {
                city.Id = Guid.NewGuid();
                _context.Add(city);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(city));
        }
예제 #7
0
        public async Task <IActionResult> Create([Bind("Id,themeName")] Theme theme)
        {
            if (ModelState.IsValid)
            {
                theme.Id = Guid.NewGuid();
                _context.Add(theme);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(theme));
        }
예제 #8
0
        public async Task <IActionResult> Create([Bind("Id,LabelName")] Label label)
        {
            if (ModelState.IsValid)
            {
                label.Id = Guid.NewGuid();
                _context.Add(label);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(label));
        }
예제 #9
0
        public async Task <IActionResult> Create([Bind("TravelsID,TravelsTitle,travelsTime,Like,Collection,Share")] Travels travels)
        {
            if (ModelState.IsValid)
            {
                travels.TravelsID = Guid.NewGuid();
                _context.Add(travels);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(travels));
        }
예제 #10
0
        public async Task <IActionResult> Create([Bind("Id,Name,Price,Detail,picture")] Goods goods)
        {
            if (ModelState.IsValid)
            {
                goods.Id = Guid.NewGuid();
                _context.Add(goods);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(goods));
        }
        public async Task <IActionResult> Create([Bind("Id,Name")] FoodClass foodClass)
        {
            if (ModelState.IsValid)
            {
                foodClass.Id = Guid.NewGuid();
                _context.Add(foodClass);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(foodClass));
        }
        public async Task <int> CreateAsync(CreateProductRepositoryModel model)
        {
            var added = _dbContext.Add(new ProductRepositoryModel
            {
                MPN   = model.MPN,
                Price = model.Price,
                Title = model.Title
            });

            await this._dbContext.SaveChangesAsync();

            return(added.Entity.Id);
        }