public GroupUserLink Create(GroupUserLink newGroupUserLink)
        {
            using (var context = new GFDbContext())
            {
                context.GroupUserLinks.Add(newGroupUserLink);
                context.SaveChanges();

                return(newGroupUserLink);
            }
        }
        public GroupUserLink Update(GroupUserLink updatedGroupUserLink)
        {
            using (var context = new GFDbContext())
            {
                var existingGroupUserLink = GetById(updatedGroupUserLink.Id);
                context.Entry(existingGroupUserLink).CurrentValues.SetValues(updatedGroupUserLink);
                context.SaveChanges();

                return(existingGroupUserLink);
            }
        }
Ejemplo n.º 3
0
        public IActionResult CreateGroup(CreateGroupViewModel vm)
        {
            Group     newGroup = vm.Group;
            IFormFile image    = vm.Image;

            //upload image.
            if (image != null && image.Length > 0)
            {
                string storageFolder = Path.Combine(_environment.WebRootPath, "images/groups");

                string newImageName = $"{Guid.NewGuid().ToString()}{Path.GetExtension(image.FileName)}";

                string fullPath = Path.Combine(storageFolder, newImageName);

                using (var stream = new FileStream(fullPath, FileMode.Create))
                {
                    image.CopyTo(stream);
                }

                //Image is successfully uploaded.
                //append new image location to new home.
                newGroup.ImageURL = $"/images/groups/{newImageName}";
            }

            // save newGroup
            _groupService.Create(newGroup);

            GroupUserLink newGroupUserLink = new GroupUserLink
            {
                GroupId     = newGroup.Id,
                UserId      = _userManager.GetUserId(User),
                IsUserAdmin = true
            };

            _groupUserLinkService.Create(newGroupUserLink);

            return(RedirectToAction("grouplist"));
        }