예제 #1
0
        //public ObservableCollection<Activity_Location> ActivityLocation { get; private set; }


        private async void Quit()
        {
            bool            isNotEntered = true;
            List <User_Log> userLogged;
            User_Log        current  = null;
            int             userQuit = 0;

            var queue = await App.MobileService.GetTable <User_Entered>().Where(p => p.Activity_Code_FK2 == selectedActivity.Id).ToListAsync();

            var userStr = await App.MobileService.GetTable <Entered_History>().Where(p => p.Activity_Code_FK2 == selectedActivity.Id).ToListAsync();

            if (queue.Count > 0)
            {
                for (int i = 0; i < queue.Count; i++)
                {
                    userLogged = await App.MobileService.GetTable <User_Log>().Where(p => p.Id == queue[i].User_Log_Id_FK1 && (p.User_LogType_Id_FK1 == "4" || p.User_LogType_Id_FK1 == "3")).ToListAsync();

                    if (userLogged[0].User_Id_FK2.Equals(userJoining[0].Id))
                    {
                        userQuit = i;
                        current  = new User_Log
                        {
                            Id                  = userLogged[0].Id,
                            LogDateTime         = DateTime.Now,
                            User_Id_FK2         = userLogged[0].User_Id_FK2,
                            Activity_code       = selectedActivity.Id,
                            User_Equipment_code = userLogged[0].User_Equipment_code,
                            User_LogType_Id_FK1 = "5"                             // quit activity
                        };
                        isNotEntered = false;
                    }
                }
            }

            if (!isNotEntered)
            {
                Entered_History entered = null;
                try
                {
                    if (!queue[userQuit].IsCreator)
                    {
                        await App.MobileService.GetTable <User_Log>().UpdateAsync(current);

                        entered = new Entered_History
                        {
                            Id = queue[userQuit].Id,
                            Activity_Code_FK2 = queue[userQuit].Activity_Code_FK2,
                            Status            = "Aborting",
                            IsCreator         = queue[userQuit].IsCreator,
                            UserJoin          = userJoining[0].Id,
                            UserCreator       = userCreatorActivity[0].Id,
                        };
                        await App.MobileService.GetTable <Entered_History>().UpdateAsync(entered);

                        await App.MobileService.GetTable <User_Entered>().DeleteAsync(queue[userQuit]);

                        entered = null;
                        await Application.Current.MainPage.DisplayAlert("Success", " You are now out of the activity", "Ok");

                        getFileUserEntry();
                    }
                    else
                    {
                        await App.MobileService.GetTable <User_Log>().UpdateAsync(current);

                        if (queue.Count > 1)
                        {
                            for (int i = 0; i < queue.Count; i++)
                            {
                                entered = new Entered_History
                                {
                                    Id = queue[i].Id,
                                    Activity_Code_FK2 = queue[i].Activity_Code_FK2,
                                    Status            = "Out",
                                    IsCreator         = queue[i].IsCreator,
                                    UserJoin          = userStr[i].UserJoin,
                                    UserCreator       = userCreatorActivity[0].Id,
                                };
                                await App.MobileService.GetTable <Entered_History>().UpdateAsync(entered);

                                await App.MobileService.GetTable <User_Entered>().DeleteAsync(queue[i]);

                                entered = null;
                            }
                        }
                        else
                        {
                            entered = new Entered_History
                            {
                                Id = queue[0].Id,
                                Activity_Code_FK2 = queue[0].Activity_Code_FK2,
                                Status            = "Out",
                                IsCreator         = queue[0].IsCreator,
                                UserJoin          = userJoining[0].Id,
                                UserCreator       = userCreatorActivity[0].Id,
                            };
                            await App.MobileService.GetTable <Entered_History>().UpdateAsync(entered);

                            await App.MobileService.GetTable <User_Entered>().DeleteAsync(queue[0]);

                            entered = null;
                        }



                        await App.MobileService.GetTable <Activity>().DeleteAsync(selectedActivity);

                        await Application.Current.MainPage.DisplayAlert("Success", " You are deleted the activity", "Ok");

                        MainViewModel.GetInstance().Activity_Child = new ActivityViewModel(userCreatorActivity);
                        await Application.Current.MainPage.Navigation.PushAsync(new ActivityPage());
                    }
                }
                catch (Exception ex)
                {
                    await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "Ok");

                    return;
                }
            }
            else
            {
                await Application.Current.MainPage.DisplayAlert("Error", "You are not on the lobby", "Ok");

                return;
            }
            getFileUserEntry();
        }
