예제 #1
0
        public async Task <int> CreateAsync(int profileId, CreateGroupInputModel input, string path)
        {
            var group = new Group()
            {
                Name        = input.Name,
                Description = input.Description,
            };

            if (input.Image?.Length > 0)
            {
                group.ImageId = await this.imagesService.CreateAsync(input.Image, path);
            }

            await this.groupsRepository.AddAsync(group);

            await this.groupsRepository.SaveChangesAsync();

            var groupMember = new GroupMember()
            {
                MemberId = profileId,
                GroupId  = group.Id,
                Role     = GroupRole.Owner,
            };

            await this.groupMembersRepository.AddAsync(groupMember);

            await this.groupMembersRepository.SaveChangesAsync();

            return(group.Id);
        }
예제 #2
0
        public IActionResult CreateGroup()
        {
            CreateGroupInputModel viewModel = new CreateGroupInputModel {
                MultiSelectUsers = this.groupsService.ListAllUsers()
            };

            return(this.View(viewModel));
        }
예제 #3
0
        public IActionResult CreateGroup(CreateGroupInputModel inputModel)
        {
            if (!ModelState.IsValid)
            {
                inputModel.MultiSelectUsers = this.groupsService.ListAllUsers();
                return(this.View(inputModel));
            }

            inputModel.OwnerId = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            this.groupsService.CreateGroup(inputModel);

            return(this.Redirect("List"));
        }
예제 #4
0
        public async Task CreateAsyncAddsItemCrorreclty()
        {
            var input = new CreateGroupInputModel()
            {
                Description = "test",
                Name        = "test",
                Image       = null,
            };

            await this.groupsService.CreateAsync(1, input, "test");

            Assert.Equal(1, await this.groupsRepository.All().CountAsync());
        }
예제 #5
0
        public async Task <IActionResult> Create(CreateGroupInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            var userid    = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            var profileId = this.profilesService.GetId(userid);

            var groupId = await this.groupsService.CreateAsync(profileId, input, $"{this.webHost.WebRootPath}/img/groups");

            return(this.RedirectToAction(nameof(this.ById), new { id = groupId }));
        }
예제 #6
0
        public async Task <IActionResult> CreateGroup(CreateGroupInputModel model)
        {
            var userId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value;

            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }


            await this.groupService.CreateGroupAsync(model, userId);

            return(this.RedirectToAction("All"));
        }
예제 #7
0
        public async Task CreateAsyncAddsItemCrorrecltyWithImage()
        {
            var imageMock = new Mock <IFormFile>();

            imageMock.Setup(x => x.Length).Returns(1);
            var input = new CreateGroupInputModel()
            {
                Description = "test",
                Name        = "test",
                Image       = imageMock.Object,
            };

            await this.groupsService.CreateAsync(1, input, "test");

            Assert.Equal(1, await this.groupsRepository.All().CountAsync());
        }
예제 #8
0
        public async Task CreateGroupAsync(CreateGroupInputModel model, string userId)
        {
            var user = await this.userManager.FindByIdAsync(userId);

            var newGroup = new Group
            {
                Admin       = user,
                Name        = model.Name,
                Description = model.Description,
                Picture     = model.Picture,
            };

            await this.groupRepo.AddAsync(newGroup);

            await this.groupRepo.SaveChangesAsync();
        }
예제 #9
0
        public void CreateGroup(CreateGroupInputModel inputModel)
        {
            Group group = new Group
            {
                Name      = inputModel.Name,
                CreatedOn = DateTime.UtcNow,
                OwnerId   = inputModel.OwnerId,
            };

            List <GroupUser> groupUsers = inputModel
                                          .SelectedUsers
                                          .Select(u => new GroupUser
            {
                UserId = this.userManager.Users.FirstOrDefault(x => x.Email == u).Id,
            })
                                          .ToList();

            group.Users = groupUsers;

            this.context.Groups.Add(group);
            this.context.SaveChanges();
        }
예제 #10
0
        public IActionResult Create()
        {
            var viewModel = new CreateGroupInputModel();

            return(this.View(viewModel));
        }