Esempio n. 1
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"));
        }
Esempio n. 2
0
        public async void Verify(Commerçant commerçant, string Id)
        {
            var com = await commercantService.GetCommerçantById(commerçant.Id);

            com.Verified = true;
            try
            {
                await commercantService.Update(com);
            }
            catch (Exception ex) { Response.Redirect("GetAllCommercant"); }
        }
Esempio n. 3
0
        public async Task <IActionResult> EditUser(Commerçant model)
        {
            string     id   = userManager.GetUserId(User);
            Commerçant user = (Commerçant)await UserService.GetUtilisateurByIdAsync(id);

            user.PersAContact = model.PersAContact;
            user.Email        = model.Email;
            user.PhoneNumber  = model.PhoneNumber;


            await UserService.PutUtilisateurAsync(id, user);

            return(RedirectToAction("ProfilCommerc"));
        }
Esempio n. 4
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());
        }
Esempio n. 5
0
 public Task Update(Commerçant Commerçant)
 {
     return(genericRepo.PutAsync(Commerçant.Id, Commerçant));
 }
Esempio n. 6
0
 public Task Delete(Commerçant Commerçant)
 {
     return(genericRepo.DeleteAsync(Commerçant.Id));
 }
Esempio n. 7
0
 public Task Ajout(Commerçant commerçant)
 {
     return(genericRepo.InsertAsync(commerçant));
 }