Esempio n. 1
0
        public IEnumerable <TOPModel> GetTOPs()
        {
            IEnumerable <TOPTable> topTables = _topService.GetTOPs();
            List <TOPModel>        topModels = new List <TOPModel>();

            foreach (var topTable in topTables)
            {
                var company = GetCompany(topTable.Company);
                var address = GetAddress(topTable.Address);
                var teacher = GetTeacher(topTable.Teacher);
                var vocationalQualificationUnit = GetVocationalQualificationUnit(topTable.VocationalQualificationUnit);

                TOPModel top = new TOPModel
                {
                    Id                          = topTable.Id,
                    PhoneNumber                 = topTable.PhoneNumber,
                    EmailAddress                = topTable.EmailAddress,
                    Reserved                    = topTable.Reserved,
                    ReservationEnds             = topTable.ReservationEnds,
                    Accepted                    = topTable.Accepted,
                    Info                        = topTable.Info,
                    Company                     = company.company,
                    Teacher                     = teacher.teacher,
                    Address                     = address.address,
                    VocationalQualificationUnit = vocationalQualificationUnit.vocationalQualificationUnit
                };
                topModels.Add(top);
            }
            return(topModels);
        }
Esempio n. 2
0
        public void SaveTOP(TextBox txtCompanyAdd, TextBox txtAddressAdd, ComboBox cboTeacherAdd,
                            ComboBox cboVocationQualificationUnitAdd, TextBox txtPhoneAdd, TextBox txtEmailAdd,
                            RichTextBox txtInfoAdd, DataGrid TOPsDataGrid, StackPanel TOP_Panel, Button btnOk)
        {
            TOPModel top = new TOPModel
            {
                Id                          = UpdateId,
                PhoneNumber                 = txtPhoneAdd.Text,
                EmailAddress                = txtEmailAdd.Text,
                Reserved                    = false,
                ReservationEnds             = DateTime.MinValue,
                Accepted                    = false,
                Info                        = new TextRange(txtInfoAdd.Document.ContentStart, txtInfoAdd.Document.ContentEnd).Text,
                Company                     = txtCompanyAdd.Text,
                Address                     = txtAddressAdd.Text,
                Teacher                     = cboTeacherAdd.Text,
                VocationalQualificationUnit = cboVocationQualificationUnitAdd.Text
            };

            if (Type == "new")
            {
                NewTOP(top, TOPsDataGrid, TOP_Panel);
                TOP_Panel_Action(TOP_Panel, 0, "", txtCompanyAdd, txtAddressAdd, cboTeacherAdd, cboVocationQualificationUnitAdd, txtPhoneAdd,
                                 txtEmailAdd, txtInfoAdd, TOPsDataGrid, btnOk);
                return;
            }
            UpdateTOP(top, TOPsDataGrid);
            TOP_Panel_Action(TOP_Panel, 0, "", txtCompanyAdd, txtAddressAdd, cboTeacherAdd, cboVocationQualificationUnitAdd, txtPhoneAdd,
                             txtEmailAdd, txtInfoAdd, TOPsDataGrid, btnOk);
        }
Esempio n. 3
0
 private bool isAccepted(TOPModel top)
 {
     if (top.Accepted)
     {
         return(true);
     }
     return(false);
 }
Esempio n. 4
0
 private bool isReserved(TOPModel top)
 {
     if (top.Reserved)
     {
         return(true);
     }
     return(false);
 }
