Exemplo n.º 1
0
 private static void DisplayGroup(GroupDto group)
 {
     Output.InWhite.WriteLine();
     Output.InYellow.WriteLine("[{1,3}] {0}", group.Name, group.Id);
     Output.InWhite.WriteLine("----------------------------");
     Output.InDarkYellow.WriteLine("Beneficiaries:");
     foreach (var b in group.People)
     {
         Output.InWhite.WriteLine("\t[{0}] {1} {2}", b.IsEducator ? "EDUCATOR" : "BENEFICIARY", b.Name, b.Surname);
     }
 }
Exemplo n.º 2
0
 public async Task<IHttpActionResult> CreateGroup([FromBody]GroupDto group)
 {
     if (!ModelState.IsValid)
     {
         return BadRequest(ModelState);
     }
     var userId = User.Identity.GetUserId();
     group.OwnerUserId = userId;
     var result = await _groupService.AddAsync(group);
     await _userGroupService.AddAsync(userId, result.GroupId);
     return Created(Url.Request.RequestUri + "/" + result.GroupId, result);
 }
Exemplo n.º 3
0
        public async Task <GroupDto> UpdateAsync(int id, GroupDto dto)
        {
            dto.BossCharacter = null;
            dto.DefaultRank   = null;

            GroupModel model = await _unitOfWork.GroupsRepository.JoinAndGetAsync(id);

            _mapper.Map(dto, model);
            await _unitOfWork.SaveAsync();

            return(dto);
        }
Exemplo n.º 4
0
        public async Task <GroupDto> Get(int id)
        {
            var entity = await this._unitOfWork.Group.Get(id);

            if (!entity.IsVisible)
            {
                return(null);
            }
            GroupDto groupDto = _mapper.Map <GroupDto>(entity);

            return(groupDto);
        }
        public async Task <int> Post(GroupDto group)
        {
            var id =
                await _groupService.InsertAsync(new GroupDto
            {
                IsActive    = group.IsActive,
                Name        = group.Name,
                Description = group.Description,
            });

            return(id);
        }
Exemplo n.º 6
0
        public void Update(GroupDto @group)
        {
            if (group == null)
            {
                throw new ArgumentNullException("Value is a null");
            }

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

            _dbContext.Groups.Update(groupEntity);
            _dbContext.SaveChanges();
        }
Exemplo n.º 7
0
        public async Task <ActionResult <Group> > RegisterGroup(GroupDto newGroup)
        {
            var group = new Group {
                Id   = newGroup.Id,
                Name = newGroup.Name
            };

            _dataContext.Groups.Add(group);
            await _dataContext.SaveChangesAsync();

            return(group);
        }
Exemplo n.º 8
0
 private Group GetGroup(GroupDto groupDto)
 {
     return(new Group
     {
         Id = groupDto.Id ?? 0,
         GroupName = groupDto.GroupName,
         Description = groupDto.Description,
         Email = groupDto.Email,
         EnabledEmail = groupDto.EnabledEmail,
         ParentGroupId = groupDto.ParentGroupId
     });
 }
Exemplo n.º 9
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.º 10
0
 private IList <Movie> GetMoviesGroup(GroupDto groupOne, GroupDto groupTwo)
 {
     return(new List <Movie>
     {
         _tiebreaker.Apply(new List <Movie> {
             groupOne.Movies.First(), groupTwo.Movies.Last()
         }).First(),
         _tiebreaker.Apply(new List <Movie> {
             groupTwo.Movies.First(), groupOne.Movies.Last()
         }).First()
     });
 }
        public int AddGroup(GroupDto value)
        {
            if (ModelState.IsValid)
            {
                using (KivoDbContext context = new KivoDbContext(Configuration.GetConnectionString("DefaultConnection")))
                {
                    return(context.Group.Add(value.ConvertToGroup()));
                }
            }

            return(0);
        }
        public void Execute(GroupDto request)
        {
            _validator.ValidateAndThrow(request);

            var group = new Group
            {
                Name = request.Name
            };

            _context.Groups.Add(group);
            _context.SaveChanges();
        }
