Ejemplo n.º 1
0
        protected Braintree.Customer SearchOrCreateBTCustomer(Profile profile)
        {
            MembershipUser user = Membership.GetUser(profile.Name);

            //Inserimento del cliente nella banca dati
            var c = new CustomerRequest
            {
                Id = profile.Name,
                Company = profile.CompanyName,
                Email = user.Email,
                Phone = profile.Phone,
            };

            Braintree.Customer customer;
            Result<Braintree.Customer> customerResult;
            //Se la carta non è stata trovata ci sono 2 possibilità:
            //1. Non esiste il cliente in Braintree
            //2. Non esiste la carta
            try
            {
                //Cerco il cliente
                customer = Constants.Gateway.Customer.Find(profile.Name);
                customerResult = Constants.Gateway.Customer.Update(profile.Name, c);
            }
            catch (NotFoundException)
            {
                customerResult = Constants.Gateway.Customer.Create(c);
                //Cerco il cliente
                customer = Constants.Gateway.Customer.Find(profile.Name);
            }

            return customer;

        }
Ejemplo n.º 2
0
        public ActionResult Register(RegisterModel model)
        {

            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus;
                Membership.CreateUser(model.UserName,
                    model.Password, model.Email,
                    passwordQuestion: "aa",
                    passwordAnswer: "aa",
                    isApproved: false,
                    providerUserKey: null,
                    status: out createStatus);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    //TO DO: create a new user in main database

                    var nProf = new Profile();
                    nProf.Name = model.UserName;
                    nProf.CompanyName = model.OrganizationName;
                    nProf.Base = model.Base;
                    nProf.Culture = model.Culture;
                    nProf.Phone = model.Phone;
                    nProf.TaxCode = model.TaxCode;
                    nProf.Refeere = model.Refeere;
                    nProf.VatNumber = model.VatNumber;
                    nProf.City = model.City;

                    profDataRep.Add(nProf);
                    profDataRep.Save();

                    //if (nProf.Name.GetDatabase() == nProf.Name.GetUser())
                    //{
                        //Sincronizzazione dei moduli
                        profDataRep.SyncroModules(nProf.Name);

                        this.CheckModuleRole(nProf);
                        ////Carta di credito
                        //this.SearchOrCreateBTCustomer(nProf);

                        this.SendConfirmationEmail(model.UserName);
                        //                    return RedirectToAction("Confirmation", "Account");
                    //}

                    return Json(new { redirectUrl = Url.Action("Confirmation") });
                }
                else
                {
                    ModelState.AddModelError("PersError", createStatus.ToString());
                }
            }

            // If we got this far, something failed, redisplay form
            return PartialView("_Register", model);
        }
Ejemplo n.º 3
0
        //
        // POST: /Account/EditProfile


        //questo metodo sinconizza le role dell'utente con i moduli attivi/disattivi
        protected void CheckModuleRole(Profile nProf)
        {

            //per ciascun modulo in prova aggiungo l'utente nel gruppo
            nProf = profDataRep.GetSingle(nProf.Name);
            //carico il membership
            MembershipUser user = Membership.GetUser(nProf.Name);

            foreach (var m in nProf.Modules)
            {
                if (!Roles.RoleExists(m.CodModule))
                    Roles.CreateRole(m.CodModule);

                if (m.IsValid)
                {
                    try
                    {
                        Roles.AddUserToRole(user.UserName, m.CodModule);
                    }
                    catch (Exception)
                    { }

                }
                else
                {
                    try
                    {
                        Roles.RemoveUserFromRole(user.UserName, m.CodModule);
                    }
                    catch (Exception)
                    { }
                }
                Membership.UpdateUser(user);
            }
        }
Ejemplo n.º 4
0
        public ActionResult Edit(Profile c)
        {

            if (ModelState.IsValid)
            {
                profDataRep.Edit(c);
                profDataRep.Save();
                return RedirectToAction("About");
            }

            return View(c);        
        }