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); }
public IActionResult CreateGroup() { CreateGroupInputModel viewModel = new CreateGroupInputModel { MultiSelectUsers = this.groupsService.ListAllUsers() }; return(this.View(viewModel)); }
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")); }
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()); }
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 })); }
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")); }
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()); }
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(); }
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(); }
public IActionResult Create() { var viewModel = new CreateGroupInputModel(); return(this.View(viewModel)); }