public ActionResult NewsAdd(NewsModel model, HttpPostedFileBase Photo)
        {
            if (Photo != null)
            {
                var fileName = Path.GetFileNameWithoutExtension(Photo.FileName);
                var extension = Path.GetExtension(Photo.FileName);
                var fileFullName = Guid.NewGuid() + fileName.Replace(" ", "").Replace(".", "") + extension;
                var path = Path.Combine(Server.MapPath("~/Content/images/haber"), fileFullName);
                Photo.SaveAs(path);

                News news = new News
                {
                    Active = model.Active,
                    Content = model.Content,
                    Photo = "images/haber/" + fileFullName,
                    Creator = model.Creator,
                    Date = model.Date,
                    Title = model.Title,
                    SeoUrl = Change(model.Title)
                };

                _newsService.Insert(news);
                _uow.SaveChanges();
            }

            return RedirectToAction("ListNews");
        }
Exemple #2
0
 /// <summary>
 /// Delete a news by news entity.
 /// </summary>
 /// <param name="news">News</param>
 public void Delete(News news)
 {
     _newsRepository.Delete(news);
 }
Exemple #3
0
 /// <summary>
 /// Update a news.
 /// </summary>
 /// <param name="news"></param>
 public void Update(News news)
 {
     _newsRepository.Update(news);
 }
Exemple #4
0
 /// <summary>
 /// Insert new news.
 /// </summary>
 /// <param name="news"></param>
 public void Insert(News news)
 {
     _newsRepository.Insert(news);
 }