public ActionResult Create(NewsViewModel newsViewModel) { News news = new News(); if (ModelState.IsValid) { if (newsViewModel.Photo != null) { ImageUploadService imageUploadService = new ImageUploadService(); bool isImageValid = imageUploadService.CheckImageExtension(newsViewModel); if (isImageValid == true) { string fileName = imageUploadService.UploadImage(newsViewModel); news.Photo = fileName; } else { ModelState.AddModelError("PhotoContentTypeError", "The file you are trying to upload is not an image!"); return(View(newsViewModel)); } } news.ID = newsViewModel.ID; news.Title = newsViewModel.Title; news.Content = newsViewModel.Content; List <Users> allUsers = UnitOfWork.UOW.UserRepository.GetAll(); Users currentUser = allUsers.Where(x => x.ID == SessionDTO.ID).FirstOrDefault(); news.User = currentUser; return(base.Create(news)); } else { return(View(newsViewModel)); } }