Exemple #1
0
        public async Task <IActionResult> CreateGroupAsync([FromBody] GroupCreateRequest request)
        {
            var course = await courseService.GetCourseByIdAsync(request.CourseId);

            if (course == null)
            {
                throw new BadRequestException("Course doesn't exist");
            }
            if (!await User.IsUniversityTeacherOrHigherAsync(course.UniversityId, universityService))
            {
                throw new ForbiddenException("Don't have rights to create a group for this course!");
            }

            var dto = new CreateGroupDTO
            {
                CourseId     = request.CourseId,
                TeacherEmail = request.TeacherEmail,
                Name         = request.GroupName
            };
            int id = await groupService.AddGroupAsync(dto);

            return(Ok(new
            {
                id
            }));
        }
Exemple #2
0
        public IHttpActionResult CreateGroup([FromBody] CreateGroupDTO groupDTO)
        {
            var group = new GroupEntity()
            {
                GroupId   = groupDTO.GroupId,
                GroupName = groupDTO.GroupName,
                SportId   = groupDTO.SportId,
                SchoolId  = groupDTO.SchoolId
            };

            groupService.Create(group);
            return(Ok());
        }
Exemple #3
0
        public IActionResult Create([FromForm] CreateGroupDTO groupData)        //FromBody nie działa z jakiegos powodu
        {
            if (!ModelState.IsValid)
            {
                return(StatusCode(422, ModelState));
            }
            var result = _groupService.CreateGroup(groupData);

            if (result.IsError)
            {
                return(StatusCode(422, result.Errors));
            }
            return(Ok(result.SuccessResult));
        }
        public async Task <IActionResult> CreateGroup()
        {
            Log.Called(nameof(CreateGroup), UserInfoManager.UserId.ToString());

            if (!(UserInfoManager.UserId != Constants.NO_ID && UserInfoManager.CanUserAccessPage(UserInfoManager.UserId)))
            {
                return(RedirectToAction("AccessError", "Home"));
            }

            var dto = new CreateGroupDTO
            {
                Colors = await _colorFacade.GetColorsAsync <ColorDTO>()
            };

            return(View(dto));
        }
Exemple #5
0
        public ServiceResult <int> CreateGroup(CreateGroupDTO groupData)
        {
            var newGroup = _mapper.Map <Group>(groupData);

            _groupRepository.Insert(newGroup);
            if (groupData.GroupImage != null)
            {
                var result = _imageService.SaveImages(newGroup.Id, groupData.GroupImage, "Groups");
                if (result.IsError)
                {
                    return(new ServiceResult <int>(result.Errors));
                }
                var paths = result.SuccessResult;
                _mapper.Map(paths, newGroup);
                _groupRepository.Update(newGroup);
            }
            return(new ServiceResult <int>(newGroup.Id));
        }
Exemple #6
0
        public async Task <IActionResult> Create(CreateGroupDTO model)
        {
            if (model.ParentId.HasValue)
            {
                var parentGroupExists = _formContext.Groups.Any(g => g.Id == model.ParentId);
                if (!parentGroupExists)
                {
                    return(BadRequest());
                }
            }

            var groupExists = _formContext.Groups.Any(g => g.GroupName == model.GroupName);

            if (groupExists)
            {
                ModelState.AddModelError("GroupName", "Group with given name already exists");
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var group = new Group()
            {
                GroupName   = model.GroupName,
                Description = model.Description,
                ParentId    = model.ParentId
            };

            try
            {
                await _formContext.Groups.AddAsync(group);

                await _formContext.SaveChangesAsync();

                return(Ok());
            }
            catch (Exception)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }
        public async Task <IActionResult> PostGroup([FromBody] CreateGroupDTO @group)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = Mapper.Map <Group>(group);

            _context.Group.Add(result);
            await _context.SaveChangesAsync();

            UserGroup ug = new UserGroup();

            ug.EmailAddress = group.EmailAddress;
            ug.GroupId      = result.GroupId;
            _context.UserGroup.Add(ug);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetGroup", result.GroupId, result));
        }
Exemple #8
0
        public async Task <int> AddGroupAsync(CreateGroupDTO dto)
        {
            Group existingGroup = (await groupRepository
                                   .Find(group => group.Name == dto.Name &&
                                         group.CourseMember.CourseId == dto.CourseId))
                                  .FirstOrDefault();

            if (existingGroup != null)
            {
                throw new BadRequestException("Group already exists!");
            }
            var teacher = await teacherRepository.GetByEmailAsync(dto.TeacherEmail);

            Group group = new Group
            {
                Name           = dto.Name,
                CourseMemberId = await courseRepository.GetCourseMemberIdAsync(dto.CourseId, teacher.UserId)
            };
            await groupRepository.AddAsync(group);

            await groupRepository.SaveChangesAsync();

            return(group.Id);
        }
Exemple #9
0
 /// <summary>
 /// Create a new group
 /// </summary>
 /// <remarks>
 /// Creates a new group with the caller as the group administrator. The caller
 /// is also initially a member of the group.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='createGroupDTO'>
 /// The initial settings of the group regarding group name and member rights
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <GroupDTO> CreateGroupAsync(this IGroups operations, CreateGroupDTO createGroupDTO = default(CreateGroupDTO), CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.CreateGroupWithHttpMessagesAsync(createGroupDTO, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Exemple #10
0
 /// <summary>
 /// Create a new group
 /// </summary>
 /// <remarks>
 /// Creates a new group with the caller as the group administrator. The caller
 /// is also initially a member of the group.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='createGroupDTO'>
 /// The initial settings of the group regarding group name and member rights
 /// </param>
 public static GroupDTO CreateGroup(this IGroups operations, CreateGroupDTO createGroupDTO = default(CreateGroupDTO))
 {
     return(operations.CreateGroupAsync(createGroupDTO).GetAwaiter().GetResult());
 }