예제 #2
0
        private async void Join()
        {
            var queue = await App.MobileService.GetTable <User_Entered>().Where(p => p.Activity_Code_FK2 == selectedActivity.Id && !p.IsCreator).ToListAsync();

            if (queue.Count > 0)
            {
                for (int i = 0; i < queue.Count; i++)
                {
                    var userLogged = await App.MobileService.GetTable <User_Log>().Where(p => p.Id == queue[i].User_Log_Id_FK1 && p.User_LogType_Id_FK1 == "4").ToListAsync();

                    if (userLogged[0].User_Id_FK2.Equals(userJoining[0].Id))
                    {
                        await Application.Current.MainPage.DisplayAlert(
                            "Error",
                            "You are in the lobby",
                            "Accept");

                        return;
                    }
                }
            }

            int len     = RandomId.length.Next(5, 10);
            var userLog = new User_Log
            {
                Id                  = RandomId.RandomString(len),
                LogDateTime         = DateTime.Today,
                User_LogType_Id_FK1 = logtypeJoin,
                User_Equipment_code = equipment.Id,
                Activity_code       = selectedActivity.Id,
                User_Id_FK2         = userJoining[0].Id
            };
            User_Entered entry = new User_Entered()
            {
                Id                = RandomId.RandomString(len),
                Status            = "in",
                IsCreator         = false,
                User_Log_Id_FK1   = userLog.Id,
                Activity_Code_FK2 = selectedActivity.Id
            };
            Entered_History entryHistory = new Entered_History()
            {
                Id                = entry.Id,
                Status            = "in",
                IsCreator         = false,
                Activity_Code_FK2 = selectedActivity.Id,
                UserJoin          = userJoining[0].Id,
                UserCreator       = userCreatorActivity[0].Id
            };

            if (userJoining[0].Id.Equals(userCreatorActivity[0].Id))
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "You are the Creator!!",
                    "Accept");

                return;
            }

            try
            {
                await App.MobileService.GetTable <User_Log>().InsertAsync(userLog);

                await App.MobileService.GetTable <User_Entered>().InsertAsync(entry);

                await App.MobileService.GetTable <Entered_History>().InsertAsync(entryHistory);

                getFileUserEntry();
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "Ok");

                return;
            }
            await Application.Current.MainPage.DisplayAlert("Success", " You are now on the queue", "Ok");
        }
