Example #1
0
        public bool DelElement(object element)
        {
            var controller = element.GetType().Name.Replace("ViewModel", "");

            try
            {
                var response = APIClient.PostRequest($"api/{controller}/DelElement", element);
                if (!response.Result.IsSuccessStatusCode)
                {
                    throw new Exception(APIClient.GetError(response));
                }
                return(true);
            }
            catch (Exception ex)
            {
                JObject message = (JObject)JsonConvert.DeserializeObject(ex.Message);
                throw new Exception(message["ExceptionMessage"].Value <string>());
            }
        }
Example #2
0
 public bool RestoringPassword(string email)
 {
     try
     {
         var response = APIClient.GetRequest($"api/User/RestoringPassword/?email={email}");
         if (!response.Result.IsSuccessStatusCode)
         {
             throw new Exception(APIClient.GetError(response));
         }
         var user = APIClient.GetElement <UserViewModel>(response);
         if (user == null)
         {
             return(false);
         }
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Example #3
0
        public void UpdateRooms()
        {
            try
            {
                var roomResponse = APIClient.GetRequest("api/Room/GetList");

                if (roomResponse.Result.IsSuccessStatusCode)
                {
                    var listRooms = APIClient.GetElement <List <RoomViewModel> >(roomResponse);
                    Rooms = listRooms;
                }
                else
                {
                    throw new Exception(APIClient.GetError(roomResponse));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            RaisePropertyChanged("Rooms");
        }
Example #4
0
        public void UpdateUsers()
        {
            try
            {
                var userResponse = APIClient.GetRequest("api/User/GetList");

                if (userResponse.Result.IsSuccessStatusCode)
                {
                    var listUsers = APIClient.GetElement <List <UserViewModel> >(userResponse);
                    Users = listUsers;
                }
                else
                {
                    throw new Exception(APIClient.GetError(userResponse));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            RaisePropertyChanged("Users");
        }
Example #5
0
 public bool SignIn(string login, string password)
 {
     try
     {
         var response = APIClient.GetRequest($"api/User/SignIn/?login={login}&password={password}");
         if (!response.Result.IsSuccessStatusCode)
         {
             throw new Exception(APIClient.GetError(response));
         }
         var user = APIClient.GetElement <UserViewModel>(response);
         if (user == null)
         {
             return(false);
         }
         CurrentUser = user;
         return(true);
     }
     catch (Exception ex)
     {
         JObject message = (JObject)JsonConvert.DeserializeObject(ex.Message);
         throw new Exception(message["ExceptionMessage"].Value <string>());
     }
 }
Example #6
0
 private void SaveButton_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         var repDays = "";
         foreach (CheckBox cb in CheckBoxContainer.Children)
         {
             if (cb.IsChecked == null)
             {
                 continue;
             }
             if (cb.IsChecked.Value)
             {
                 repDays += "1";
             }
             else
             {
                 repDays += "0";
             }
         }
         var userMeetings = new List <UserMeeting>();
         foreach (UserViewModel user in InvitedUsersListBox.Items)
         {
             if (Meeting.Id > 0)
             {
                 userMeetings.Add(new UserMeeting
                 {
                     UserId    = user.Id,
                     MeetingId = Meeting.Id
                 });
             }
             else
             {
                 userMeetings.Add(new UserMeeting
                 {
                     UserId = user.Id
                 });
             }
         }
         if (Meeting.Id > 0)
         {
             //Изменение
             if (DatePicker.SelectedDate != null &&
                 !string.IsNullOrEmpty(startTimeMaskedTextBox.Text) &&
                 !string.IsNullOrEmpty(durationMaskedTextBox.Text) &&
                 !string.IsNullOrEmpty(TitleTextBox.Text) &&
                 !string.IsNullOrEmpty(SubjTextBox.Text) &&
                 !string.IsNullOrEmpty(DescriptionTextBox.Text))
             {
                 if (DatePicker.SelectedDate.Value + DateTime.Parse(startTimeMaskedTextBox.Text).TimeOfDay <= DateTime.Now)
                 {
                     MessageBox.Show("Время, на которое Вы хотите назвачить мероприятие, уже прошло", "Ошибка", MessageBoxButton.OK);
                     return;
                 }
                 var response = APIClient.PostRequest("api/Meeting/UpdElement", new Meeting
                 {
                     Id                 = Meeting.Id,
                     MeetingName        = TitleTextBox.Text,
                     MeetingTheme       = SubjTextBox.Text,
                     MeetingDescription = DescriptionTextBox.Text,
                     StartTime          = DatePicker.SelectedDate.Value + DateTime.Parse(startTimeMaskedTextBox.Text).TimeOfDay,
                     EndTime            = DatePicker.SelectedDate.Value + DateTime.Parse(startTimeMaskedTextBox.Text).TimeOfDay +
                                          DateTime.Parse(durationMaskedTextBox.Text).TimeOfDay,
                     UserMeetings  = userMeetings,
                     RoomId        = Data.CurrentRoom.Id,
                     CreatorId     = Data.CurrentUser.Id,
                     RepeatingDays = repDays
                 });
                 MessageBox.Show("Изменено", "Успех", MessageBoxButton.OK);
             }
         }
         else
         {
             //Добавление
             if (DatePicker.SelectedDate != null &&
                 !string.IsNullOrEmpty(startTimeMaskedTextBox.Text) &&
                 !string.IsNullOrEmpty(durationMaskedTextBox.Text) &&
                 !string.IsNullOrEmpty(TitleTextBox.Text) &&
                 !string.IsNullOrEmpty(SubjTextBox.Text) &&
                 !string.IsNullOrEmpty(DescriptionTextBox.Text))
             {
                 if (DatePicker.SelectedDate.Value + DateTime.Parse(startTimeMaskedTextBox.Text).TimeOfDay <= DateTime.Now)
                 {
                     MessageBox.Show("Время, на которое Вы хотите назвачить мероприятие, уже прошло", "Ошибка", MessageBoxButton.OK);
                     return;
                 }
                 Data.AddElement(new Meeting
                 {
                     MeetingName        = TitleTextBox.Text,
                     MeetingTheme       = SubjTextBox.Text,
                     MeetingDescription = DescriptionTextBox.Text,
                     StartTime          = DatePicker.SelectedDate.Value + DateTime.Parse(startTimeMaskedTextBox.Text).TimeOfDay,
                     EndTime            = DatePicker.SelectedDate.Value + DateTime.Parse(startTimeMaskedTextBox.Text).TimeOfDay +
                                          DateTime.Parse(durationMaskedTextBox.Text).TimeOfDay,
                     UserMeetings  = userMeetings,
                     RoomId        = Data.CurrentRoom.Id,
                     CreatorId     = Data.CurrentUser.Id,
                     RepeatingDays = repDays
                 });
             }
             MessageBox.Show("Добавлено", "Успех", MessageBoxButton.OK);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OKCancel);
         return;
     }
     DialogResult = true;
     Close();
 }
Example #7
0
        public ProfileWindow(DataSamples data)
        {
            InitializeComponent();
            Data                   = data;
            FIOTextBox.Text        = Data.CurrentUser.UserFIO;
            CurrentFIO             = Data.CurrentUser.UserFIO;
            FIOTextBox.Focusable   = false;
            FIOTextBox.IsEnabled   = false;
            LoginTextBox.Text      = Data.CurrentUser.UserLogin;
            CurrentLogin           = Data.CurrentUser.UserLogin;
            LoginTextBox.Focusable = false;
            LoginTextBox.IsEnabled = false;
            EmailTextBox.Text      = Data.CurrentUser.UserMail;
            CurrentEmail           = Data.CurrentUser.UserMail;
            Password               = Data.CurrentUser.UserPassword;
            EmailTextBox.Focusable = false;
            EmailTextBox.IsEnabled = false;

            PasswordTextBox.Focusable        = false;
            PasswordTextBox.IsEnabled        = false;
            PasswordConfirmTextBox.IsEnabled = false;
            PasswordConfirmTextBox.Focusable = false;


            try
            {
                var response = APIClient.GetRequest("api/Meeting/GetListUserCreatedMeetings/" + Data.CurrentUser.Id);
                if (response.Result.IsSuccessStatusCode)
                {
                    var list = APIClient.GetElement <List <MeetingViewModel> >(response);
                    if (list != null)
                    {
                        Data.UserMeetings = list;
                    }
                }
                else
                {
                    throw new Exception(APIClient.GetError(response));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            MeetingsListBoxCreated.ItemsSource = Data.UserMeetings;


            try
            {
                var response = APIClient.GetRequest("api/Meeting/GetListUserInvites/" + Data.CurrentUser.Id);
                if (response.Result.IsSuccessStatusCode)
                {
                    var list = APIClient.GetElement <List <MeetingViewModel> >(response);
                    if (list != null)
                    {
                        Data.UserMeetings = list;
                    }
                }
                else
                {
                    throw new Exception(APIClient.GetError(response));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            MeetingsListBoxInvited.ItemsSource = Data.UserMeetings;
        }
Example #8
0
        private void ChangeProfileButton_Click(object sender, RoutedEventArgs e)
        {
            if (ChangeProfileButton.Content.ToString() == "Редактировать")
            {
                FIOTextBox.Focusable   = true;
                FIOTextBox.IsEnabled   = true;
                LoginTextBox.Focusable = true;
                LoginTextBox.IsEnabled = true;
                EmailTextBox.Focusable = true;
                EmailTextBox.IsEnabled = true;

                PasswordTextBox.Focusable        = true;
                PasswordTextBox.IsEnabled        = true;
                PasswordConfirmTextBox.IsEnabled = true;
                PasswordConfirmTextBox.Focusable = true;
                ChangeProfileButton.Content      = "Сохранить изменения";
            }
            else
            {
                string changed = ""; //выведем пользователю те поля, которые были изменены. изменяются только те поля, которые он ввёл в соответствующие текстбоксы
                var    user    = Data.CurrentUser;



                if (PasswordTextBox.Password != "")
                {
                    if (PasswordTextBox.Password == PasswordConfirmTextBox.Password)
                    {
                        user.UserPassword = Data.GetHashString(PasswordTextBox.Password);
                        changed          += " Пароль; ";
                    }
                    else
                    {
                        MessageBox.Show("Введённые пароли не совпадают", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                }
                else
                {
                    user.UserPassword = Password;
                }
                if (FIOTextBox.Text != CurrentFIO)
                {
                    user.UserFIO = FIOTextBox.Text;
                    changed     += " ФИО; ";
                }
                if (LoginTextBox.Text != CurrentLogin)
                {
                    user.UserLogin = LoginTextBox.Text;
                    changed       += " Логин; ";
                }
                if (EmailTextBox.Text != CurrentEmail)
                {
                    user.UserMail = EmailTextBox.Text;
                    changed      += " E-mail; ";
                }
                try
                {
                    var response = APIClient.PostRequest("api/User/UpdElement", user);

                    if (!response.Result.IsSuccessStatusCode)
                    {
                        throw new Exception(APIClient.GetError(response));
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                MessageBox.Show(changed + " были обновлены", "Успешно изменено", MessageBoxButton.OK);

                ChangeProfileButton.Content      = "Редактировать";
                FIOTextBox.Focusable             = false;
                LoginTextBox.Focusable           = false;
                EmailTextBox.Focusable           = false;
                PasswordTextBox.Focusable        = false;
                PasswordConfirmTextBox.Focusable = false;
            }
        }