Beispiel #1
0
        // adds a Demo User (CoUser)to database and returns it
        private static Result GenerateDemoUser()
        {
            Result result = new Result();
            using (ForGoodEntities db = new ForGoodEntities())
            {
                string email = Guid.NewGuid().ToString();
                while(db.Users.Any(u => u.Email == email)){
                    email = Guid.NewGuid().ToString();
                }
                email = "demo_" + email + "@forgood.com";
                User demoUser = new User()
                {
                    Email = email,
                    Password = CalculateSHA1("1111"),
                    CreationDateUtc = DateTime.Now.ToUniversalTime()
                };
                db.AddToUsers(demoUser);
                db.SaveChanges();
                result.Code = RESULT_CODES.Succeeded;
                result.ReturnedObj = MapToCustomObject(demoUser) as CoUser;

                AddCard(email, "What is the supreme law of the land?", "The Constitution");
                AddCard(email, "What does the Constitution do?", "sets up the government\ndefines the government\nprotects basic rights of Americans");

            }
            return result;
        }
Beispiel #2
0
 // returns UserId (int)
 private static Result RegNewUser(string email, string password)
 {
     Result result = new Result();
     using (ForGoodEntities db = new ForGoodEntities())
     {
         if (db.Users.Any(u => u.Email == email))
         {
             result.Code = RESULT_CODES.Failed;
             result.ErrorCodes.Add(ERROR_CODES.RegNewUser_EmailAlreadyExists);
         }
         else
         {
             User user = new User()
             {
                 Email = email,
                 Password = password,
                 CreationDateUtc = DateTime.Now.ToUniversalTime()
             };
             db.AddToUsers(user);
             db.SaveChanges();
             result.Code = RESULT_CODES.Succeeded;
             result.ReturnedObj = user.UserId;
         }
     }
     return result;
 }