Exemplo n.º 1
0
        public async Task <ResultEntity> AddOrUpdateAsync(Group group)
        {
            var result = new ResultEntity();
            var exist  = await _groupRepository.GetQueryable().Where(a => a.Name == group.Name && a.Id != group.Id).CountAsync() > 0;

            if (exist)
            {
                result.Message = "分组名称已存在";
            }
            else
            {
                if (group.Id > 0)
                {
                    _groupRepository.Update(group);
                }
                else
                {
                    await _groupRepository.AddAsync(group);
                }

                result.Success = true;
            }

            return(result);
        }
Exemplo n.º 2
0
        public Task <Group> AddGroupAsync(CreateNewGroup newGroupData)
        {
            newGroupData.Validate();
            var group = newGroupData.ToGroup();

            return(groupRepository.AddAsync(group));
        }
Exemplo n.º 3
0
        public async Task CreateGroupAsync(CreateGroupDto group)
        {
            var superVisor = await _userManager.FindByIdAsync(group.SuperVisorId) as Teacher;

            var headMan = await _userManager.FindByIdAsync(group.HeadManId) as Student;

            var students = await InitializeStudents(group.StudentIds);

            Group groupToDb = new()
            {
                Name         = group.Name,
                Class        = group.Class,
                Courses      = null,
                SuperVisor   = superVisor,
                SuperVisorId = superVisor?.Id,
                Students     = students,
                HeadMan      = headMan,
                HeadManId    = headMan?.Id
            };

            await _groupRepository.AddAsync(groupToDb);

            await _groupRepository.UnitOfWork.SaveChangesAsync();

            var groupId = await GetGroupIdByName(group.Name);

            await UpdateStudentsAsync(groupId, students);
        }
 public async Task HandleAsync(GroupCreated @event)
 {
     await _handler
     .Run(async() =>
     {
         var group = await _groupServiceClient.GetAsync <Group>(@event.GroupId);
         group.Value.MembersCount = group.Value.Members?.Count ?? 0;
         await _groupRepository.AddAsync(group.Value);
         await _groupCache.AddAsync(group.Value);
         if (!group.Value.OrganizationId.HasValue)
         {
             return;
         }
         var organization = await _organizationRepository.GetAsync(group.Value.OrganizationId.Value);
         if (organization.Value.Groups == null)
         {
             organization.Value.Groups = new List <Guid>();
         }
         organization.Value.Groups.Add(@event.GroupId);
         organization.Value.GroupsCount = organization.Value.Groups.Count;
         await _organizationRepository.UpdateAsync(organization.Value);
         await _organizationCache.AddAsync(organization.Value);
     })
     .OnError((ex, logger) =>
     {
         logger.Error(ex, $"Error occured while handling {@event.GetType().Name} event");
     })
     .ExecuteAsync();
 }
Exemplo n.º 5
0
        public async Task Handle(AddGroupCommand command)
        {
            var commandInformation = command.GetCommandInformation();

            var group = new Group(command.NewGroupId, "Company", command.GroupName, command.OwnerUserId, GroupStatus.ACTIVE, null, null, commandInformation);

            await _groupRepository.AddAsync(group);
        }
Exemplo n.º 6
0
 public async Task <IActionResult> SaveGroup([FromBody] Group group)
 {
     try {
         return(Ok(await _groupRepository.AddAsync(_mapper.Map <Groups>(group))));
     } catch (Exception e) {
         return(BadRequest(e.Message));
     }
 }
Exemplo n.º 7
0
        public async Task <GroupDto> CreateGroupAsync(GroupDto newGroupDto)
        {
            var newGroup = _mapper.Map <Group>(newGroupDto);
            await _groups.AddAsync(newGroup);

            await _unitOfWork.CommitAsync();

            return(_mapper.Map <GroupDto>(newGroup));
        }
Exemplo n.º 8
0
        public async Task <GroupManageModel> AddAsync(GroupAddModel model)
        {
            _unitOfWork.BeginTransaction();
            var addedModel = await _repository.AddAsync(_mapper.Map <GroupModel>(model));

            var result = await _unitOfWork.CommitAsync();

            return(result > 0 ? _mapper.Map <GroupManageModel>(addedModel) : null);
        }
Exemplo n.º 9
0
        public async Task Add(GroupModel model)
        {
            var groupEntity = new GroupEntity
            {
                Id       = model.Id,
                Name     = model.Name,
                CourseId = model.CourseId
            };

            await _repository.AddAsync(groupEntity);
        }