예제 #3
0
        private async void CreateActivity()
        {
            CheckConnectionInternet.checkConnectivity();

            //if ((this.StartDay.Date + this.StartHour) < DateTime.Now)
            //{
            //    await Application.Current.MainPage.DisplayAlert(
            //        "Message",
            //        "Past date is not allowed.",
            //        "Ok");
            //    return;
            //}

            //if (this.StartDay.Date + this.StartHour > this.FinishDay.Date + this.FinishHour)
            //{
            //    await Application.Current.MainPage.DisplayAlert(
            //        "Message",
            //        "The Start Date is greater than Finish Date",
            //        "Ok");
            //    this.FinishDay = this.StartDay;
            //    this.FinishHour = this.StartHour;
            //    return;

            //}
            ValidateDatetime();

            if (string.IsNullOrEmpty(this.ActivityName))
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "You must enter an Activity Name.",
                    "Accept");

                return;
            }
            if (string.IsNullOrEmpty(this.Description))
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "You must enter a description.",
                    "Accept");

                return;
            }
            if (SelectedCategory == null)
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "You must select a Category.",
                    "Accept");

                return;
            }


            if (loc == null)
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "You must select a Location.",
                    "Accept");

                return;
            }

            if ((this.StartDay.Date + this.StartHour) < DateTime.Now)
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Message",
                    "Past date is not allowed.",
                    "Ok");

                this.StartHour = DateTime.Now.TimeOfDay;
                return;
            }


            string[] addrSplit = this.Placename.Split(',');
            for (int i = 0; i < addrSplit.Length; i++)
            {
                addrSplit[i] = addrSplit[i].Trim();
            }
            int len = RandomId.length.Next(5, 10);
            Activity_Location activity_location = new Activity_Location()
            {
                Id        = RandomId.RandomString(len),
                Nameplace = addrSplit[0],
                City      = addrSplit.Length == 5 ? addrSplit[2] : addrSplit[1],
                State     = "PR",//Cambiarlo luego con IF dinamico
                Country   = addrSplit.Length == 5 ? addrSplit[4] : addrSplit[3],
                ZipCode   = addrSplit.Length == 5 ? addrSplit[3] : addrSplit[2],
                IsSecure  = false,
                Latitude  = (decimal)this.loc.Latitude,
                Longitude = (decimal)this.loc.Longitude,
                CreatorOriginalPinLatitude  = (decimal)this.origLoc.Latitude,
                CreatorOriginalPinLongitude = (decimal)this.origLoc.Longitude
            };

            try
            {
                //find duplicate
                var query = await App.MobileService.GetTable <Activity_Location>().Where(
                    p => p.Nameplace == activity_location.Nameplace &&
                    p.City == activity_location.City &&
                    p.ZipCode == activity_location.ZipCode
                    ).ToListAsync();

                if (query.Count == 0)
                {
                    await App.MobileService.GetTable <Activity_Location>().InsertAsync(activity_location);
                }
                else
                {
                    var location = query?.FirstOrDefault();
                    activity_location.Id = location.Id;
                }
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "Ok");
            }

            Activity activity = new Activity()
            {
                Id                 = RandomId.RandomString(len),
                Name               = this.ActivityName,
                Created_Date       = DateTime.Now,
                IsPrivate          = false,//todo
                Start_Act_Datetime = this.StartDay.Date + this.StartHour,
                End_Act_Datetime   = this.FinishDay.Date + this.FinishHour,
                Description        = this.Description.TrimEnd().TrimStart(),
                Status             = 1,//check
                IsService          = this.IsService,
                Activity_Cat_Code  = SelectedCategory.Id,
                Activity_Loc_Id    = activity_location.Id
            };

            //ctivity history
            Activity_History activityHistory = new Activity_History()
            {
                Id = RandomId.RandomString(len),
                Activity_Code_Id   = activity.Id,
                Name               = this.ActivityName,
                Created_Date       = DateTime.Now,
                IsPrivate          = false,//todo
                Start_Act_Date     = this.StartDay.Date + this.StartHour,
                End_Act_Date       = this.FinishDay.Date + this.FinishHour,
                Description        = this.Description,
                Status             = 1,//check
                IsService          = this.IsService,
                Activity_Cat_code  = SelectedCategory.Id,
                Activity_Loc_Id_FK = activity_location.Id
            };

            userCreating = User_LogType.userLogTypesAsync(userQuery[0].Id, usLog);
            User_Entered entry = new User_Entered()
            {
                Id                = RandomId.RandomString(len),
                Status            = "in",
                IsCreator         = true,
                User_Log_Id_FK1   = userCreating.Id,
                Activity_Code_FK2 = activityHistory.Activity_Code_Id
            };
            Entered_History entryHistory = new Entered_History()
            {
                Id                = entry.Id,
                Status            = "in",
                IsCreator         = true,
                Activity_Code_FK2 = activityHistory.Activity_Code_Id,
                UserJoin          = userQuery[0].Id,
                UserCreator       = userQuery[0].Id
            };

            try
            {
                await App.MobileService.GetTable <Activity>().InsertAsync(activity);

                await App.MobileService.GetTable <Activity_History>().InsertAsync(activityHistory);

                await App.MobileService.GetTable <User_Log>().InsertAsync(userCreating);

                await App.MobileService.GetTable <User_Entered>().InsertAsync(entry);

                await App.MobileService.GetTable <Entered_History>().InsertAsync(entryHistory);
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "Ok");
            }

            MainViewModel.GetInstance().Activity_Child = new ActivityViewModel(userQuery, entry);
            await Application.Current.MainPage.Navigation.PushAsync(new ActivityPage());
        }