Esempio n. 5
0
 public void NewTOP(TOPModel top, DataGrid TOPsDataGrid, StackPanel TOP_Panel)
 {
     if (top.Company == "" || top.Address == "" || top.Teacher == "" || top.VocationalQualificationUnit == "")
     {
         MessageBox.Show("Missing information!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         return;
     }
     AddTOP(top, TOPsDataGrid);
 }
Esempio n. 6
0
 private async void AddTOP(TOPModel top, DataGrid TOPsDataGrid)
 {
     if (await top_Functionality.AddTOPAsync(top) != "{\"message\":\"TOP is added to database\"}")
     {
         MessageBox.Show("TOP is not added", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         return;
     }
     MessageBox.Show("TOP is added", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
     GetTOPs(TOPsDataGrid);
 }
Esempio n. 7
0
        public bool AddTOP(TOPModel topModel)
        {
            if (CheckDetails(topModel) == false)
            {
                return(false);
            }

            AddTOPTable(topModel);
            return(true);
        }
Esempio n. 8
0
        public async Task <string> AddTOPAsync(TOPModel top)
        {
            HttpResponseMessage response = await HttpClientSettings.client.PostAsJsonAsync(Url.Controller_TOP, top);

            response.EnsureSuccessStatusCode();

            string result = await response.Content.ReadAsStringAsync();

            return(result);
        }
Esempio n. 9
0
        public void AcceptTOP(DataGrid TOPsDataGrid)
        {
            TOPModel top = TOPsDataGrid.SelectedItem as TOPModel;

            if (isAccepted(top))
            {
                MessageBox.Show($"This top is already accpeted", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            Acception(top, TOPsDataGrid);
        }
Esempio n. 10
0
        public void ReserveTOP(DataGrid TOPsDataGrid)
        {
            TOPModel top = TOPsDataGrid.SelectedItem as TOPModel;

            if (isReserved(top))
            {
                MessageBox.Show($"This top is already reserved to someone it's reservations ends {top.ReservationEnds}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            Reservation(top, TOPsDataGrid);
        }
Esempio n. 11
0
        public async Task <string> DeleteTOPAsync(TOPModel top)
        {
            string requestUri            = Url.Controller_TOP + "/" + top.Id;
            HttpResponseMessage response = await HttpClientSettings.client.DeleteAsync(requestUri);

            response.EnsureSuccessStatusCode();

            string result = await response.Content.ReadAsStringAsync();

            return(result);
        }
Esempio n. 12
0
        public async void DeleteTOP(DataGrid TOPsDataGrid)
        {
            TOPModel top = TOPsDataGrid.SelectedItem as TOPModel;

            if (await top_Functionality.DeleteTOPAsync(top) != "{\"message\":\"TOP is deleted from database\"}")
            {
                MessageBox.Show("TOP is not deleted", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            MessageBox.Show("TOP is deleted", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
            GetTOPs(TOPsDataGrid);
        }
Esempio n. 13
0
        private void Reservation(TOPModel top, DataGrid TOPsDataGrid)
        {
            ReservationWindow reservation = new ReservationWindow();

            if (reservation.ShowDialog() == true)
            {
                top.Reserved        = true;
                top.ReservationEnds = reservation.ReservationEndDate.SelectedDate.Value;
                UpdateTOP(top, TOPsDataGrid);
                return;
            }
            MessageBox.Show("TOP is not reserved!", "Info", MessageBoxButton.OK, MessageBoxImage.Warning);
        }
Esempio n. 14
0
 public void TOP_Panel_Action(StackPanel TOP_Panel, int width, string type, TextBox txtCompanyAdd, TextBox txtAddressAdd, ComboBox cboTeacherAdd,
                              ComboBox cboVocationQualificationUnitAdd, TextBox txtPhoneAdd, TextBox txtEmailAdd,
                              RichTextBox txtInfoAdd, DataGrid TOPsDataGrid, Button btnOk)
 {
     Type            = type;
     TOP_Panel.Width = width;
     if (type == "")
     {
         txtCompanyAdd.IsEnabled = true;
         txtAddressAdd.IsEnabled = true;
         txtEmailAdd.IsEnabled   = true;
         txtInfoAdd.IsEnabled    = true;
         txtPhoneAdd.IsEnabled   = true;
         cboTeacherAdd.IsEnabled = true;
         cboVocationQualificationUnitAdd.IsEnabled = true;
         btnOk.IsEnabled    = true;
         txtCompanyAdd.Text = "";
         txtAddressAdd.Text = "";
         txtEmailAdd.Text   = "";
         txtInfoAdd.Document.Blocks.Clear();
         txtInfoAdd.Document.Blocks.Add(new Paragraph(new Run("")));
         txtPhoneAdd.Text            = "";
         cboTeacherAdd.SelectedIndex = -1;
         cboVocationQualificationUnitAdd.SelectedIndex = -1;
     }
     else if (type == "edit" || type == "show")
     {
         TOPModel top = TOPsDataGrid.SelectedItem as TOPModel;
         UpdateId           = top.Id;
         txtCompanyAdd.Text = top.Company;
         txtAddressAdd.Text = top.Address;
         txtEmailAdd.Text   = top.EmailAddress;
         txtInfoAdd.Document.Blocks.Clear();
         txtInfoAdd.Document.Blocks.Add(new Paragraph(new Run(top.Info)));
         txtPhoneAdd.Text   = top.PhoneNumber;
         cboTeacherAdd.Text = top.Teacher;
         cboVocationQualificationUnitAdd.Text = top.VocationalQualificationUnit;
         if (type == "show")
         {
             txtCompanyAdd.IsEnabled = false;
             txtAddressAdd.IsEnabled = false;
             txtEmailAdd.IsEnabled   = false;
             txtInfoAdd.IsEnabled    = false;
             txtPhoneAdd.IsEnabled   = false;
             cboTeacherAdd.IsEnabled = false;
             cboVocationQualificationUnitAdd.IsEnabled = false;
             btnOk.IsEnabled = false;
         }
     }
 }
Esempio n. 15
0
        private bool CheckDetails(TOPModel topModel)
        {
            var company = _companyService.Add(CreateCompany(topModel.Company));
            var address = _addressService.Add(CreateAddress(topModel.Address));
            var teacher = _teacherService.Add(CreateTeacher(topModel.Teacher));
            var vocationalQualificationUnit = _vocationalQualificationUnitService.Add(
                CreateVocationalQualificationUnit(topModel.VocationalQualificationUnit));

            if (company == null || address == null || teacher == null || vocationalQualificationUnit == null)
            {
                return(false);
            }
            return(true);
        }
Esempio n. 16
0
        public void UpdateTOP(TOPModel topModel)
        {
            var top = GetTOPTable(topModel.Id);

            UpdateCompany(top.Company, topModel.Company);
            UpdateAddress(top.Address, topModel.Address);

            top.PhoneNumber                 = topModel.PhoneNumber;
            top.EmailAddress                = topModel.EmailAddress;
            top.Reserved                    = topModel.Reserved;
            top.ReservationEnds             = topModel.ReservationEnds;
            top.Accepted                    = topModel.Accepted;
            top.Info                        = topModel.Info;
            top.Teacher                     = ChangeTeacher(topModel.Teacher).Id;
            top.VocationalQualificationUnit = ChangeVocationalQualificationUnit(topModel.VocationalQualificationUnit).Id;

            _topService.UpdateTOP(top);
        }
Esempio n. 17
0
        public IActionResult UpdateTOP([FromBody] TOPModel topModel)
        {
            try
            {
                if (topModel == null)
                {
                    return(BadRequest(new { Error = "top is null" }));
                }

                _mainService.UpdateTOP(topModel);

                return(Ok(new { message = "TOP is updated to database" }));
            }
            catch (Exception ex)
            {
                string message = ex.Message + " " + ex.StackTrace;
                return(BadRequest(new { Error = message }));
            }
        }
Esempio n. 18
0
        private void AddTOPTable(TOPModel topModel)
        {
            var      company = _companyService.GetByName(topModel.Company);
            var      address = _addressService.GetByName(topModel.Address);
            var      teacher = _teacherService.GetByName(topModel.Teacher);
            var      vocationalQualificationUnit = _vocationalQualificationUnitService.GetByName(topModel.VocationalQualificationUnit);
            TOPTable top = new TOPTable
            {
                PhoneNumber                 = topModel.PhoneNumber,
                EmailAddress                = topModel.EmailAddress,
                Reserved                    = topModel.Reserved,
                ReservationEnds             = topModel.ReservationEnds,
                Accepted                    = topModel.Accepted,
                Info                        = topModel.Info,
                Company                     = company.Id,
                Address                     = address.Id,
                Teacher                     = teacher.Id,
                VocationalQualificationUnit = vocationalQualificationUnit.Id
            };

            _topService.AddTOP(top);
        }
Esempio n. 19
0
        public IActionResult AddTOP([FromBody] TOPModel topModel)
        {
            try
            {
                if (topModel == null)
                {
                    return(BadRequest(new { Error = "top is null" }));
                }

                if (_mainService.AddTOP(topModel) == false)
                {
                    return(BadRequest(new { Error = "Error cant add TOP" }));
                }

                return(Ok(new { message = "TOP is added to database" }));
            }
            catch (Exception ex)
            {
                string message = ex.Message + " " + ex.StackTrace;
                return(BadRequest(new { Error = message }));
            }
        }
Esempio n. 20
0
        public TOPModel GetTOP(Guid topId)
        {
            var topTable = GetTOPTable(topId);
            var company  = GetCompany(topTable.Company);
            var address  = GetAddress(topTable.Address);
            var teacher  = GetTeacher(topTable.Teacher);
            var vocationalQualificationUnit = GetVocationalQualificationUnit(topTable.VocationalQualificationUnit);

            TOPModel top = new TOPModel
            {
                PhoneNumber                 = topTable.PhoneNumber,
                EmailAddress                = topTable.EmailAddress,
                Reserved                    = topTable.Reserved,
                ReservationEnds             = topTable.ReservationEnds,
                Accepted                    = topTable.Accepted,
                Info                        = topTable.Info,
                Company                     = company.company,
                Teacher                     = teacher.teacher,
                Address                     = address.address,
                VocationalQualificationUnit = vocationalQualificationUnit.vocationalQualificationUnit
            };

            return(top);
        }
Esempio n. 21
0
 public void Acception(TOPModel top, DataGrid TOPsDataGrid)
 {
     top.Accepted = true;
     UpdateTOP(top, TOPsDataGrid);
 }