Example #1
0
        public async Task <ActionResult> AddNews(IFormFile files, News news)//添加商品
        {
            if (!ReLogin())
            {
                return(RedirectToAction("Index", "Login"));
            }
            if (news.NewsId > 0)//修改
            {
                _context.Update(news);
                await _context.SaveChangesAsync();
            }
            else
            {
                var fileName = files.FileName;
                var filePath = _hostingEnvironment.WebRootPath + @"\images\" + fileName; //获取wwwboot目录
                                                                                         //根据路径创建文件
                using (var stream = new FileStream(filePath, FileMode.Create))
                {
                    await files.CopyToAsync(stream);
                }
                news.PhotoUrl = fileName;
                _context.Add(news);
                await _context.SaveChangesAsync();
            }

            return(RedirectToAction("NewsManage", "Home"));
        }
Example #2
0
        public async Task <IActionResult> Edit(int id, [Bind("AdminUsersId,UserName,Pwd,Role")] AdminUser adminUser)
        {
            if (id != adminUser.AdminUsersId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(adminUser);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AdminUserExists(adminUser.AdminUsersId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(adminUser));
        }