Beispiel #1
0
        public IActionResult DevnirFournisseurLogement(string id)
        {
            ViewData["countries"] = AvailableCountries;

            string idx = userManager.GetUserId(User);

            if (idx == null)
            {
                var user = new CommercentViewModel {
                    TypseService = id
                };
                return(View("New", user));
            }
            var userCo = fournisseurService.GetFournisseurById(idx);

            if (idx != null && (userCo.Result != null))
            {
                return(RedirectToAction("AjouterLogement", "Service"));
            }
            else
            {
                var com  = commercantService.GetCommerçantById(idx).Result;
                var user = new CommercentViewModel {
                    TypseService = id
                };
                if (com.SituationEntreprise != null)
                {
                    return(RedirectToAction("ChangerEnFournisseur", "Service", user));
                }



                return(RedirectToAction("CommercantPersonne", "service", user));
            }
        }
Beispiel #2
0
        public async Task <IActionResult> CommercantPersonne(CommercentViewModel model, string Password, string email)
        {
            string     idx         = userManager.GetUserId(User);
            var        com         = commercantService.GetCommerçantById(idx).Result;
            Commerçant com2        = (Commerçant)userService.GetById(idx).Result;
            var        fournisseur = new Fournisseur
            {
                UserName = com.Email,

                PhoneNumber         = com.PhoneNumber,
                PersAContact        = com.PersAContact,
                Email               = com.Email,
                FormeJuridique      = model.Forme,
                Secteur             = model.Secteur,
                DomainActivite      = model.Domaine,
                SituationEntreprise = model.SituationEntreprise,
                EffectFemme         = model.EffectFemme,
                EffectHomme         = model.EffectHomme,
                Type        = com.Type,
                TypeService = (TypeService)Enum.Parse(typeof(TypeService), model.TypseService)
            };
            await commercantService.Delete(com);

            var result = await userManager.CreateAsync(fournisseur, Password);

            if (result.Succeeded)
            {
                Debug.WriteLine("cest un user");
                await userManager.AddToRoleAsync(fournisseur, "Commercant");

                await signInManager.SignInAsync(fournisseur, isPersistent : false);
            }
            return(RedirectToAction("Index", "Home"));
        }
