示例#1
0
        public ActionResult Create(RegisterNewCustomerModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    string email = model.UserName + "@domain.com";
                    MembershipCreateStatus createStatus;
                    Membership.CreateUser(model.UserName, "cde32wsx", email, null, null, true, null, out createStatus);
                    if (createStatus == MembershipCreateStatus.Success)
                    {
                        if (!Roles.RoleExists("Customers"))
                            Roles.CreateRole("Customers");
                        if (!Roles.IsUserInRole(model.UserName, "Customers"))
                            Roles.AddUserToRole(model.UserName, "Customers");

                        using (var context = new LibraryContainer())
                        {
                            var customer = new Customer { Name = model.UserName, Title = model.UserTitle};
                            context.AddToCustomer(customer);
                            context.SaveChanges();
                        }

                        return RedirectToAction("Index", "Customer", new { area = "Presentation" });
                    }
                    else
                    {
                        ModelState.AddModelError("", ErrorCodeToString(createStatus));
                    }
                }
                return View(model);
            }
            catch
            {
                return View(model);
            }
        }
示例#2
0
 /// <summary>
 /// Create a new Customer object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="title">Initial value of the Title property.</param>
 public static Customer CreateCustomer(global::System.Int32 id, global::System.String name, global::System.String title)
 {
     Customer customer = new Customer();
     customer.Id = id;
     customer.Name = name;
     customer.Title = title;
     return customer;
 }
示例#3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Customer EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCustomer(Customer customer)
 {
     base.AddObject("Customer", customer);
 }