private async void DoLogin(PasswordBox pb)
        {
            LoaderManager.Instance.ShowLoader();
            TimerServerClient serv = null;

            try
            {
                serv = new TimerServerClient(StationManager.EndpointName);
                var result = await Task.Run(() =>
                {
                    if (!serv.UserExists(Username, pb.Password))
                    {
                        return(null);
                    }
                    User user    = serv.GetUser(Username, pb.Password);
                    user.Groups  = serv.GetUserGroups(user).ToList();
                    user.Records = serv.GetUserRecords(user).ToList();
                    return(user);
                });


                if (result == null)
                {
                    MessageBox.Show("Oooops. Couldn't find you.");
                    LoaderManager.Instance.HideLoader();
                    return;
                }
                else
                {
                    StationManager.CurrentUser = result;
                    var record = await Task.Run(() => serv.GetUserRecords(result).Where(r => r.EndTime == null).FirstOrDefault());

                    if (record != null)
                    {
                        record.User = result;
                        StationManager.CurRecord = record;
                    }
                    else
                    {
                        Record rec = new Record();
                        rec.User = result;
                        rec.Id   = Guid.NewGuid();
                        StationManager.CurRecord = rec;
                    }
                    LoaderManager.Instance.HideLoader();
                    pb.Clear();
                    NavigationManager.Instance.Navigate(ViewType.MainView);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Ooops, problems with server \n" + e.Message);
                LoaderManager.Instance.HideLoader();
            }
            finally
            {
                serv?.Close();
            }
        }
Beispiel #2
0
        public static void DeleteRecord(Guid guid)
        {
            TimerServerClient serv = null;

            try
            {
                serv = new TimerServerClient(EndpointName);
                serv.DeleteRecords(new Guid[] { guid });
            }
            catch (Exception e)
            {
                MessageBox.Show("Ooops, problems with server \n" + e.Message);
            }
            finally
            {
                serv?.Close();
            }
        }
Beispiel #3
0
        public static void SubmitUpdateRecord(Record record, string[] updateFields)
        {
            TimerServerClient serv = null;

            try
            {
                serv = new TimerServerClient(EndpointName);
                serv.UpdateRecord(record, updateFields);
            }
            catch (Exception e)
            {
                MessageBox.Show("Ooops, problems with server \n" + e.Message);
            }
            finally
            {
                serv?.Close();
            }
        }
Beispiel #4
0
        public static Record GetUnfinishedRecord(User user)
        {
            TimerServerClient serv = null;

            try
            {
                serv = new TimerServerClient(EndpointName);
                var record = serv.GetUserRecords(user).Where(r => r.EndTime == null).FirstOrDefault();
                return(record);
            }
            catch (Exception e)
            {
                MessageBox.Show("Ooops, problems with server \n" + e.Message);
            }
            finally
            {
                serv?.Close();
            }

            return(null);
        }
Beispiel #5
0
        private async void DoSignUp(PasswordBox pb)
        {
            if (!new EmailAddressAttribute().IsValid(Email))
            {
                MessageBox.Show("Email is not correct!");
                return;
            }

            Guid          newId    = Guid.NewGuid();
            UserCandidate userCand = new UserCandidate();

            userCand.Id       = newId;
            userCand.Username = Username;
            userCand.Email    = Email;
            userCand.Password = pb.Password;
            userCand.Name     = Name;
            userCand.Surname  = Surname;

            User user = new User();

            user.Id       = newId;
            user.Username = Username;
            user.Email    = Email;
            user.Name     = Name;
            user.Surname  = Surname;

            LoaderManager.Instance.ShowLoader();
            TimerServerClient serv = null;

            try
            {
                serv = new TimerServerClient(StationManager.EndpointName);
                bool unique = await Task.Run(() =>
                {
                    return(serv.IsUserUnique(Username, Email));
                });

                if (!unique)
                {
                    MessageBox.Show("User with this username or email already exists");
                    LoaderManager.Instance.HideLoader();
                    return;
                }
                else
                {
                    await Task.Run(() =>
                    {
                        serv.AddUser(userCand);
                    });
                }
                LoaderManager.Instance.HideLoader();
                StationManager.CurRecord      = new Record();
                StationManager.CurRecord.User = user;
                StationManager.CurRecord.Id   = Guid.NewGuid();
                user.Groups  = new List <Group>();
                user.Records = new List <Record>();
                StationManager.CurrentUser = user;
                NavigationManager.Instance.Navigate(ViewType.MainView);
            }
            catch (Exception e)
            {
                MessageBox.Show("Ooops, problems with server \n" + e.Message);
                LoaderManager.Instance.HideLoader();
            }
            finally
            {
                serv?.Close();
            }
        }