Beispiel #1
0
        public async Task AddNewsAsync(AddNewsInputModel input)
        {
            var news = new News
            {
                Name        = input.Name,
                Description = input.Description,
                ImageName   = input.ImageName,
                NewsDate    = DateTime.UtcNow,
            };

            await this.newsRepository.AddAsync(news);

            await this.newsRepository.SaveChangesAsync();
        }
Beispiel #2
0
        public async Task <IActionResult> AddNews(AddNewsInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View());
            }

            if (input.Image != null && input.Image.Length > 0)
            {
                using (FileStream fs = new FileStream(this.webHostEnvironment.WebRootPath + ("/images/news/" + input.ImageName + ".jpg"), FileMode.Create))
                {
                    await input.Image.CopyToAsync(fs);
                }
            }

            await this.newsService.AddNewsAsync(input);

            return(this.RedirectToAction(nameof(this.Success)));
        }