Exemplo n.º 10
0
        public async Task <GroupDto> AddAsync(GroupDto groupDto)
        {
            var group  = _mapper.Map <GroupDto, Group>(groupDto);
            var result = await _groupRepository.AddAsync(group);

            if (result.Status == RepositoryStatus.Created)
            {
                var entity = result.Entity;
                return(_mapper.Map <Group, GroupDto>(entity));
            }
            throw new ServiceException(ErrorCodes.DatabaseError);
        }
Exemplo n.º 11
0
        public async Task <IResultModel> Add(GroupAddModel model)
        {
            var entity = _mapper.Map <GroupEntity>(model);
            //if (await _repository.Exists(entity))
            //{
            //return ResultModel.HasExists;
            //}

            var result = await _repository.AddAsync(entity);

            return(ResultModel.Result(result));
        }
        public async Task <IResultModel> Add(GroupAddModel model)
        {
            var entity = _mapper.Map <GroupEntity>(model);

            if (await _repository.Exists(entity))
            {
                return(ResultModel.Failed("编码已存在"));
            }

            var result = await _repository.AddAsync(entity);

            return(ResultModel.Result(result));
        }
Exemplo n.º 13
0
        public async Task AddAsync(Group group)
        {
            if (!(await faceAPIClient.GroupExistsAsync(group.Code)))
            {
                await faceAPIClient.GroupCreateAsync(group.Code, group.Name);

                await groupRepository.AddAsync(group);
            }
            else
            {
                throw new BusinessException($"Person group '{group.Code}' already exists.");
            }
        }
Exemplo n.º 14
0
        public async Task CreateIfNotFoundAsync(Guid id, string name, bool isPublic,
                                                string state, string userId, IDictionary <string, ISet <string> > criteria,
                                                Guid?organizationId = null)
        {
            var group = await _groupRepository.GetAsync(id);

            if (group.HasValue)
            {
                return;
            }
            Logger.Debug($"Creating a new group: '{id}', name: '{name}', public: '{isPublic}'.");
            group = new Group(id, name, isPublic, state, userId, criteria, organizationId);
            await _groupRepository.AddAsync(group.Value);
        }
Exemplo n.º 15
0
        public async Task AddAsync(Group group)
        {
            if (!(await faceAPIClient.GroupExistsAsync(group.Code)))
            {
                // ToDo: Call faceAPIClient.GroupCreateAsync() here...
                throw new System.NotImplementedException();

                await groupRepository.AddAsync(group);
            }
            else
            {
                throw new BusinessException($"Person group '{group.Code}' already exists.");
            }
        }
Exemplo n.º 16
0
        public async Task AddAsync(Group group)
        {
            // ToDo: Check if the group exists using GroupExistsAsync from faceAPIClient
            if (!(await faceAPIClient.GroupExistsAsync(group.Code)))
            {
                // ToDo: If the group do not exists, call faceAPIClient to create a group
                await faceAPIClient.GroupCreateAsync(group.Code, group.Name);

                // ToDo: If the group do not exists, call groupRepository to save the group details
                await groupRepository.AddAsync(group);
            }
            else
            {
                // ToDo: If the group already exists, throw a new BusinessException with the message "Person group '[CODE]' already exists."
                throw new BusinessException($"Person group '{group.Code}' already exists.");
            }
        }
Exemplo n.º 17
0
        public async Task <IActionResult> Save(int?id, string title, string slug, State state, IFormFile photo)
        {
            if (id == null)
            {
                //Todo:add
                var group = new Group
                {
                    CreateDate = DateTime.UtcNow,
                    Title      = title,
                    Slug       = slug.CheckStringIsNull()? null:slug,
                    Creator    = Operator,
                    State      = state,
                };
                await _repo.AddAsync(group);

                await _repo.SaveAsync();

                if (photo != null)
                {
                    var groupId = group.Id;

                    var ext  = Path.GetExtension(photo.FileName);
                    var path = Path.Combine(_env.WebRootPath + "\\Images\\Groups", groupId + ext);
                    using (var filestream = new FileStream(path, FileMode.Create))
                    {
                        await photo.CopyToAsync(filestream);
                    }
                }
                return(RedirectToAction("list"));
            }
            else
            {
                //Todo:edit
                var model = await _repo.GetGroupAsync(id.Value);

                model.Title          = title;
                model.State          = state;
                model.LastModifier   = Operator;
                model.LastModifyDate = DateTime.UtcNow;

                await _repo.Update(model);

                await _repo.SaveAsync();
            }
            return(View());
        }
