예제 #1
0
        /// <summary>
        /// Edits Single NewsItem in Database from <see cref="EditNewsItemViewModel"/>
        /// </summary>
        /// <param name="model"></param>
        /// <returns><see cref="bool"/></returns>
        public async Task <bool> EditSingleNews(EditNewsItemViewModel model)
        {
            if (await _healthyGamerPortalDbContext.NewsItem.AsNoTracking().FirstOrDefaultAsync(i => i.Id == model.Id) != null)
            {
                var newsItem = _mapper.Map <EditNewsItemViewModel, NewsItem>(model);
                _healthyGamerPortalDbContext.Update(newsItem);
                await _healthyGamerPortalDbContext.SaveChangesAsync();

                return(true);
            }
            return(false);
        }
        public async Task <IActionResult> Edit(EditNewsItemViewModel model)
        {
            if (ModelState.IsValid)
            {
                var api = RestService.For <IHealthyGamerPortalNewsApi>(new HttpClient(new Helpers.AuthenticatedHttpClientHandler())
                {
                    BaseAddress = new Uri(BaseUrl)
                });
                var response = await api.EditSingleNews(model);

                if (response.Result)
                {
                }
            }
            return(PartialView("_Edit", model));
        }
예제 #3
0
        internal void AdminEditNewsItem(int id, EditNewsItemViewModel model)
        {
            news newsItem = _dbContext.news.Find(id);

            if (model.Title != null)
            {
                newsItem.title = model.Title;
            }

            if (model.Body != null)
            {
                newsItem.body = model.Body;
            }

            if (model.ImageFilePath != null)
            {
                newsItem.image = model.ImageFilePath;
            }

            newsItem.active = model.Active;

            Save();
        }
        public async Task <IActionResult> EditSingleNews([FromBody] EditNewsItemViewModel model)
        {
            var result = await _INewsService.EditSingleNews(model);

            return(Ok(GenerateSuccessfulResponse(result)));
        }