Beispiel #1
0
        public async Task <IActionResult> Edit(EditPostViewModel model)
        {
            FormSubmit submitInfo = new FormSubmit
            {
                IndexUrl = Url.Action(nameof(Index), "Post")
            };

            if (ModelState.IsValid)
            {
                Post post = await _post.GetPostAsync(model.Id);

                post.Title               = model.Title;
                post.Content             = model.Content;
                post.RowModifiedBy       = Convert.ToInt32(_userManager.GetUserId(User));
                post.RowModifiedDateTime = DateTime.Now;

                Result result = new Result(false, "Unable to edit post at this time.");

                try
                {
                    await _post.EditPostAsync(post);

                    result.Succeeded = true;
                    result.Message   = "Post edited.";
                }
                catch (Exception ex)
                {
                    SysException exception = new SysException(ex)
                    {
                        Url = UrlHelper.GetRequestUrl(HttpContext)
                    };
                }

                submitInfo.Result = result;
            }

            ViewData[Constants.FormSubmit] = submitInfo;

            return(View(model));
        }