Beispiel #3
0
        public async Task <IActionResult> RegisterCommercant(CommercentViewModel model)
        {
            ViewData["countries"] = AvailableCountries;
            if (ModelState.IsValid)
            {
                string uniqueFileName = null;
                if (model.FileP != null)
                {
                    // The image must be uploaded to the images folder in wwwroot
                    // To get the path of the wwwroot folder we are using the inject
                    // HostingEnvironment service provided by ASP.NET Core
                    string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "Files");
                    // To make sure the file name is unique we are appending a new
                    // GUID value and and an underscore to the file name
                    uniqueFileName = Guid.NewGuid().ToString() + "_" + model.FileP.FileName;
                    string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                    // Use CopyTo() method provided by IFormFile interface to
                    // copy the file to wwwroot/images folder
                    model.FileP.CopyTo(new FileStream(filePath, FileMode.Create));
                }

                //phone
                try
                {
                    var numberDetails = await PhoneNumberResource.FetchAsync(
                        pathPhoneNumber : new Twilio.Types.PhoneNumber(model.Telephone),
                        countryCode : model.PhoneNumberCountryCode,

                        type : new List <string> {
                        "carrier"
                    });

                    // only allow user to set phone number if capable of receiving SMS
                    if (numberDetails?.Carrier != null && numberDetails.Carrier.GetType().Equals(""))
                    {
                        ModelState.AddModelError($"{nameof(model.Telephone)}.{nameof(model.Telephone)}",
                                                 $"Le format du numero ne convient pas à votre pays");
                        return(View());
                    }

                    var numberToSave = numberDetails.PhoneNumber.ToString();



                    var user = new Commerçant
                    {
                        UserName = model.Email,

                        PhoneNumber         = numberToSave,
                        PersAContact        = model.PersAContact,
                        Email               = model.Email,
                        FormeJuridique      = model.Forme,
                        Secteur             = model.Secteur,
                        DomainActivite      = model.Domaine,
                        SituationEntreprise = model.SituationEntreprise,
                        EffectFemme         = model.EffectFemme,
                        EffectHomme         = model.EffectHomme,
                        Type    = model.Type,
                        Patente = uniqueFileName,
                        Country = model.PhoneNumberCountryCode
                    };
                    var result = await userManager.CreateAsync(user, model.Password);


                    if (result.Succeeded)
                    {
                        System.Diagnostics.Debug.WriteLine("Country is" + model.PhoneNumberCountryCode);


                        if (await roleManager.RoleExistsAsync("Commercant"))
                        {
                            await userManager.AddToRoleAsync(user, "Commercant");
                        }
                        else
                        {
                            IdentityRole identityrole = new IdentityRole
                            {
                                Name = "Commercant"
                            };
                            await roleManager.CreateAsync(identityrole);

                            await userManager.AddToRoleAsync(user, "Commercant");
                        }
                        var token = await userManager.GenerateEmailConfirmationTokenAsync(user);

                        var confirmationLink = Url.Action("ConfirmEmail", "Account",
                                                          new { userId = user.Id, token = token }, Request.Scheme, Request.Host.ToString());

                        //sending email


                        var mailMessage = new MimeMessage();
                        mailMessage.From.Add(new MailboxAddress("from TourME", "*****@*****.**"));
                        mailMessage.To.Add(new MailboxAddress("Client", model.Email));
                        mailMessage.Subject = "Email Confirmation";
                        mailMessage.Body    = new TextPart("plain")
                        {
                            Text = $"{confirmationLink}"
                        };

                        using (var smtpClient = new SmtpClient())
                        {
                            smtpClient.CheckCertificateRevocation = false;
                            smtpClient.Connect("smtp.gmail.com", 587, SecureSocketOptions.Auto);
                            smtpClient.Authenticate("*****@*****.**", "wiss20/20");
                            smtpClient.Send(mailMessage);
                            smtpClient.Disconnect(true);
                        }
                        //



                        ViewBag.ErrorTitle   = "Registration successful";
                        ViewBag.ErrorMessage = "Before you can Login, please confirm your " +
                                               "email, by clicking on the confirmation link we have emailed you";
                        return(View("Error"));

                        //await signInManager.SignInAsync(user, isPersistent: false);


                        //  return RedirectToAction("CreateExperience", "Experience");
                    }
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError("", error.Description);
                    }

                    return(View(model));
                }
                catch (ApiException ex)
                {
                    ModelState.AddModelError($"{nameof(model.Telephone)}.{nameof(model.Telephone)}",
                                             $"Le numéro entré n'est pas valide  (Code d'erreur {ex.Code})");
                    return(View());
                }
            }
            return(View());
        }
