Exemplo n.º 1
0
        private ChannelEntity DeleteUserChannelsInChannel(ChannelEntity channel, string[] usersEmails)
        {
            List <string> user_emails = channel.Users.Split(",").ToList();
            List <string> owner_ids   = channel.Owner.Split(",").ToList();


            foreach (string user in usersEmails)
            {
                string id = this.UserService.getUserId(user).Result;
                if (!string.IsNullOrEmpty(id))
                {
                    UserChannelEntity entity = new UserChannelEntity();
                    entity.ChannelID   = channel.ChannelId;
                    entity.WorkspaceID = channel.WorkspaceID;
                    entity.UserID      = id;
                    this.ChannelService._userChannelRepository.Delete(entity);
                }
                if (owner_ids.Contains(id) && owner_ids.Count == 1)
                {
                }
                else if (owner_ids.Contains(id) && owner_ids.Count > 1)
                {
                    owner_ids.Remove(id);
                }

                user_emails.Remove(user);
            }
            channel.Owner = this.ChannelService.ToSingleString(owner_ids.ToArray());
            channel.Users = this.ChannelService.ToSingleString(user_emails.ToArray());
            return(channel);
        }
Exemplo n.º 2
0
        public async Task <ResponseModel> EditChannel(ChannelDetailsModel model, string workspaceId, string userId)
        {
            return(await Task <ResponseModel> .Run(() =>
            {
                ResponseModel responseModel = new ResponseModel();
                Boolean userHasPermission = this.ChannelService.UserIsChannelOwner(userId, workspaceId, model.Id);

                if (!userHasPermission)
                {
                    responseModel.ErrorMessage.Add("User does not have Permission");
                    return responseModel;
                }

                string[] key = new string[2] {
                    "PartitionKey", "RowKey"
                };
                string[] value = new string[2] {
                    workspaceId, model.Id
                };
                ChannelEntity channel = this.ChannelService._channelRepository.Get(key, value).Result;

                if (!string.IsNullOrEmpty(model.Name))
                {
                    channel.Name = model.Name;
                }
                List <string> owners = new List <string>();

                if (model.Users != null)
                {
                    foreach (ChannelUserModel userModel in model.Users)
                    {
                        if (userModel.IsOwner)
                        {
                            owners.Add(userModel.Email);
                        }
                    }
                }

                List <string> CurrentOwners = channel.Owner.Split(",").ToList();

                foreach (string owner_email in owners)
                {
                    string id = this.UserService.getUserId(owner_email).Result;
                    if (!CurrentOwners.Contains(id))
                    {
                        CurrentOwners.Add(id);
                        UserChannelEntity userChannelEntity = new UserChannelEntity();
                        userChannelEntity.ChannelID = model.Id;
                        userChannelEntity.UserID = id;
                        userChannelEntity.WorkspaceID = workspaceId;
                        userChannelEntity.Owner = true;

                        this.ChannelService._userChannelRepository.Update(userChannelEntity);
                    }
                }

                channel.Owner = this.ChannelService.ToSingleString(CurrentOwners.ToArray());

                if (string.IsNullOrWhiteSpace(model.PictureLocation))
                {
                    channel.Picture_Location = model.PictureLocation;
                }

                this.ChannelService._channelRepository.Update(channel);

                responseModel.Message = "Successfully Updated";



                return responseModel;
            }));
        }