Example #1
0
        private void ExecuteOnCreate()
        {
            try
            {
                if (Validate())
                {
                    IsCreating = true;
                    Task.Run(() =>
                    {
                        var selectedContacts = ContactList.Where(c => c.IsSelected).Select(ui => ui as UserUiInfo).ToList();

                        var chatGroup = new ChatGroup();

                        chatGroup.Name = Name;

                        UserServiceClient.AddOrUpdateChatGroup(chatGroup);
                        chatGroup = UserServiceClient.GetChatGroup(chatGroup.Name);

                        foreach (var uiInfo in selectedContacts)
                        {
                            UserServiceClient.AddUserToChatGroupContact(chatGroup.Id, uiInfo.UserId);
                        }

                        UserServiceClient.AddUserToChatGroupContact(chatGroup.Id, GlobalBase.CurrentUser.Id);

                        if (_newAvatar != null)
                        {
                            var updatedChat     = UserServiceClient.GetChatGroup(Name);
                            updatedChat.ImageId = GlobalBase.FileServiceClient.UploadFile(new FileService.ChatFile()
                            {
                                Source = CompressionHelper.CompressImage(_newAvatar)
                            });
                            UserServiceClient.AddOrUpdateChatGroup(updatedChat);
                        }
                    }).ContinueWith(task =>
                    {
                        Application.Current.Dispatcher.Invoke(new Action(() =>
                        {
                            IsCreating = false;
                            _view.CloseWindow();
                        }));
                    });
                }
            }
            catch (Exception)
            {
            }
        }
Example #2
0
        private void ExecuteOnApplyChanges()
        {
            try
            {
                if (Validate())
                {
                    IsSavingProgress = true;
                    var res = string.Empty;

                    Task.Run(() =>
                    {
                        _group.Name = GroupName;

                        var chatFile = GlobalBase.FileServiceClient.getChatFileById(_group.ImageId);

                        if (_newAvatar != null)
                        {
                            if (chatFile == null)
                            {
                                _group.ImageId = GlobalBase.FileServiceClient.UploadFile(new FileService.ChatFile()
                                {
                                    Source = CompressionHelper.CompressImage(_newAvatar)
                                });
                            }
                            else
                            {
                                GlobalBase.FileServiceClient.UpdateFileSource(chatFile.Id, CompressionHelper.CompressImage(_newAvatar));
                            }
                        }

                        if (_membersToAdd?.Count != 0)
                        {
                            foreach (var uiInfo in _membersToAdd)
                            {
                                UserServiceClient.AddUserToChatGroupContact(_group.Id, (uiInfo as UserUiInfo).UserId);
                            }
                        }

                        res = UserServiceClient.AddOrUpdateChatGroup(_group);

                        SetAvatarForUI();

                        if (res == string.Empty)
                        {
                            Application.Current.Dispatcher.Invoke(new Action((() =>
                            {
                                CustomMessageBox.Show(Translations.GetTranslation()["ChangesSaved"].ToString());
                            })));
                        }
                    }).ContinueWith(task =>
                    {
                        IsSavingProgress = false;
                        IsNewChanges     = false;

                        GlobalBase.UpdateContactList();
                    });
                }
            }
            catch (Exception)
            {
            }
        }