Exemplo n.º 13
0
        public GroupDto GetSingle(Guid id)
        {
            GroupDto groupDto = null;

            using (ISession session = _sessionFactory.OpenSession())
            {
                IRepository <Group> groupRepository = new Repository <Group>(session);
                var group = groupRepository.FindOne(id);
                groupDto = Mapper.Map <GroupDto>(group);
            }

            return(groupDto);
        }
        public void GroupDtoValidation_Valid_NoErrors()
        {
            var dto = new GroupDto
            {
                Name = RandomFactory.GetCompanyName(),
            };

            var validationContext = new ValidationContext(dto);

            var validationResults = dto.Validate(validationContext);

            validationResults.Should().HaveCount(0);
        }
Exemplo n.º 15
0
        private Group MapGroupDto(GroupDto groupDto)
        {
            Group         group   = _mapper.Map <Group>(groupDto);
            ClientProfile profile = _database.ClientProfileRepository.GetByName(groupDto.Username);

            if (profile != null)
            {
                group.ApplicationUserId = profile.Id;
                return(group);
            }

            return(null);
        }
Exemplo n.º 16
0
        public async Task <GroupDto> CreateGroup(GroupDto groupDto)
        {
            Group group = MapGroupDto(groupDto);

            if (group == null)
            {
                return(null);
            }

            group = await _database.GroupRepository.Create(group);

            return(await MapGroup(group));
        }
Exemplo n.º 17
0
        public static GroupDto ToGroupDto(this Group group)
        {
            var groupDto = new GroupDto();

            if (group != null)
            {
                groupDto.Id      = group.Id;
                groupDto.Title   = group.Title;
                groupDto.Created = group.Created;
                groupDto.Number  = group.Number;
            }
            return(groupDto);
        }
