Beispiel #1
0
        public async Task <IdentityResult> CreateDriverUserAsync(DriverRegisterViewModel model)
        {
            Company company = _context.Companies.SingleOrDefault(c => c.Team.ID == Convert.ToInt32(model.DriverTeamId));
            var     user    = new DriverUser {
                UserName = model.Email, Email = model.Email, CompanyID = company.ID
            };
            var result = await _userManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                await _userManager.AddToRoleAsync(user, AppRole.DRIVER);
                await ConfirmUserEmail(user);

                var driverRegistrationRequest = _context.DriverRegistrationRequests.SingleOrDefault(m => m.DriverEmail == model.Email);
                var teamIdForDriver           = driverRegistrationRequest.TeamID.ToString();
                await CreateDriverEntity(user, teamIdForDriver);
            }
            return(result);
        }
Beispiel #2
0
        private async Task CreateDriverEntity(DriverUser user, string teamId)
        {
            var driverEntity = new Driver();

            driverEntity.User = user;
            int idInt = Convert.ToInt32(teamId);

            _context.Drivers.Add(driverEntity);
            var company = _context.Companies.
                          Include(c => c.Team)
                          .ThenInclude(t => t.Drivers)
                          .SingleOrDefault(c => c.ID == user.CompanyID);
            Company userCompany = _context.Companies.Where(c => c.ID == user.CompanyID).First();
            var     team        = userCompany.Team;

            team.Drivers.Add(driverEntity);
            var completedDriverRequest = await _context.DriverRegistrationRequests.SingleOrDefaultAsync(m => m.DriverEmail == user.Email);

            _context.DriverRegistrationRequests.Remove(completedDriverRequest);
            await _context.SaveChangesAsync();
        }
        private async void DriverRegisterCommand(object sender, EventArgs e)
        {
            Active.IsRunning = true;
            var location = await Geolocation.GetLocationAsync();

            Settings.LastLat = location.Latitude.ToString();
            Settings.LastLng = location.Longitude.ToString();
            var device = DeviceInfo.Model;

            if (AllNeeded() == true)
            {
                GetFirbasetoken();
                UserService userService = new UserService();
                DriverUser  _driveruser = new DriverUser
                {
                    email          = EmailEntry.Text,
                    name           = NameEntry.Text,
                    phone          = PhoneEntry.Text,
                    password       = passwordEntry.Text,
                    confirmpass    = confirmpassEntry.Text,
                    country        = CountryEntry.Text,
                    city           = CityEntry.Text,
                    firebase_token = Settings.UserFirebaseToken,
                    nationality    = nationalityEntry.Text,
                    national       = Settings.Residentid.ToString(),
                    device_id      = Settings.LastSignalID,
                    age            = AgeEntry.Text,
                    carmodal       = Settings.CarModelID,
                    cartype        = Settings.cartype.ToString(),
                    //denominationnumber = denominationnumberimg,
                    //passportnumber = passportnumber.Text,
                    carnumber = CarNumberEntry.Text,
                    idnumber  = IdNumberEntry.Text,
                    type      = Settings.Type.ToString(),
                    load      = loadEntry.Text,
                    lat       = Settings.LastLat,
                    lng       = Settings.LastLng
                };

                StringContent name           = new StringContent(_driveruser.name);
                StringContent phone          = new StringContent(_driveruser.phone);
                StringContent email          = new StringContent(_driveruser.email);
                StringContent password       = new StringContent(_driveruser.password);
                StringContent confirmpass    = new StringContent(_driveruser.confirmpass);
                StringContent country        = new StringContent(_driveruser.country);
                StringContent city           = new StringContent(_driveruser.city);
                StringContent cartype        = new StringContent(_driveruser.cartype);
                StringContent carmodal       = new StringContent(_driveruser.carmodal);
                StringContent carnumber      = new StringContent(_driveruser.carnumber);
                StringContent device_id      = new StringContent(_driveruser.device_id);
                StringContent age            = new StringContent(_driveruser.age);
                StringContent idnumber       = new StringContent(_driveruser.idnumber);
                StringContent firebase_token = new StringContent(_driveruser.firebase_token);
                StringContent national       = new StringContent(_driveruser.national);
                StringContent nationality    = new StringContent(_driveruser.nationality);
                StringContent load           = new StringContent(_driveruser.load);
                StringContent type           = new StringContent(_driveruser.type);
                StringContent lat            = new StringContent(_driveruser.lat);
                StringContent lng            = new StringContent(_driveruser.lng);
                var           content        = new MultipartFormDataContent();

                content.Add(name, "name");
                content.Add(email, "email");
                content.Add(phone, "phone");
                content.Add(password, "password");
                content.Add(confirmpass, "confirmpass");
                content.Add(country, "country");
                content.Add(city, "city");
                content.Add(cartype, "cartype");
                content.Add(carmodal, "carmodal");
                content.Add(carnumber, "carnumber");
                content.Add(device_id, "device_id");
                content.Add(age, "age");
                content.Add(idnumber, "idnumber");
                content.Add(firebase_token, "firebase_token");
                content.Add(national, "national");
                content.Add(nationality, "nationality");
                content.Add(load, "load");
                content.Add(type, "type");
                content.Add(lat, "lat");
                content.Add(lng, "lng");
                content.Add(new StreamContent(DriverLicImg.GetStream()), "denominationnumber", $"{DriverLicImg.Path}");
                content.Add(new StreamContent(ProfilePic.GetStream()), "image", $"{ProfilePic.Path}");
                content.Add(new StreamContent(passportnumber.GetStream()), "passportnumber", $"{passportnumber.Path}");
                //content.Add(new StreamContent(_mediafile.GetStream()), "images", $"{_mediafile.Path}");
                HttpClient httpClient = new HttpClient();
                try
                {
                    var httpResponseMessage = await httpClient.PostAsync("https://waselksa.alsalil.net/api/register",
                                                                         content);

                    var serverResponse = httpResponseMessage.Content.ReadAsStringAsync().Result.ToString();
                    if (serverResponse == "false")
                    {
                        Active.IsRunning = false;
                        await DisplayAlert(AppResources.Error, AppResources.ErrorMessage, AppResources.Ok);
                    }
                    else
                    {
                        try
                        {
                            try
                            {
                                Active.IsRunning = false;
                                var JsonResponse = JsonConvert.DeserializeObject <Response <string, Models.DriverUser> >(serverResponse);
                                if (JsonResponse.success == true)
                                {
                                    Settings.LastUsedDriverID = JsonResponse.message.id;
                                    Settings.LastUsedEmail    = JsonResponse.message.email;
                                    Settings.LastUserStatus   = "0";
                                    Settings.ProfileUser      = "******";
                                    Settings.ProfileName      = JsonResponse.message.name;
                                    Settings.CarLat           = Convert.ToDouble(JsonResponse.message.lat);
                                    Settings.CarLng           = Convert.ToDouble(JsonResponse.message.lng);
                                    await PopupNavigation.Instance.PushAsync(new RegisterPopup(JsonResponse.data));

                                    Device.BeginInvokeOnMainThread(() => App.Current.MainPage = new MainTabbedPage());
                                }
                            }
                            catch
                            {
                                var JsonResponse = JsonConvert.DeserializeObject <RegisterResponse>(serverResponse);
                                if (JsonResponse.success == false)
                                {
                                    Active.IsRunning = false;
                                    await PopupNavigation.Instance.PushAsync(new RegisterPopup(JsonResponse.data));
                                }
                            }
                        }
                        catch (Exception)
                        {
                            Active.IsRunning = false;
                            await PopupNavigation.Instance.PushAsync(new ConnectionPopup());

                            return;
                        }
                    }
                }
                catch (Exception)
                {
                    await DisplayAlert(AppResources.Error, AppResources.ErrorMessage, AppResources.Ok);
                }
            }
        }