Beispiel #1
0
        public async Task <ActionResult> Create([FromForm] StoryViewModel model)
        {
            try
            {
                var result = await storyService.CreateAsync(model);

                return(Ok(new
                {
                    data = new
                    {
                        title = "Success",
                        Msg = "Create success!"
                    },
                    Success = true
                }));
            }
            catch
            {
                return(BadRequest(new
                {
                    data = new
                    {
                        title = "Error",
                        Msg = "Fail to create!"
                    },
                    Success = false
                }));
            }
        }
        public async Task <IActionResult> Create(CreateStoryInputModel model)
        {
            try
            {
                if (this.ModelState.IsValid)
                {
                    string storyId = await storyService.CreateAsync(model.Title, CurrentUser);

                    if (string.IsNullOrEmpty(storyId))
                    {
                        AddDangerNotification(string.Format(Notifications.CreatedFail, model.Title));
                        return(Redirect("/Stories"));
                    }

                    logger.LogInformation(
                        string.Format(SetLog.CreatedSuccess,
                                      CurrentUser.UserName,
                                      CurrentController,
                                      storyId
                                      ));

                    AddWarningNotification(string.Format(Notifications.CreatedSuccess, model.Title));
                    return(Redirect($"/Stories/Update/{storyId}"));
                }
                else
                {
                    logger.LogInformation(string.Format(SetLog.CreatedFail,
                                                        CurrentUser.UserName,
                                                        CurrentController));

                    AddDangerNotification(string.Format(Notifications.CreatedFail, model.Title));
                    return(View(model));
                }
            }
            catch (System.Exception e)
            {
                logger.LogError(string.Format(SetLog.Error,
                                              CurrentUser.UserName,
                                              CurrentController,
                                              e.Message));

                AddDangerNotification(string.Format(Notifications.Fail));

                return(Redirect("/Stories"));
            }
        }