예제 #1
0
        public async Task <ActionResult <EditStaticPageDto> > Edit(int Id, CancellationToken cancellationToken)
        {
            try
            {
                var page = await _staticPageService.GetByIdAsync(cancellationToken, Id);

                EditStaticPageDto model = new EditStaticPageDto
                {
                    PageTitle      = page.PageTitle,
                    Caption        = page.Caption,
                    Url            = page.Url,
                    Content        = page.Content,
                    DescriptionSeo = page.DescriptionSeo,
                    IsActive       = page.IsActive,
                    Id             = page.Id,
                    Keywords       = page.Keywords,
                };

                return(View(model));
            }
            catch (Exception e)
            {
                ErrorNotification(OperationMessage.OperationFailed.ToDisplay(), true);
                return(RedirectToAction("Error", "Home"));
            }
        }
예제 #2
0
        public async Task <IActionResult> Edit(int Id, EditStaticPageDto ModelDto, CancellationToken cancellationToken)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    AddNotification(NotifyType.Warning, OperationMessage.ModelStateIsNotValid.ToDisplay(), true);
                    return(View(ModelDto));
                }
                var model = await _staticPageService.GetByIdAsync(cancellationToken, Id);

                if (model != null)
                {
                    model.PageTitle      = ModelDto.PageTitle;
                    model.Caption        = ModelDto.Caption;
                    model.Url            = ModelDto.Url;
                    model.Content        = ModelDto.Content;
                    model.DescriptionSeo = ModelDto.DescriptionSeo;
                    model.IsActive       = ModelDto.IsActive;
                    model.Keywords       = ModelDto.Keywords;
                    await _staticPageService.UpdateAsync(model, cancellationToken);

                    AddNotification(NotifyType.Success, OperationMessage.OperationSucceed.ToDisplay(), true);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    AddNotification(NotifyType.Success, OperationMessage.ModelStateIsNotValid.ToDisplay(), true);
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                ErrorNotification(OperationMessage.OperationFailed.ToDisplay(), true);
                return(RedirectToAction("Error", "Home"));
            }
        }