Beispiel #4
0
        public async Task <IActionResult> BecomeCommercant(CommercentViewModel model, string jobb)
        {
            ViewData["countries"] = AvailableCountries;
            string idx = userManager.GetUserId(User);

            if (ModelState.IsValid)
            {
                Debug.WriteLine("valid" + ModelState.IsValid.ToString());
                string uniqueFileName       = null;
                List <EmployeDocuments> emp = new List <EmployeDocuments>();
                if (model.Documents != null && model.Documents.Count > 0)
                {
                    // Loop thru each selected file
                    foreach (IFormFile photo in model.Documents)
                    {
                        EmployeDocuments employe = new EmployeDocuments();
                        // The file must be uploaded to the images folder in wwwroot
                        // To get the path of the wwwroot folder we are using the injected
                        // IHostingEnvironment service provided by ASP.NET Core
                        string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "Files");
                        // To make sure the file name is unique we are appending a new
                        // GUID value and and an underscore to the file name
                        uniqueFileName = Guid.NewGuid().ToString() + "_" + photo.FileName;
                        string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                        // Use CopyTo() method provided by IFormFile interface to
                        // copy the file to wwwroot/images folder
                        photo.CopyTo(new FileStream(filePath, FileMode.Create));
                        employe.Filepath = uniqueFileName;
                        emp.Add(employe);
                    }
                }
                if (model.FileP != null)
                {
                    // The image must be uploaded to the images folder in wwwroot
                    // To get the path of the wwwroot folder we are using the inject
                    // HostingEnvironment service provided by ASP.NET Core
                    string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images");
                    // To make sure the file name is unique we are appending a new
                    // GUID value and and an underscore to the file name
                    uniqueFileName = Guid.NewGuid().ToString() + "_" + model.FileP.FileName;
                    string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                    // Use CopyTo() method provided by IFormFile interface to
                    // copy the file to wwwroot/images folder
                    model.FileP.CopyTo(new FileStream(filePath, FileMode.Create));
                }
                //phone
                try
                {
                    var numberDetails = await PhoneNumberResource.FetchAsync(
                        pathPhoneNumber : new Twilio.Types.PhoneNumber(model.Telephone),
                        countryCode : model.PhoneNumberCountryCode,

                        type : new List <string> {
                        "carrier"
                    });

                    // only allow user to set phone number if capable of receiving SMS
                    if (numberDetails?.Carrier != null && numberDetails.Carrier.GetType().Equals(""))
                    {
                        ModelState.AddModelError($"{nameof(model.Telephone)}.{nameof(model.Telephone)}",
                                                 $"Le format du numero ne convient pas à votre pays");
                        return(View());
                    }

                    var numberToSave = numberDetails.PhoneNumber.ToString();

                    var user = new Fournisseur
                    {
                        UserName = model.Email,

                        PhoneNumber         = numberToSave,
                        PersAContact        = model.PersAContact,
                        Email               = model.Email,
                        Secteur             = model.Secteur,
                        NomGerant           = model.NomGerant,
                        DomainActivite      = model.Domaine,
                        Identifiant_fiscale = model.Identifiant_fiscale,
                        Titre               = model.Titre,
                        EffectFemme         = model.EffectFemme,
                        EffectHomme         = model.EffectHomme,
                        //Type = model.Type,
                        ProfilePhoto     = uniqueFileName,
                        TypeService      = (TypeService)Enum.Parse(typeof(TypeService), jobb),
                        Adresse          = model.Adresse,
                        EmployeDocuments = emp
                    };
                    var result = await userManager.CreateAsync(user, model.Password);


                    if (result.Succeeded)
                    {
                        if (await roleManager.RoleExistsAsync("Commercant"))
                        {
                            await userManager.AddToRoleAsync(user, "Commercant");
                        }
                        else
                        {
                            IdentityRole identityrole = new IdentityRole
                            {
                                Name = "Commercant"
                            };
                            await roleManager.CreateAsync(identityrole);

                            await userManager.AddToRoleAsync(user, "Commercant");
                        }
                        await signInManager.SignInAsync(user, isPersistent : false);
                    }

                    if (user.TypeService.ToString().ToLower() == "transport")
                    {
                        return(RedirectToAction("AjouterTransport", "Service"));
                    }
                    else if (user.TypeService.ToString().ToLower() == "logement")
                    {
                        return(RedirectToAction("AddLogement", "Service"));
                    }
                    else if (user.TypeService.ToString().ToLower() == "nourriture")
                    {
                        return(RedirectToAction("AddRestaurant", "Service"));
                    }
                }
                catch (ApiException ex)
                {
                    ModelState.AddModelError($"{nameof(model.Telephone)}.{nameof(model.Telephone)}",
                                             $"Le numéro entré n'est pas valide  (Code d'erreur {ex.Code})");
                    return(View());
                }
            }

            return(View(model));
        }
