Exemplo n.º 1
0
        public static async Task <string> CreateNewGroupAsync(
            GroupUploadModel groupUploadModel,
            Guid userId,
            IRepositoryManager repositoryManager)
        {
            try
            {
                var newGroupIdentifier = await GenerateNewGroupIdentifierAsync(repositoryManager.GroupRepository).ConfigureAwait(false);

                var newGroup = new Domain.Entities.Group
                {
                    Identifier    = newGroupIdentifier,
                    Name          = groupUploadModel.Name,
                    IsPrivate     = groupUploadModel.IsPrivate,
                    CreatedOn     = DateTime.Now,
                    CreatedBy     = userId,
                    LastUpdatedOn = DateTime.Now,
                    LastUpatedBy  = userId
                };

                await repositoryManager.GroupRepository.AddAsync(newGroup);

                await CreateNewGroupMemberAsync(
                    newGroup.Id,
                    userId,
                    repositoryManager).ConfigureAwait(false);

                return(newGroupIdentifier);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 2
0
        public async Task <ActionResult <string> > CreateNewGroupAsync(GroupUploadModel groupUploadModel)
        {
            try
            {
                if (await IsUserValidAsync())
                {
                    if (!GroupModel.IsGroupUploadModelValid(groupUploadModel))
                    {
                        return(BadRequest());
                    }

                    var groupIdentifier = await GroupModel.CreateNewGroupAsync(
                        groupUploadModel,
                        ExtractUserIdFromToken(),
                        RepositoryManager);

                    return(Ok(groupIdentifier));
                }
                else
                {
                    return(Unauthorized());
                }
            }
            catch (Exception err)
            {
                LogException(err);

                return(Problem());
            }
        }
Exemplo n.º 3
0
 public static bool IsGroupUploadModelValid(GroupUploadModel groupUploadModel)
 {
     if (groupUploadModel.Name.Length > 150)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }