public static void CreateUsers(ExpenseDatabaseContext context)
 {
     var user = new User()
                        {
                            Login = "******",
                            Password = "******",
                            UserGuid = Guid.NewGuid().ToString()
                        };
         context.Users.Add(user);
 }
Ejemplo n.º 2
0
        public SetupData()
        {
            // create new account record
            MyAccount = new User()
                            {
                                Login = "******",                      // login
                                Password = "******",                    // passwor
                                UserGuid = Guid.NewGuid().ToString(),   // generate new GUID
                                Expenses = new Collection<ExpenseNamespace.Expense>()   // empty collection of expenes
                            };

            TagsList = new List<ExpenseNamespace.Tag>();

            // create 1-st tag
            ExpenseNamespace.Tag tagFun = new ExpenseNamespace.Tag()
                                           {
                                               Name = "fun",
                                               User = MyAccount
                                           };
            TagsList.Add(tagFun);

            // create new expense
            ExpenseNamespace.Expense expense1 = new ExpenseNamespace.Expense()
                                         {
                                             Amount = 100,                            // expense sum
                                             DateOfMakingExpense = DateTime.UtcNow,   // date of take expense
                                             Description = "present for mom",         // reason
                                             Tag = tagFun,                            // select tag
                                             User = MyAccount                         // owner
                                         };

            ExpenseNamespace.Tag tagFood = new ExpenseNamespace.Tag()
                                        {
                                            Name = "food",
                                            User = MyAccount
                                        };

            TagsList.Add(tagFood);

            MyAccount.Expenses.Add(expense1);

            ExpenseNamespace.Expense expense2 = new ExpenseNamespace.Expense()
                                        {
                                            Amount = 50,
                                            DateOfMakingExpense = DateTime.UtcNow,
                                            Description = "",
                                            Tag = tagFood,
                                            User = MyAccount
                                        };

            MyAccount.Expenses.Add(expense2);

            ExpenseNamespace.Expense expense3 = new ExpenseNamespace.Expense()
            {
                Amount = 55,
                DateOfMakingExpense = DateTime.UtcNow,
                Description = "",
                Tag = tagFood,
                User = MyAccount
            };

            MyAccount.Expenses.Add(expense3);
        }
        public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            using (var context = new ExpenseDatabaseContext())
            {
                User user = context.Users.FirstOrDefault(u => u.Login == username);

                string passwordSHA = UserHelper.hashSHA512(password);

                if (user == null)
                {
                    // ExpenseTrackingSystem.Database.Security.User
                    User userRecord = new User();
                    userRecord.UserGuid = Guid.NewGuid().ToString();
                    userRecord.Login = username;
                    userRecord.Password = passwordSHA;
                    context.Users.Add(userRecord);
                    try
                    {
                        if (context.SaveChanges() != 1)
                        {
                            status = MembershipCreateStatus.ProviderError;
                            MvcApplication.log.Error(" Saving were not completed ");

                            return null;
                        }
                    }
                    catch (UpdateException ex)
                    {
                        status = MembershipCreateStatus.ProviderError;
                        MvcApplication.log.ErrorException(" Exeption during save data in the database: " + ex.StackTrace, ex);

                        return null;
                    }
                }
                else
                {
                    status = MembershipCreateStatus.DuplicateUserName;

                    return null;
                }

                status = MembershipCreateStatus.Success;

                return null;
            }
        }