public async Task CreateGroupController_GroupNotExist_ReturnsConflict() { // Arrange var controller = new GroupsController(new GroupRepositoryStub(), new UserRepositoryStub(), new SmartLockRepositoryStub(), new AzureAdRepositoryStub(), _mapper); var groupCreationDto = new GroupCreationDto { Id = Guid.Parse("c374cb18-862e-4fef-871f-ae08337d1f76"), Status = Status.Active, SmartLockGroups = new List <SmartLockCollectionDto> { new SmartLockCollectionDto { SmartLockId = Guid.Parse("3fa85f64-5717-4562-b3fc-2c963f66afa6") } } }; // Act var result = await controller.CreateGroup(groupCreationDto); // Assert Assert.IsInstanceOfType(result.Result, typeof(ConflictObjectResult)); }
public ActionResult CreateGroup(GroupCreationDto newGroup, int userId) { UserDto currentUser = (UserDto)Session["session"]; newGroup.CreatorId = currentUser.Id; groupService.AddNewGroup(newGroup); return(RedirectToAction("GroupsList", new { userId = userId })); }
public Group GetNewGroup(GroupCreationDto creatingDto) { Group group = new Group(); group.Title = creatingDto.Title; GroupType type = dbContext.GroupTypes.Where(r => r.Title == creatingDto.Type.ToString()).First(); group.GroupTypeId = type.Id; return(group); }
public async Task <ActionResult <GroupDto> > CreateGroup([FromBody] GroupCreationDto group) { try { await _azureAdRepository.GetGroup(group.Id.ToString()); } catch (ServiceException e) { if (e.StatusCode == HttpStatusCode.NotFound) { ModelState.AddModelError("azureAdGroupNotFound", $"Group with id: {group.Id} was not found on Azure AD"); } } var groupExists = await _groupRepository.GroupExists(group.Id); if (groupExists) { return(Conflict("Group already exists")); } if (group.SmartLockGroups.Count > 0) { foreach (var smartLockGroup in group.SmartLockGroups) { var smartLockExist = await _smartLockRepository.SmartLockExists(smartLockGroup.SmartLockId); if (!smartLockExist) { ModelState.AddModelError("smartLockNotExist", $"Smart lock with id: {smartLockGroup.SmartLockId} doesn't exist"); } } } if (!ModelState.IsValid) { return(ValidationProblem(ModelState)); } var groupEntity = _mapper.Map <Group>(group); _groupRepository.AddGroup(groupEntity); await _groupRepository.Save(); var groupDto = _mapper.Map <GroupDto>(groupEntity); return(CreatedAtAction("GetGroup", new { groupId = groupDto.Id }, groupDto)); }
public IActionResult Post([FromBody] GroupCreationDto groupCreationDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var group = _mapper.Map <Group>(groupCreationDto); if (!_groupService.Add(group)) { return(BadRequest("Group already exists")); } var createdGroup = _mapper.Map <Group>(group); _groupService.Save(); return(CreatedAtRoute("GetGroup", new { createdGroup.Id })); }
public void AddNewGroup(GroupCreationDto newGroup) { Group group = groupMapper.GetNewGroup(newGroup); groupManager.AddNewGroup(group, newGroup.CreatorId); }
public void GroupCreation(GroupCreationDto groupcreationDto) { Group group = mapper.FromGroupCreationDtoToGroup(groupcreationDto); groupManager.AddGroup(group); }