async Task GetUserEmployeeInformation() { //Obtine los empleos del usuario. var userEmployees = await EmployeeDataStore.GetUserEmployees(App.LogUser.UserId.ToString()); UserStoreEmployee = new ObservableCollection <Store>(); foreach (var item in userEmployees) { //Obtine el empleado item.EmployeeStore = await StoreDataStore.GetAvailableStoreInformation(item.StoreId); if (item.EmployeeStore != null) { var empWorkHours = await EmployeeWorkHour.GetEmployeeWorkHours(item.EmployeeId.ToString()); item.EmployeeWorkHours = empWorkHours.ToList(); var storePresenter = new StorePresenters(item.EmployeeStore); StorePresenters.Add(storePresenter); } //UserStoreEmployee.Add(item.EmployeeStore); } App.LogUser.Employees = userEmployees.ToList(); }
public SearchEmployeePresenter(UserDTO userDTO, string storeId) { this.UserId = userDTO.UserId; this.Name = userDTO.Name; this.Phone = userDTO.Phone; this.Gender = userDTO.Gender.ToString(); this.Email = userDTO.Phone; this.RequestToStore = Guid.Parse(storeId); SendRequestCommand = new Command(async() => { bool isEmployee = await EmployeeDataStore.IsEmployeeFromStore(RequestToStore, UserId); if (!isEmployee) { var jobRequest = new UserRequest() { RequestId = Guid.NewGuid(), FromStore = RequestToStore, ToUser = UserId, Type = RequestType.JobRequest, RequestAnswer = Answer.None }; var userhaveOrder = RequestDataStore.UserRequestExists(UserId, RequestToStore); if (!userhaveOrder) { var result = await RequestDataStore.AddItemAsync(jobRequest); var userhubconnectionResult = await userConnectedDataStore.GetUserConnectedID(jobRequest.ToUser); if (userhubconnectionResult != null) { await App.ComunicationService.SendRequestToUser(userhubconnectionResult.HubConnectionID, jobRequest); } } else { await Shell.Current.DisplayAlert("Notification", "Request was sended is waiting for response.", "OK"); } } else { await Shell.Current.DisplayAlert("Notification", "Is Employee", "OK"); } }); }
public RequestPresenter(UserRequest userRequest) { RequestId = userRequest.RequestId; var store = GetStore(userRequest.FromStore.ToString()); if (userRequest.Type == RequestType.JobRequest) { RequestTitle = store.Result.StoreName + " Send Job Request"; } RequestAnswerCommand = new Command <string>(async(e) => { if (Answer.Accept.ToString() == e) { userRequest.RequestAnswer = Answer.Accept; var requestUpdated = await requestDataStore.UpdateItemAsync(userRequest); if (requestUpdated) { MessagingCenter.Send <RequestPresenter>(this, "RefreshInbox"); var newStoreEmployee = new Employee() { EmployeeId = Guid.NewGuid(), UserId = userRequest.ToUser, StoreId = userRequest.FromStore, Type = EmployeeType.New }; var employeeAdded = await EmployeeDataStore.AddItemAsync(newStoreEmployee); } } if (Answer.Decline.ToString() == e) { //userRequest.RequestAnswer = Answer.Decline; //var requestUpdated = await requestDataStore.UpdateItemAsync(userRequest); //MessagingCenter.Send<RequestPresenter>(this, "RefreshInbox"); var deleted = await requestDataStore.DeleteItemAsync(RequestId.ToString()); MessagingCenter.Send <RequestPresenter>(this, "RefreshInbox"); } }); }
public async Task GetEmployeeDataOfStore(string storeId) { Guid storeGuidId = new Guid(storeId); var employeesData = await EmployeeDataStore.GetEmployeesOfStore(storeGuidId); if (Employees.Count > 0) { Employees.Clear(); } foreach (var item in employeesData) { var user = await userDataStore.GetItemAsync(item.UserId.ToString()); var workhours = await EmployeeWorkHour.GetEmployeeWorkHours(item.EmployeeId.ToString()); item.EmployeeUser = user; item.EmployeeWorkHours = OrderingEmpWorkHour(workhours.ToList()); var employeePresenter = new StoreEmployeesPresenter(item); Employees.Add(employeePresenter); } }
//Obtiene la informacion de horas de trabajos async void GetWorkHourSchedule() { StoreEmployee = await EmployeeDataStore.GetSpecificStoreEmployee(App.LogUser.UserId, Store.StoreId); var empWorkHour = await EmployeeWorkHour.GetEmployeeWorkHours(StoreEmployee.EmployeeId.ToString()); empWorkHour = OrderingEmpWorkHour(empWorkHour.ToList()); if (empWorkHour.Count() > 0) { EmpWorkHour.Clear(); foreach (var item in empWorkHour) { if (item != null) { if (item.WillWork) { EmpWorkHour.Add(item); } } } } }
public LoginViewModel(INavigation _navigation) { Navigation = _navigation; popupNavigation = PopupNavigation.Instance; Task.Run(async() => { Username = await SecureStorage.GetAsync("username"); Password = await SecureStorage.GetAsync("password"); }); ValidatorsInitializer(); //App.ComunicationService = new ComunicationService(); Genders = new List <string>(Enum.GetNames(typeof(Gender)).ToList()); IsLoading = false; LoginCommand = new Command(async() => { //var currentuserID = Xamarin.Forms.Application.Current.Properties["loginId "].ToString(); IsLoading = true; if (!string.IsNullOrEmpty(Username) && !string.IsNullOrEmpty(Password)) { //Verifica si el telefono tiene acceso a internet if (Connectivity.NetworkAccess == NetworkAccess.Internet) { //Obtine los credenciales del usuario //var loginresult = userDataStore.CheckUserCredential(Username, Password); //Obtiene el token de acceso App.TokenDto = userDataStore.LoginCredential(Username, Password); var loginresult = App.TokenDto.UserDetail; //Verifica si el resultado del login no es vacio. if (loginresult != null) { if (!loginresult.IsValidUser) { App.LogUser = loginresult; await popupNavigation.PushAsync(new ValidateEmailCode()); IsLoading = false; } else { Task.Run(async() => { await App.ComunicationService.Connect(); }).Wait(); App.LogUser = loginresult; bool hasPaymentCard = App.LogUser.PaymentCards.Count() > 0 ? true : false; //Verfico si hay tarjetas registradas con el usuario if (hasPaymentCard) { var data = App.LogUser.PaymentCards; var card = new List <PaymentCard>(data); var userCardTokenId = await stripeServiceDS.GetCustomerCardId(App.LogUser.StripeUserId, card[0].StripeCardId); App.CardPaymentToken.CardTokenId = userCardTokenId; } if (!String.IsNullOrEmpty(App.ComunicationService.hubConnection.ConnectionId)) { App.UsersConnected = new UsersConnected() { HubConnectionID = App.ComunicationService.hubConnection.ConnectionId, UserID = App.LogUser.UserId, IsDisable = false, ConnecteDate = DateTime.Now }; var result = await userConnectedDataStore.ModifyOldConnections(App.UsersConnected); var hub_connected_Result = await userConnectedDataStore.AddItemAsync(App.UsersConnected); } App.Current.MainPage = new AppShell(); IsLoading = false; } } else { IsLoading = false; await App.Current.MainPage.DisplayAlert("Notification", "Incorrect login...!", "OK"); } } } else { IsLoading = false; await App.Current.MainPage.DisplayAlert("Notification", "Empty values...!", "OK"); } }); LoginEmployeeCommand = new Command(async() => { IsLoading = true; if (!string.IsNullOrEmpty(Username) && !string.IsNullOrEmpty(Password)) { //var loginresult = userDataStore.CheckUserCredential(Username, Password); App.TokenDto = userDataStore.LoginCredential(Username, Password); var loginresult = App.TokenDto.UserDetail; if (loginresult != null) { Task.Run(async() => { await App.ComunicationService.Connect(); }).Wait(); var userEmployees = await EmployeeDataStore.GetUserEmployees(loginresult.UserId.ToString()); App.LogUser = loginresult; if (!String.IsNullOrEmpty(App.ComunicationService.hubConnection.ConnectionId)) { App.UsersConnected = new UsersConnected() { HubConnectionID = App.ComunicationService.hubConnection.ConnectionId, UserID = App.LogUser.UserId, IsDisable = false, ConnecteDate = DateTime.Now }; var result = await userConnectedDataStore.ModifyOldConnections(App.UsersConnected); var hub_connected_Result = await userConnectedDataStore.AddItemAsync(App.UsersConnected); } //App.UsersConnected = new UsersConnected() //{ // HubConnectionID = App.ComunicationService.hubConnection.ConnectionId, // UserID = App.LogUser.UserId, // IsDisable = false, // ConnecteDate = DateTime.Now //}; //var result = await userConnectedDataStore.ModifyOldConnections(App.UsersConnected); //var hub_connected_Result = await userConnectedDataStore.AddItemAsync(App.UsersConnected); App.Current.MainPage = new EmployeeShell(); IsLoading = false; } else { await App.Current.MainPage.DisplayAlert("Notification", "Incorrect login.", "OK"); } } else { await App.Current.MainPage.DisplayAlert("Notification", "Empty inputs.", "OK"); } }); RegisterCommand = new Command(async() => { await App.Current.MainPage.Navigation.PushAsync(new RegisterPage()); }); DoneCommand = new Command(async() => { SetValidatorValues(); //Verficamos que las propiedades esten de con la informacion correcta y llenas. if (!UsernameValidator.HasError && !FullNameValidator.HasError && !PhoneValidator.HasError && !AddressValidator.HasError && !PasswordValidator.HasError && !ConfirmPasswordValidator.HasError && !EmailValidator.HasError && !GenderValidator.HasError && !EmailPatternValidator.HasError) { if (!await userDataStore.EmailExist(Email)) { ConfirmAndPasswordValidator = ValidatorRules.PasswordAndConfirmPasswordEquals(Password, ConfirmPassword); //Verificamos que el password y el confirmpassword matcheen if (!ConfirmAndPasswordValidator.HasError) { //Si el username y password existen tendra que reinsertar esa informacion if (!await userDataStore.CheckIfUsernameAndPasswordExist(Username, Password)) { var userlogin = new Login() { LoginId = Guid.NewGuid(), IsConnected = false, Password = Password, Username = Username }; Gender value; Enum.TryParse(GenderSelected, out value); var newUser = new User() { UserId = Guid.NewGuid(), Email = Email, Name = Fullname, LoginId = userlogin.LoginId, Phone = Phone, Address = Address, Gender = value, UserLogin = userlogin, }; userlogin.UserId = newUser.UserId; try { var optionsCustomers = new UserDTO { Name = Fullname, Email = Email, Phone = Phone, Address = Address }; //Create Customer var customertokenId = await stripeServiceDS.CreateStripeCustomer(optionsCustomers); if (!string.IsNullOrEmpty(customertokenId)) { Task.Run(async() => { await App.ComunicationService.Connect(); }).Wait(); newUser.StripeUserId = customertokenId; var result = await userDataStore.AddItemAsync(newUser); //var credentialsResult = userDataStore.CheckUserCredential(Username, Password); App.TokenDto = userDataStore.LoginCredential(Username, Password); if (result) { App.LogUser = App.TokenDto.UserDetail; if (!String.IsNullOrEmpty(App.ComunicationService.hubConnection.ConnectionId)) { App.UsersConnected = new UsersConnected() { HubConnectionID = App.ComunicationService.hubConnection.ConnectionId, UserID = App.LogUser.UserId, IsDisable = false, ConnecteDate = DateTime.Now }; //var oldConnectionModify = await userConnectedDataStore.ModifyOldConnections(App.UsersConnected); var hub_connected_Result = await userConnectedDataStore.AddItemAsync(App.UsersConnected); } try { await SecureStorage.SetAsync("username", Username); await SecureStorage.SetAsync("password", Password); } catch (Exception ex) { // Possible that device doesn't support secure storage on device. } await popupNavigation.PushAsync(new RegisterValidationEmail()); } } } catch (Exception e) { await App.Current.MainPage.DisplayAlert("Notification", e.Message, "OK"); } } else { await App.Current.MainPage.DisplayAlert("Notification", "Username or password exist try to change to other one.", "OK"); } } } else { await App.Current.MainPage.DisplayAlert("Notification", "Email is in used.", "OK"); } } else { await App.Current.MainPage.DisplayAlert("Notification", "Some error ocurred check the information.", "OK"); } }); GoForgotPasswordCommand = new Command(async() => { await App.Current.MainPage.Navigation.PushAsync(new ForgotPasswordPage()); }); }
public StoreEmployeeEditViewModel() { MessagingCenter.Subscribe <Employee>(this, "EmpEdit", (sender) => { EmpDetail = sender; }); #region Initialize Positions Collection Positions = new ObservableCollection <string>(); foreach (var item in Enum.GetValues(typeof(EmployeeType)).Cast <EmployeeType>().ToList()) { Positions.Add(item.ToString()); } #endregion #region WorkHourPresenter Initialize WorkHourPresenters = new ObservableCollection <WorkHourPresenter>(); WorkHourPresenters.Add(new WorkHourPresenter(DayOfWeek.Monday.ToString())); WorkHourPresenters.Add(new WorkHourPresenter(DayOfWeek.Tuesday.ToString())); WorkHourPresenters.Add(new WorkHourPresenter(DayOfWeek.Wednesday.ToString())); WorkHourPresenters.Add(new WorkHourPresenter(DayOfWeek.Thursday.ToString())); WorkHourPresenters.Add(new WorkHourPresenter(DayOfWeek.Friday.ToString())); WorkHourPresenters.Add(new WorkHourPresenter(DayOfWeek.Saturday.ToString())); WorkHourPresenters.Add(new WorkHourPresenter(DayOfWeek.Sunday.ToString())); #endregion CompleteEditCommand = new Command(async() => { List <EmployeeWorkHour> employeeWorkHour = new List <EmployeeWorkHour>(); foreach (var item in WorkHourPresenters) { var workhour = new EmployeeWorkHour() { CloseTime = Convert.ToDateTime(item.Close.ToString()), Day = item.Day, OpenTime = Convert.ToDateTime(item.Open.ToString()), WorkHourId = Guid.NewGuid(), EmpId = empDetail.EmployeeId, WillWork = item.WillWork }; employeeWorkHour.Add(workhour); } EmpDetail.EmployeeWorkHours = employeeWorkHour; EmployeeType type; Enum.TryParse(SelectedPosisition, out type); EmpDetail.Type = type; var empUpdateResult = await EmployeeDataStore.UpdateItemAsync(empDetail); if (empUpdateResult) { await Shell.Current.DisplayAlert("Notification", "Employee Update", "OK"); //await Shell.Current.GoToAsync($"..?id={StoreControlPanelViewModel.YourSelectedStore.StoreId.ToString()}"); } }); }