public async Task <IActionResult> Update([FromBody] UpdatePageViewModel model)
        {
            var grain  = this._client.GetGrain <IManageContentGrain>(model.Id);
            var result = await grain.UpdatePage(model);

            return(Json(result));
        }
        Task IUpdateContentRepository.UpdatePage(UpdatePageViewModel model, string entityId, string userId)
        {
            var foundActivePage =
                _context.Set <Page>().FirstOrDefault(x => x.IsActiveVersion && x.EntityId == entityId);

            if (foundActivePage == null)
            {
                return(Task.FromException(new Exception("Page to update not found.")));
            }

            foundActivePage.IsActiveVersion = false;
            foundActivePage.Modified        = DateTime.Now;
            _context.Update(foundActivePage);
            _context.SaveChanges();

            var newPage = foundActivePage;

            newPage.Id = Guid.NewGuid().ToString();
            newPage.IsActiveVersion = true;
            newPage.Name            = model.Name;
            newPage.Version         = GetNextVersion <Page>(foundActivePage.EntityId);
            newPage.Content         = model.Content;
            newPage.FeedEnabled     = model.FeedEnabled;
            _context.Add(newPage);

            return(_context.SaveChangesAsync());
        }
        public IActionResult UpdatePage(UpdatePageViewModel model)
        {
            if (!ModelState.IsValid)
            {
                Page page = new Page
                {
                    Title       = model.Title,
                    Description = model.Description,
                    Id          = model.Id,
                    Text        = model.Text,
                    Type        = model.Type
                };
                ViewData["GeneralError"] = Messages.RequiredInput;
                return(View(page));
            }
            var data = _pageService.GetById(model.Id);

            if (data.Data != null)
            {
                string oldImage = data.Data.Image;

                data.Data.Title       = model.Title;
                data.Data.Description = model.Description;
                data.Data.Text        = model.Text;
                data.Data.Type        = model.Type;

                if (model.File != null)
                {
                    var source = _galleryService.UploadGalleryImage(model.File, ImageSavePaths.PageSavePath);
                    if (source.Success)
                    {
                        data.Data.Image = source.Data;
                        var result = _pageService.UpdateWithImage(data.Data, oldImage);

                        if (result.Success)
                        {
                            ViewData["GeneralSuccess"] = result.Message;
                            return(RedirectToAction("ListPage", "ManagementPanel"));
                        }
                    }
                }
                else
                {
                    var result = _pageService.Update(data.Data);
                    if (result.Success)
                    {
                        ViewData["GeneralSuccess"] = result.Message;
                        return(RedirectToAction("ListPage", "ManagementPanel"));
                    }
                }
            }


            ViewData["GeneralError"] = Messages.GeneralError;
            return(RedirectToAction("ListPage", "ManagementPanel"));
        }
        public async Task <string> UpdatePage(UpdatePageViewModel model)
        {
            var page = await _context.Set <Page>().FindAsync(model.Id);

            page.FeedEnabled = model.FeedEnabled;
            page.Name        = model.Name;

            var result = _context.Update(page);
            await _context.SaveChangesAsync();

            return(result.Id);
        }
        public async Task <GrainOperationResult> UpdatePage(UpdatePageViewModel model, string entityId)
        {
            try
            {
                await _repository.UpdatePage(model, entityId, GrainUserId);

                return(new GrainOperationResult {
                    Successful = true, Message = "Operation executed successfully."
                });
            }
            catch (Exception ex)
            {
                return(ex.ResultFromException());
            }
        }
示例#6
0
        public async Task OnGetAsync()
        {
            var dto = await pageAdminAppService.GetAsync(Id);

            ViewModel = ObjectMapper.Map <PageDto, UpdatePageViewModel>(dto);
        }
 public async Task <string> UpdatePage(UpdatePageViewModel model)
 {
     return(await _updateRepository.UpdatePage(model));
 }
 public UpdatePage()
 {
     InitializeComponent();
     BindingContext = new UpdatePageViewModel();
 }