コード例 #1
0
        public ActionResult <VlogDetailsViewModel> Details(int id, TranslationLanguage?language = null)
        {
            var vm = this.manager.GetQueryById(id)
                     .Select(VlogDetailsViewModel.FromEntity(language ?? base.AppSettings.DefaultLanguage))
                     .FirstOrDefault();

            return(vm);
        }
コード例 #2
0
        public ActionResult <ISearchResultModel <VlogDetailsViewModel> > Index(ISearchVlogModel search)
        {
            var result = this.manager.SearchVlogs(search);
            var vm     = new SearchResultModel <VlogDetailsViewModel>()
            {
                List       = result.List.Select(VlogDetailsViewModel.FromEntity(search.Language ?? base.AppSettings.DefaultLanguage)),
                Page       = result.Page,
                PageCount  = result.PageCount,
                PageSize   = result.PageSize,
                TotalCount = result.TotalCount
            };

            return(vm);
        }
コード例 #3
0
        public async Task <ActionResult <OkObjectViewModel <VlogDetailsViewModel> > > Update(UpdateVlogViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(new BadRequestObjectResult(new BadRequestViewModel <ModelStateError>(ModelState.GetErrors())));
            }

            var result = await this.manager.UpdateVlogAsync(model);

            if (!result.Succeeded)
            {
                AddManagerErrorsToModelState(result.Errors);
                return(new BadRequestObjectResult(new BadRequestViewModel <ModelStateError>(ModelState.GetErrors())));
            }

            var vm = this.manager.GetQueryById(result.Model.Id)
                     .Select(VlogDetailsViewModel.FromEntity(AppSettings.DefaultLanguage))
                     .FirstOrDefault();

            base.Response.StatusCode = (int)HttpStatusCode.Created;
            return(new OkObjectViewModel <VlogDetailsViewModel>("Success", vm));
        }