public async Task <IActionResult> Edit(Entity.News entity, IFormFile file) { if (ModelState.IsValid) { //News tbl_News = new News(); if (file != null) { //Set Key Name string FileName = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName); //Get url To Save string SavePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/img", FileName); using (var stream = new FileStream(SavePath, FileMode.Create)) { await file.CopyToAsync(stream); } if (file.FileName == null) { } entity.NewsImg = file.FileName; } newsRepository.UpdateNews(entity); return(RedirectToAction("Index")); } ViewData["CategoryId"] = new SelectList(categoryRepository.GetAll(), "Id", "CatName"); return(View(entity)); }
protected void Page_Load(object sender, EventArgs e) { b_News = new BLL.News(); if (!IsPostBack) { GetNewsTXT(News_Name); SetLanguageControl(News_LanguageID); switch (g_Action_ID) { case 1: News_AddTime_TD.Visible = false; News_Submit.Text = " 添加 "; break; case 2: if (g_News_ID == 0) ResponseError("参数错误"); e_News = b_News.Select_News(g_News_ID); if (e_News != null) { News_LanguageID.SelectedValue = e_News.News_LanguageID.ToString(); News_AddTime.Text = e_News.News_AddTime.ToString(); News_Intro.Text = e_News.News_Intro; News_Title.Text = e_News.News_Title; News_Content.Value = e_News.News_Content; } News_Submit.Text = " 修改 "; break; case 3: if (g_News_ID == 0) ResponseError("参数错误"); b_News.Delete_News(g_News_ID); ResponseClose("删除成功"); break; } } }
public async Task <IActionResult> Create(Entity.News entity, IFormFile file) { if (ModelState.IsValid) { var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\img", file.FileName); using (var stream = new FileStream(path, FileMode.Create)) { await file.CopyToAsync(stream); } entity.IsActiv = true; entity.ViewCount = 0; entity.NewsImg = file.FileName; newsRepository.AddNews(entity); return(RedirectToAction("Index")); } return(View(entity)); }