Пример #1
0
        public JsonResult DeleteStory(int storyId)
        {
            var story = _storyService.GetById(storyId);

            _storyService.Delete(story);

            var questions = _questionService.GetByStoryId(storyId);

            _questionService.DeleteRange(questions);
            return(Json("1"));
        }
Пример #2
0
        public ActionResult Delete(string id)
        {
            id = id.NullSafe();

            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(id), "Identyfikator artyku³u nie mo¿e byæ pusty."),
                new Validation(() => id.ToGuid().IsEmpty(), "Niepoprawny identyfikator artyku³u."),
                new Validation(() => !IsCurrentUserAuthenticated, "Nie jesteœ zalogowany."),
                new Validation(() => !CurrentUser.CanModerate(), "Nie masz praw do wo³ania tej metody.")
                );

            if (viewData == null)
            {
                try
                {
                    using (IUnitOfWork unitOfWork = UnitOfWork.Get())
                    {
                        IStory story = _storyRepository.FindById(id.ToGuid());

                        if (story == null)
                        {
                            viewData = new JsonViewData {
                                errorMessage = "Podany artyku³ nie istnieje."
                            };
                        }
                        else
                        {
                            _storyService.Delete(story, CurrentUser);
                            unitOfWork.Commit();

                            viewData = new JsonViewData {
                                isSuccessful = true
                            };
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("usuwania artyku³u")
                    };
                }
            }

            return(Json(viewData));
        }
Пример #3
0
        public async Task <IActionResult> Delete(int id)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index", "Board"));
            }

            bool succesful = await StoryService.Delete(id);

            if (!succesful)
            {
                return(BadRequest("Could not remove story"));
            }

            return(RedirectToAction("Board", "Board"));
        }
Пример #4
0
        public ActionResult Delete(string id)
        {
            id = id.NullSafe();

            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(id), "Story identifier cannot be blank."),
                new Validation(() => id.ToGuid().IsEmpty(), "Invalid story identifier."),
                new Validation(() => !IsCurrentUserAuthenticated, "You are currently not authenticated."),
                new Validation(() => !CurrentUser.CanModerate(), "You do not have the privilege to call this method.")
                );

            if (viewData == null)
            {
                try
                {
                    IStory story = _storyRepository.FindById(id.ToGuid());

                    if (story == null)
                    {
                        viewData = new JsonViewData {
                            errorMessage = "Specified story does not exist."
                        };
                    }
                    else
                    {
                        _storyService.Delete(story, CurrentUser);

                        viewData = new JsonViewData {
                            isSuccessful = true
                        };
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("deleting story")
                    };
                }
            }

            return(Json(viewData));
        }