Esempio n. 1
0
        public async Task <IActionResult> Add(AddPostViewModel model)
        {
            FormSubmit submitInfo = new FormSubmit
            {
                IndexUrl = Url.Action(nameof(Index), "Post")
            };

            if (ModelState.IsValid)
            {
                Post post = new Post
                {
                    BlogId              = _appSettings.BlogID,
                    Title               = model.Title,
                    Content             = model.Content,
                    RowCreatedBy        = Convert.ToInt32(_userManager.GetUserId(User)),
                    RowModifiedBy       = Convert.ToInt32(_userManager.GetUserId(User)),
                    RowCreatedDateTime  = DateTime.Now,
                    RowModifiedDateTime = DateTime.Now
                };

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

                try
                {
                    await _post.AddPostAsync(post);

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

                submitInfo.Result = result;
            }

            ViewData[Constants.FormSubmit] = submitInfo;

            return(View(model));
        }