Example #1
0
        protected override void AddNewItem()
        {
            if (StringValidation.ValidSqlInputVariable(this._tb_Description.Text) ||
                StringValidation.ValidSqlInputVariable(this._tb_Name.Text) ||
                StringValidation.ValidSqlInputVariable(this._tb_Owner.Text))
            {
                return;
            }
            else
            {
                try
                {
                    if (this._tb_Description.Text.Length == 0 ||
                        this._tb_Name.Text.Length == 0 ||
                        this._tb_Owner.Text.Length == 0)
                    {
                        return;
                    }

                    bool isActive = (bool)this._cb_IsActive.IsChecked;

                    ejsCourse course = new ejsCourse()
                    {
                        _creationDate = DateTime.Now,
                        _description  = this._tb_Description.Text,
                        _isActive     = isActive,
                        _name         = this._tb_Name.Text,
                        _owner        = this._tb_Owner.Text
                    };

                    BackgroundWorker bgw = new BackgroundWorker();
                    bgw.RunWorkerCompleted        += new RunWorkerCompletedEventHandler(OperationCompleted);
                    bgw.WorkerSupportsCancellation = true;
                    bgw.DoWork += delegate(object sender, DoWorkEventArgs e)
                    {
                        try
                        {
                            ejsBridgeManager.AddNewCourse(this._currentUserToken, course);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                            e.Cancel = true;
                        }
                    };

                    bgw.RunWorkerAsync();

                    this._parentStage.RaiseAsyncOperationStartedEvent("Uploading and Saving Course Document.");
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
        private void AuthenticateUserAsync()
        {
            if (this._tb_UserName.Text == "" ||
                this._tb_ServerAddress.Text == "" ||
                this._pwb_Password.Password.Length == 0)
            {
                return;
            }

            if (StringValidation.ValidSqlInputVariable(this._tb_UserName.Text) ||
                StringValidation.ValidSqlInputVariable(this._tb_ServerAddress.Text) ||
                StringValidation.ValidSqlInputVariable(this._pwb_Password.Password))
            {
                return;
            }

            string userName      = this._tb_UserName.Text;
            string serverAddress = this._tb_ServerAddress.Text;
            string password      = this._pwb_Password.Password;

            ServiceOperations.ejsBridgeManager.EjsAddress = serverAddress;

            BackgroundWorker bgw = new BackgroundWorker();

            bgw.RunWorkerCompleted        += new RunWorkerCompletedEventHandler(LoginOperationCompleted);
            bgw.WorkerSupportsCancellation = true;
            bgw.DoWork += delegate(object sender, DoWorkEventArgs e)
            {
                try
                {
                    e.Result = ServiceOperations.ejsBridgeManager.AuthenticateUser(
                        userName, password, Guid.NewGuid());
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    e.Cancel = true;
                }
            };
            bgw.RunWorkerAsync();

            this.RaiseAsyncOperationStartedEvent("Authenticating...");
        }
        private void UpdateCourse(ejsCourse courseToUpdate)
        {
            lock (this.threadLock)
            {
                if (this._isStageBusy)
                {
                    return;
                }

                this._isStageBusy = true;

                BackgroundWorker bgw = new BackgroundWorker();
                bgw.RunWorkerCompleted        += new RunWorkerCompletedEventHandler(UpdateItemOperationCompleted);
                bgw.WorkerSupportsCancellation = true;
                bgw.DoWork += delegate(object sender, DoWorkEventArgs e)
                {
                    try
                    {
                        if (StringValidation.ValidSqlInputVariable(courseToUpdate._description) ||
                            StringValidation.ValidSqlInputVariable(courseToUpdate._name) ||
                            StringValidation.ValidSqlInputVariable(courseToUpdate._owner))
                        {
                            MessageBox.Show("Invalid Course Data.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                            return;
                        }

                        ejsBridgeManager.UpdateCourse(this.CurrentUserToken, courseToUpdate);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        e.Cancel = true;
                    }
                };

                bgw.RunWorkerAsync();

                this.RaiseAsyncOperationStartedEvent("Updating Course on eJournalServer...");
            }
        }
        protected override void AddNewItem()
        {
            if (StringValidation.ValidSqlInputVariable(this._tb_Title.Text) ||
                StringValidation.ValidSqlInputVariable(this._tb_Description.Text) ||
                StringValidation.ValidSqlInputVariable(this._pathToDocumentFile))
            {
                return;
            }
            else
            {
                try
                {
                    if (this._tb_Title.Text.Length == 0 ||
                        this._tb_Description.Text.Length == 0 ||
                        this._pathToDocumentFile.Length == 0)
                    {
                        return;
                    }

                    string title       = this._tb_Title.Text;
                    string description = this._tb_Description.Text;
                    bool   isActive    = (bool)this._cb_IsAvailable.IsChecked;
                    int    courseId    = ((ejsCourse)this._cb_CourseList.SelectedItem)._id;

                    FileStream   fs       = new FileStream(this._pathToDocumentFile, FileMode.Open, FileAccess.Read);
                    BinaryReader br       = new BinaryReader(fs);
                    long         fileSize = fs.Length;
                    byte[]       data     = br.ReadBytes((int)fs.Length);
                    br.Close();
                    fs.Close();
                    fs.Dispose();

                    ejsCourseDocument document = new ejsCourseDocument();
                    document._name         = title;
                    document._byteSize     = data.Length;
                    document._isAvailable  = isActive;
                    document._creationDate = DateTime.Now;
                    document._description  = description;
                    document._documentId   = Guid.NewGuid();

                    BackgroundWorker bgw = new BackgroundWorker();
                    bgw.RunWorkerCompleted        += new RunWorkerCompletedEventHandler(OperationCompleted);
                    bgw.WorkerSupportsCancellation = true;
                    bgw.DoWork += delegate(object sender, DoWorkEventArgs e)
                    {
                        try
                        {
                            ejsBridgeManager.AddDocumentToCourse(this._currentUserToken, document, courseId, data);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                            e.Cancel = true;
                        }
                    };

                    bgw.RunWorkerAsync();

                    this._parentStage.RaiseAsyncOperationStartedEvent("Uploading and Saving Course Document.");
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
        protected override void AddNewItem()
        {
            if (StringValidation.ValidSqlInputVariable(this._tb_Email.Text) ||
                StringValidation.ValidSqlInputVariable(this._tb_FirstName.Text) ||
                StringValidation.ValidSqlInputVariable(this._tb_Password.Text) ||
                StringValidation.ValidSqlInputVariable(this._tb_UserName.Text) ||
                StringValidation.ValidSqlInputVariable(this._tb_LastName.Text))
            {
                return;
            }
            else
            {
                try
                {
                    if (this._tb_Email.Text.Length == 0 ||
                        this._tb_FirstName.Text.Length == 0 ||
                        this._tb_UserName.Text.Length == 0 ||
                        this._tb_LastName.Text.Length == 0 ||
                        this._tb_Password.Text.Length == 0)
                    {
                        return;
                    }

                    bool isActive = (bool)this._cb_CanLogin.IsChecked;

                    ejsUserInfo uInfo = new ejsUserInfo()
                    {
                        FirstName       = this._tb_FirstName.Text,
                        LastName        = this._tb_LastName.Text,
                        Email           = this._tb_Email.Text,
                        IsAccountActive = isActive,
                        UserName        = this._tb_UserName.Text,
                        Id = Guid.NewGuid().ToString()
                    };

                    int groupid = 3;
                    if (this._cb_IsTeacher.IsChecked == true)
                    {
                        groupid = 2;
                    }

                    string password = this._tb_Password.Text;

                    BackgroundWorker bgw = new BackgroundWorker();
                    bgw.RunWorkerCompleted        += new RunWorkerCompletedEventHandler(OperationCompleted);
                    bgw.WorkerSupportsCancellation = true;
                    bgw.DoWork += delegate(object sender, DoWorkEventArgs e)
                    {
                        try
                        {
                            ejsBridgeManager.AddNewUser(this._currentUserToken, uInfo, groupid, password);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                            e.Cancel = true;
                        }
                    };

                    bgw.RunWorkerAsync();

                    this._parentStage.RaiseAsyncOperationStartedEvent("Creating New User Record.");
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }