public async Task <ActionResult> CreateNews(CorrectNewsForm news) { var user = await _userManager.GetUserAsync(HttpContext.User); if (ModelState.IsValid) { var newsDB = new NewsDB { Id = _rand.Next(), Title = news.Title, Body = news.Body, AuthorId = user.Id, CategotyId = news.CategoryId, Date = DateTime.Now }; _newsProvider.AddNewsDB(newsDB); var path = Configuration.GetValue <String>("Path1") + newsDB.Id.ToString(); if (news.Picture != null && news.Picture.Length > 0 && ImageUtils.IsImage(news.Picture)) { using (var stream = new FileStream(path, FileMode.OpenOrCreate)) { await news.Picture.CopyToAsync(stream); } } } else { ModelState.AddModelError(string.Empty, "Не удалось сохранить новость"); } return(RedirectToAction("UserProfile", "User")); }
public async Task <ActionResult> CorrectNews(CorrectNewsForm news) { var user = await _userManager.GetUserAsync(HttpContext.User); var newsDB = _newsProvider.GetNewsDB(news.Id); if (ModelState.IsValid && newsDB != null && user.Id == newsDB.AuthorId) { newsDB.Title = news.Title; newsDB.CategotyId = news.CategoryId; newsDB.Body = news.Body; newsDB.Date = DateTime.Now; var path = Configuration.GetValue <String>("Path1") + news.Id.ToString(); if (news.Picture != null && news.Picture.Length > 0) { using (var stream = new FileStream(path, FileMode.OpenOrCreate)) { await news.Picture.CopyToAsync(stream); } } _newsProvider.UpdateNewsDB(news.Id, newsDB); } else { ModelState.AddModelError(string.Empty, "Не удалось сохранить новость"); } return(RedirectToAction("UserProfile", "User")); }