예제 #1
0
        public async Task <IActionResult> SaveInteraction(string interactionid, string commentarytext)
        {
            var UserLogged = await _userServices.GetByIdAsync(User.FindFirstValue(ClaimTypes.NameIdentifier));

            var Interaction = await _context.Interactions
                              .Include(x => x.Comentaries)
                              .FirstAsync(x => x.Id == interactionid);

            var subInt = new SubInteractionDataModel();
            var newInt = new InteractionDataModel
            {
                Likes       = new List <LikesDataModel>(),
                Comentaries = new List <ComentaryDataModel>()
            };

            subInt.Interaction = newInt;

            ComentaryDataModel NewCommentarie = new ComentaryDataModel
            {
                Text           = commentarytext,
                User           = UserLogged,
                SubInteraction = subInt
            };

            Interaction.Comentaries.Add(NewCommentarie);

            await _context.SaveChangesAsync();

            return(Json(new { CommentarieId = NewCommentarie.Id, UserId = UserLogged.Id, UserName = UserLogged.UserName, Text = NewCommentarie.Text }));
        }
예제 #2
0
        public IActionResult UserStoryChapterSectionsCreateEdit(string storyId, StoryChapters Chapter, List <SectionModel> Sections)
        {
            var DBStorys        = _context.Storys.Include(x => x.User);
            var DBStorysChapter = _context.Storys.Include(x => x.Chapters);

            var Story = DBStorysChapter.Where(x => x.User.Id == User.FindFirstValue(ClaimTypes.NameIdentifier) && x.Id == storyId).First();

            var NextSeq = 0;

            if (Story.Chapters.Count > 1)
            {
                NextSeq = Story.Chapters.Last().Seq + 1;
            }

            if (Chapter.Id == "novo")
            {
                if (Story.Chapters == null)
                {
                    Story.Chapters = new List <ChapterDataModel>();
                }

                var NewInteraction = new InteractionDataModel();
                NewInteraction.Likes       = new List <LikesDataModel>();
                NewInteraction.Comentaries = new List <ComentaryDataModel>();

                Story.Chapters.Add(new ChapterDataModel
                {
                    Seq           = NextSeq,
                    Title         = Chapter.Title,
                    Description   = Chapter.Description,
                    Published     = Chapter.Published,
                    DtLastPublish = Chapter.Published ? DateTime.Now : new DateTime(),
                    Sections      = UpdateSections(Sections),
                    Interaction   = NewInteraction
                });
            }
            else
            {
                var DBStoryChapter = _context.Chapters.Include(x => x.Sections);
                var StoryChapter   = DBStoryChapter.Where(x => x.Id == Chapter.Id).First();

                StoryChapter.Seq         = Chapter.Seq;
                StoryChapter.Title       = Chapter.Title;
                StoryChapter.Description = Chapter.Description;
                StoryChapter.Sections.Clear();
                StoryChapter.Sections = UpdateSections(Sections);
                if (Chapter.Published != StoryChapter.Published)
                {
                    StoryChapter.Published     = Chapter.Published;
                    StoryChapter.DtLastPublish = DateTime.Now;
                }
            }

            _context.SaveChanges();

            return(Json(new { ChapterId = Story.Chapters.Where(x => x.Seq == Chapter.Seq).First().Id, SectionsSaved = Sections }));
        }
예제 #3
0
        public IActionResult UserStoryCreateEdit(StoryModel Story)
        {
            if (ModelState.IsValid)
            {
                if (Story.Id != null)
                {
                    var DBStorys = _context.Storys.Include(x => x.User);

                    foreach (var DBStory in DBStorys.Where(x => x.User.Id == User.FindFirstValue(ClaimTypes.NameIdentifier) && x.Id == Story.Id))
                    {
                        DBStory.Title       = Story.Title;
                        DBStory.Description = Story.Description;
                        DBStory.Gender      = Story.Gender;
                        if (Story.Published != DBStory.Published)
                        {
                            DBStory.Published     = Story.Published;
                            DBStory.DtLastPublish = DateTime.Now;
                        }
                    }
                }
                else
                {
                    var NewInteraction = new InteractionDataModel();
                    NewInteraction.Likes       = new List <LikesDataModel>();
                    NewInteraction.Comentaries = new List <ComentaryDataModel>();

                    _context.Storys.Add(new StoryDataModel
                    {
                        Title         = Story.Title,
                        Description   = Story.Description,
                        Gender        = Story.Gender,
                        User          = _userManager.FindByIdAsync(User.FindFirstValue(ClaimTypes.NameIdentifier)).Result,
                        Published     = Story.Published,
                        DtLastPublish = Story.Published ? DateTime.Now : new DateTime(),
                        DtCreation    = DateTime.Now,
                        Interaction   = NewInteraction
                    });
                }

                _context.SaveChanges();

                return(RedirectToAction("UserStorys"));
            }

            return(View());
        }