Beispiel #1
0
        public async Task <IActionResult> Add(NewViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var news = new New {
            };

            news.Id      = model.Id;
            news.Name    = model.Name;
            news.Context = model.Context;
            news.Created = DateTime.Now;

            if (model.UploadedPhoto != null)
            {
                news.Photo = await _photoService.AddNew(model.UploadedPhoto, news.Id, _webHostEnvironment.WebRootPath);
            }
            await _newService.Add(news);

            return(RedirectToAction("News"));
        }