Exemplo n.º 18
0
        public IActionResult CreateGroup(GroupDto groupDto)
        {
            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var group  = new Group
            {
                Name   = groupDto.Name,
                UserId = userId
            };

            _context.Add(group);
            _context.SaveChanges();
            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 19
0
 public bool Save(GroupDto dto)
 {
     try
     {
         bool retVal = this.dal.Save(dto.Id, dto.Name);
         return(retVal);
     }
     catch (Exception ex)
     {
         base.Logger.Error("[GroupLogic] An error occurred", ex);
         throw;
     }
 }
Exemplo n.º 20
0
 public GroupDto GetByName(string name)
 {
     try
     {
         GroupDto retVal = this.dal.GetByName(name).ToDto();
         return(retVal);
     }
     catch (Exception ex)
     {
         base.Logger.Error("[GroupLogic] An error occurred", ex);
         throw ex;
     }
 }
Exemplo n.º 21
0
        public IHttpActionResult GetGroup(int id)
        {
            var group = db.Groups.Find(id);

            if (group == null)
            {
                return(NotFound());
            }

            var dto = new GroupDto(group);

            return(Ok(dto));
        }
Exemplo n.º 22
0
        public async Task <IActionResult> Join([FromBody] GroupDto group)
        {
            var email = User.GetEmail();

            var joined = await _userLogic.JoinGroup(group, email);

            if (joined)
            {
                return(Ok());
            }

            return(NotFound());
        }
Exemplo n.º 23
0
        public async Task <IActionResult> Put(string groupName, [FromBody] GroupDto group)
        {
            var existingGroup = await _groupsService.GetGroupAsync(groupName);

            if (existingGroup == null)
            {
                return(NotFound());
            }

            await _groupsService.UpdateGroupAsync(groupName, group);

            return(Ok());
        }
Exemplo n.º 24
0
        public async Task <int> AddGroupAsync(GroupDto groupDto)
        {
            if (groupDto == null)
            {
                throw new ArgumentNullException($"Argument {nameof(groupDto)} can't be null!");
            }

            int id = context.Set <Group>().Add(groupDto.ToGroup()).Id;

            await context.SaveChangesAsync();

            return(id);
        }
Exemplo n.º 25
0
        public async Task PutGroup(GroupDto group)
        {
            try
            {
                var response = await PutAsJsonAsync(client, "api/groups/" + group.ID, group);

                response.EnsureSuccessStatusCode();
            }
            catch (Exception)
            {
                return;
            }
        }
Exemplo n.º 26
0
        public async Task CreateGroupCommand(GroupDto group)
        {
            try
            {
                var response = await PostAsJsonAsync(client, "api/groups", group);

                response.EnsureSuccessStatusCode();
            }
            catch (Exception)
            {
                return;
            }
        }
        public void Execute(GroupDto request)
        {
            _validator.ValidateAndThrow(request);
            var group = _context.Groups.Find(request.Id);

            if (group == null)
            {
                throw new EntityNotFoundException(request.Id, typeof(Group));
            }

            _mapper.Map(request, group);
            _context.SaveChanges();
        }
Exemplo n.º 28
0
        public ActionResult ShowGroupPage(int groupId)
        {
            int      userId   = ((UserDto)Session["session"]).Id;
            GroupDto groupDto = groupService.GetGroupDtoById(groupId, userId);

            ViewData["mainWallId"] = groupService.GetGroupMainWallId(groupId);
            GroupRoles role = groupService.GetUserRoleInGroup(userId, groupId);

            ViewData["role"]          = role;
            ViewData["groupId"]       = groupId;
            ViewData["requestIsSent"] = groupService.CheckRequest(userId, groupId);
            return(View("GroupPage", groupDto));
        }
Exemplo n.º 29
0
        public static GroupDto ConvertGroupToGroupDto(Group group)
        {
            GroupDto groupDto = new GroupDto()
            {
                Id             = group.Id,
                Name           = group.Name,
                Members        = group.UserGroups.Where(ug => !ug.IsAdmin).Select(ug => ug.UserId).ToList(),
                Administrators = group.UserGroups.Where(ug => ug.IsAdmin).Select(ug => ug.UserId).ToList(),
                Files          = group.Files.Where(f => f.GroupId == group.Id).Select(f => f.Id).ToList()
            };

            return(groupDto);
        }
Exemplo n.º 30
0
        public IActionResult Get(long id)
        {
            Group group = _groupService.GetById(id);

            if (group == null)
            {
                return NotFound();
            }

            GroupDto groupToReturn = _mapper.Map<GroupDto>(group);

            return Ok(groupToReturn);
        }
        public async Task <GroupDto> GetGroupById(int groupId)
        {
            var grp = await _context.Groups.FirstOrDefaultAsync(x => x.Id == groupId);

            var group = new GroupDto
            {
                UserId    = 0,
                GroupId   = grp.Id,
                GroupName = grp.GroupName
            };

            return(group);
        }
Exemplo n.º 32
0
 public DResult AddGroup(GroupDto dto, string creatorId)
 {
     if (Groups.Exists(g => g.Code == dto.Code || g.Group == dto.Name))
         return DResult.Error("词条分类已存在!");
     var item = dto.MapTo<WikiGroup>();
     item.Id = CombHelper.Guid16;
     item.CreateTime = Clock.Now;
     item.WikiCount = 0;
     item.CreatorId = creatorId;
     item.Sort = Groups.Max(g => g.Sort) + 1;
     var result = Groups.Insert(item);
     return string.IsNullOrWhiteSpace(result)
         ? DResult.Error("添加词条分类失败!")
         : DResult.Success;
 }
Exemplo n.º 33
0
 public ActionResult AddGroup(GroupDto dto)
 {
     var result = _wikiContract.AddGroup(dto, string.Empty);
     return DeyiJson(result);
 }