Beispiel #5
0
        public async Task <IActionResult> DevnirFournisseurLogement(CommercentViewModel model)
        {
            ViewData["countries"] = AvailableCountries;
            if (ModelState.IsValid)
            {
                Debug.WriteLine("valid" + ModelState.IsValid.ToString());
                string uniqueFileName = null;
                if (model.FileP != null)
                {
                    // The image must be uploaded to the images folder in wwwroot
                    // To get the path of the wwwroot folder we are using the inject
                    // HostingEnvironment service provided by ASP.NET Core
                    string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "Files");
                    // To make sure the file name is unique we are appending a new
                    // GUID value and and an underscore to the file name
                    uniqueFileName = Guid.NewGuid().ToString() + "_" + model.FileP.FileName;
                    string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                    // Use CopyTo() method provided by IFormFile interface to
                    // copy the file to wwwroot/images folder
                    model.FileP.CopyTo(new FileStream(filePath, FileMode.Create));
                }
                //phone
                try
                {
                    var numberDetails = await PhoneNumberResource.FetchAsync(
                        pathPhoneNumber : new Twilio.Types.PhoneNumber(model.Telephone),
                        countryCode : model.PhoneNumberCountryCode,

                        type : new List <string> {
                        "carrier"
                    });

                    // only allow user to set phone number if capable of receiving SMS
                    if (numberDetails?.Carrier != null && numberDetails.Carrier.GetType().Equals(""))
                    {
                        ModelState.AddModelError($"{nameof(model.Telephone)}.{nameof(model.Telephone)}",
                                                 $"Le format du numero ne convient pas à votre pays");
                        return(View());
                    }

                    var numberToSave = numberDetails.PhoneNumber.ToString();

                    var user = new Fournisseur
                    {
                        UserName = model.Email,

                        PhoneNumber         = numberToSave,
                        PersAContact        = model.PersAContact,
                        Email               = model.Email,
                        FormeJuridique      = model.Forme,
                        Secteur             = model.Secteur,
                        DomainActivite      = model.Domaine,
                        SituationEntreprise = model.SituationEntreprise,
                        EffectFemme         = model.EffectFemme,
                        EffectHomme         = model.EffectHomme,
                        Type        = model.Type,
                        Patente     = uniqueFileName,
                        TypeService = (TypeService)Enum.Parse(typeof(TypeService), model.TypseService)
                    };
                    var result = await userManager.CreateAsync(user, model.Password);


                    if (result.Succeeded)
                    {
                        System.Diagnostics.Debug.WriteLine("Country is" + model.PhoneNumberCountryCode);


                        if (await roleManager.RoleExistsAsync("Commercant"))
                        {
                            await userManager.AddToRoleAsync(user, "Commercant");
                        }
                        else
                        {
                            IdentityRole identityrole = new IdentityRole
                            {
                                Name = "Commercant"
                            };
                            await roleManager.CreateAsync(identityrole);

                            await userManager.AddToRoleAsync(user, "Commercant");
                        }
                        await signInManager.SignInAsync(user, isPersistent : false);

                        if (user.TypeService.ToString() == "Logement")
                        {
                            return(RedirectToAction("AjouterLogement", "Service"));
                        }
                        if (user.TypeService.ToString() == "Nourriture")
                        {
                            return(RedirectToAction("AjouterNourriture", "Service"));
                        }

                        if (user.TypeService.ToString() == "Transport")
                        {
                        }
                    }
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError("", error.Description);
                    }

                    return(View(model));
                }
                catch (ApiException ex)
                {
                    ModelState.AddModelError($"{nameof(model.Telephone)}.{nameof(model.Telephone)}",
                                             $"Le numéro entré n'est pas valide  (Code d'erreur {ex.Code})");
                    return(View());
                }
            }
            Debug.WriteLine("ma5dmtch" + ModelState.IsValid.ToString());
            return(View("New"));
        }
Beispiel #6
0
 public IActionResult CommercantPersonne(CommercentViewModel model)
 {
     return(View(model));
 }
Beispiel #7
0
 public IActionResult ChangerEnFournisseur(CommercentViewModel model)
 {
     return(View(model));
 }