Exemplo n.º 1
0
        public async Task <IActionResult> NewPost(CreatePostCommand command)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.ShowMessage = true;
                ViewBag.Message     = "Something went wrong";
                return(View());
            }

            try
            {
                CreatePostValidation.CommandValidation(command);

                var admin = await _adminService.GetAdminAsync();

                await _postService.AddPostAsync(command, admin);

                ViewBag.Added = true;
                return(View());
            }
            catch (InternalSystemException ex)
            {
                ViewBag.ShowMessage = true;
                ViewBag.Message     = ex.Message;
                return(View());
            }
            catch (Exception)
            {
                ViewBag.ShowMessage = true;
                ViewBag.Message     = "Something went wrong!";
                return(View());
            }
        }
Exemplo n.º 2
0
 public EfCreatePostsCommand(ProjekatContext context, CreatePostValidation validator)
 {
     _context   = context;
     _validator = validator;
 }