示例#1
0
        public static UserIdentity CreateUser(DataContext context, string userName = "******", string password = "******",
                                              string title     = "Mr", string firstName     = "James", string surname = "Mccall", string idNumber = "7005245602074", GenderType gender = GenderType.Male,
                                              string Telephone = "0723257865", string email = "*****@*****.**", string streetName = "3559 Tempor Street", string city = "Gianco", string postalCode = "1899")
        {
            try
            {
                //fetch according to unique index
                var current = context.UserIdentitySet
                              .Include(a => a.Roles)
                              .Where(a => a.UserName == userName).SingleOrDefault(); //check against unique index
                if (current == null)                                                 //if not found in db
                {
                    //create instance of entity and insert to table.
                    current       = new Entities.SecurityData.UserIdentity();
                    current.Roles = new List <Role>();
                    context.UserIdentitySet.Add(current);
                }

                //set all attributes - this will update if existing, or insert if new
                current.UserName      = userName;
                current.Title         = title;
                current.FirstName     = firstName;
                current.Surname       = surname;
                current.IdPassportNum = idNumber;
                current.Gender        = gender;
                current.PasswordHash  = Cipher.Encrypt(password);
                current.Telephone     = Telephone;
                current.EmailAddress  = email;
                current.AddressLine1  = streetName;
                current.City          = city;
                current.PostalCode    = postalCode;
                current.Active        = true;

                context.SaveChanges(); //commit changes
                return(current);
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException e)
            {
                throw e;
            }
        }
示例#2
0
 public void SendPasswordResetEmail(Entities.SecurityData.UserIdentity user, string newPassword)
 {
 }