Exemplo n.º 18
0
        public async Task HandleAsync(CreateGroupCommand command)
        {
            var groupId = GroupId.From(command.GroupId);

            if (await _groupRepository.ExistsAsync(groupId))
            {
                throw new GroupAlreadyExistsException(groupId);
            }

            var me = await _client.GetAsync <UserDto>("/identity/me", new MeQuery(command.UserId));

            var avatar = await GetAvatar(me.Avatar);

            var group = Domain.Entities.Group.Create(groupId, GroupName.Create(command.GroupName), UserId.From(command.UserId), MemberName.Create(me.Nickname), avatar, _clock);

            await _groupRepository.AddAsync(group);
        }
Exemplo n.º 19
0
        public async Task <IActionResult> CreateGroup([FromBody] CreateGroupDto groupDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var group = _mapper.Map <CreateGroupDto, Group>(groupDto);

            group.CreateDateTime = DateTime.Now;
            _groupRepository.AddAsync(group);
            await _unitOfWork.CompleteAsync();

            var result = _mapper.Map <Group, CreateGroupDto>(group);

            return(Ok(result));
        }
 public async Task HandleAsync(GroupCreated @event)
 {
     await _handler
     .Run(async() =>
     {
         var group = await _groupServiceClient.GetAsync <Group>(@event.GroupId);
         group.Value.MembersCount = group.Value.Members.Count;
         await _groupRepository.AddAsync(group.Value);
         await _groupCache.AddAsync(group.Value);
         var owner = group.Value.Members.First(x => x.Role == "owner");
         var user  = await _userRepository.GetByIdAsync(owner.UserId);
         if (user.Value.Groups == null)
         {
             user.Value.Groups = new HashSet <UserGroup>();
         }
         user.Value.Groups.Add(new UserGroup
         {
             Id       = group.Value.Id,
             Name     = group.Value.Name,
             Role     = owner.Role,
             IsActive = owner.IsActive
         });
         await _userRepository.EditAsync(user.Value);
         await _userCache.AddAsync(user.Value);
         if (!group.Value.OrganizationId.HasValue)
         {
             return;
         }
         var organization = await _organizationRepository.GetAsync(group.Value.OrganizationId.Value);
         if (organization.Value.Groups == null)
         {
             organization.Value.Groups = new List <Guid>();
         }
         organization.Value.Groups.Add(@event.GroupId);
         organization.Value.GroupsCount = organization.Value.Groups.Count;
         await _organizationRepository.UpdateAsync(organization.Value);
         await _organizationCache.AddAsync(organization.Value);
     })
     .OnError((ex, logger) =>
     {
         logger.Error(ex, $"Error occured while handling {@event.GetType().Name} event");
     })
     .ExecuteAsync();
 }
Exemplo n.º 21
0
        public async Task <IActionResult> Post([FromBody] GroupDTO dto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Group group = new Group {
                ClassId = dto.ClassId,
                Number  = dto.Number
            };

            if (await _repo.AddAsync(group))
            {
                return(Ok());
            }

            throw new Exception("Unable creating group");
        }
Exemplo n.º 22
0
        public async Task CreateAsync(CreateGroup command)
        {
            var foundGroup = await _groupRepository.GetAsync(command.Name);

            if (foundGroup != null)
            {
                throw new AppException($"Group with name ${command.Name} already exists.", AppErrorCode.ALREADY_EXISTS);
            }

            var group  = new Group(command.Id, command.Name);
            var author = await _userRepository.GetAsync(command.UserId);

            group.AddAdministrator(author);
            group.AddStudent(author);

            await _groupRepository.AddAsync(group);

            await _groupRepository.SaveChangesAsync();
        }
Exemplo n.º 23
0
        public async Task CreateAsync(Guid id, string name, string userId, bool isPublic,
                                      IDictionary <string, ISet <string> > criteria, Guid?organizationId = null)
        {
            if (await ExistsAsync(name))
            {
                throw new ServiceException(OperationCodes.GroupNameInUse,
                                           $"Group with name: '{name}' already exists.");
            }
            var user = await _userRepository.GetAsync(userId);

            var organization = await ValidateIfGroupCanBeAddedToOrganizationAsync(
                id, organizationId, user.Value);

            var owner = Member.Owner(user.Value.UserId, user.Value.Name);
            var group = new Group(id, name, owner, isPublic, criteria, organizationId);
            await _groupRepository.AddAsync(group);

            if (organization.HasNoValue)
            {
                return;
            }
            organization.Value.AddGroup(group);
            await _organizationRepository.UpdateAsync(organization.Value);
        }
Exemplo n.º 24
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);
        }
Exemplo n.º 25
0
        public async Task <Group> CreateGroupAsync(Group group)
        {
            var addedGroup = await _groupRepository.AddAsync(group);

            return(addedGroup);
        }