Example #1
0
        public async Task <IActionResult> CreatePost(CreateSquirrelViewModel viewModel)
        {
            var userId      = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var currentUser = await _userManager.FindByIdAsync(userId);

            Squirrel squirrel = new Squirrel()
            {
                Name          = viewModel.Name,
                Image         = viewModel.Image,
                PartyTrick    = viewModel.PartyTrick,
                PartyStory    = viewModel.PartyStory,
                PartyLocation = viewModel.PartyLocation,
                PartySince    = viewModel.PartySince,
                Creator       = userId
            };

            _db.Squirrels.Add(squirrel);

            _db.SquirrelUser.Add(new SquirrelUser()
            {
                SquirrelId = squirrel.SquirrelId, UserId = userId, Squirrel = squirrel, User = currentUser
            });
            _db.SaveChanges();
            return(RedirectToAction("Details", "Parties", new { id = userId }));
        }
Example #2
0
        public async Task <IActionResult> Create(CreatePartyMessageViewModel viewModel)
        {
            var userTo = await _userManager.FindByIdAsync(viewModel.UserId);

            var userFrom = await _userManager.FindByIdAsync(viewModel.UserFromId);

            PartyMessage newMessage = new PartyMessage();

            newMessage.UserId      = viewModel.UserId;
            newMessage.User        = userTo;
            newMessage.UserFromId  = viewModel.UserFromId;
            newMessage.UserFrom    = userFrom;
            newMessage.MessageBody = viewModel.MessageBody;
            _db.PartyMessages.Add(newMessage);
            _db.SaveChanges();
            return(RedirectToAction("Details", "Parties", new { id = viewModel.UserId }));
        }