Пример #1
0
        public async Task <IActionResult> OnPost(long?id)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    bool isNew = !id.HasValue;
                    Repository.Models.Post post = isNew ? new Repository.Models.Post
                    {
                        AddedDate = DateTime.UtcNow
                    } : await postService.Get(id.Value);

                    post.Title        = createEditPostViewModel.Title;
                    post.Content      = createEditPostViewModel.Content;
                    post.CategoryId   = createEditPostViewModel.CategoryId;
                    post.IPAddress    = Request.HttpContext.Connection.RemoteIpAddress.ToString();
                    post.ModifiedDate = DateTime.UtcNow;
                    if (isNew)
                    {
                        await postService.Insert(post);
                    }
                    else
                    {
                        await postService.Update(post);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(RedirectToPage("Index"));
        }
Пример #2
0
 public async Task OnGet(long id)
 {
     post = await postService.Get(id);
 }