Example #1
0
        public async Task <ActionResult> AddPart(StoryPartModel part)
        {
            var user = System.Web.HttpContext.Current.GetOwinContext()
                       .GetUserManager <ApplicationUserManager>()
                       .FindById(System.Web.HttpContext.Current.User.Identity.GetUserId());

            if (ModelState.IsValid)
            {
                try
                {
                    var sp = new StoryPartViewModel
                    {
                        PartId          = Guid.NewGuid(),
                        CreatedDateTime = DateTime.Now,
                        PartText        = part.PartText,
                        Author          = user.UserName,
                        IsEnd           = part.IsEnd,
                        StoryId         = ViewBag.Id
                    };


                    await _storyOrchestrator.AddPart(sp);

                    if (part.IsEnd == false)
                    {
                        var nextAuthor = await _nextAuthorService.GetNextAuthor(user);

                        await _nextAuthorService.SetNextAuthor(part.StoryId, nextAuthor);
                    }
                    else
                    {
                        await _storyOrchestrator.FinishStory(part.StoryId);
                    }
                    return(View("~/Views/Home/Index.cshtml"));
                }
                catch (DataException dex)
                {
                    Console.WriteLine(dex);
                    ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
                }
            }

            return(View("AddPart"));
        }
Example #2
0
        public async Task <ActionResult> CreatePrompt(StoryPartModel prompt)
        {
            var user = System.Web.HttpContext.Current.GetOwinContext()
                       .GetUserManager <ApplicationUserManager>()
                       .FindById(System.Web.HttpContext.Current.User.Identity.GetUserId());

            if (ModelState.IsValid)
            {
                try
                {
                    var part = new StoryPartViewModel
                    {
                        PartId          = Guid.NewGuid(),
                        CreatedDateTime = DateTime.Now,
                        PartText        = prompt.PartText,
                        Author          = user.UserName,
                        IsEnd           = false,
                        StoryId         = Guid.NewGuid(),
                        StoryName       = prompt.StoryName
                    };

                    await _storyOrchestrator.CreatePrompt(part);

                    var nextAuthor = await _nextAuthorService.GetNextAuthor(user);

                    await _nextAuthorService.SetNextAuthor(part.StoryId, nextAuthor);

                    System.Web.HttpContext.Current.Response.Write("<script>alert('Prompt created successfully!')</script>");
                    ModelState.Clear();
                    return(View("CreatePrompt"));
                }
                catch (DataException dex)
                {
                    Console.WriteLine(dex);
                    ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
                }
            }
            return(View("CreatePrompt"));
        }