Example #1
0
 public bool ValidCreateObject(FPUser fpUser, IFPUserService _fpUserService, IEmployeeService _employeeService)
 {
     //VHasEmployee(fpUser, _employeeService);
     //if (!isValid(fpUser)) { return false; }
     VHasUniquePIN(fpUser, _fpUserService);
     return(isValid(fpUser));
 }
Example #2
0
        public dynamic Insert(FPUser model)
        {
            model.Errors = new Dictionary <string, string>();
            try
            {
                if (!AuthenticationModel.IsAllowed("Create", Core.Constants.Constant.MenuName.FPUser, Core.Constants.Constant.MenuGroupName.Setting))
                {
                    model.Errors.Add("Generic", "You are Not Allowed to Add record");

                    return(Json(new
                    {
                        model.Errors
                    }, JsonRequestBehavior.AllowGet));
                }

                model.IsInSync = false;
                model          = _fpUserService.CreateObject(model, _employeeService);
            }
            catch (Exception ex)
            {
                LOG.Error("Insert Failed", ex);
                model.Errors.Add("Generic", "Error " + ex);

                return(Json(new
                {
                    model.Errors
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                model.Errors
            }));
        }
        private static async Task SeedAccountsAsync(FPUser user, ApplicationDbContext context)
        {
            //account 1
            var account = new BankAccount
            {
                HouseHoldId     = (int)user.HouseHoldId,
                FPUserId        = user.Id,
                Name            = "Chase",
                Type            = AccountType.Checking,
                StartingBalance = 500,
                CurrentBalance  = 500
            };

            context.Add(account);
            await context.SaveChangesAsync();

            //account 2
            account = new BankAccount
            {
                HouseHoldId     = (int)user.HouseHoldId,
                FPUserId        = user.Id,
                Name            = "WellsFargo",
                Type            = AccountType.Savings,
                StartingBalance = 1000,
                CurrentBalance  = 1000
            };
            context.Add(account);
            await context.SaveChangesAsync();
        }
        private static async Task SeedCategoriesAsync(FPUser user, ApplicationDbContext context)
        {
            var category = new Category
            {
                HouseHoldId = (int)user.HouseHoldId,
                Name        = "House",
                Description = "All house related expenses ie: rent, repairs, lightbulbs, etc..."
            };

            context.Add(category);
            await context.SaveChangesAsync();

            category = new Category
            {
                HouseHoldId = (int)user.HouseHoldId,
                Name        = "Car",
                Description = "All car related expenses ie: gas, insurance, oil changes, etc..."
            };
            context.Add(category);
            await context.SaveChangesAsync();

            category = new Category
            {
                HouseHoldId = (int)user.HouseHoldId,
                Name        = "Food",
                Description = "All food related expenses ie: groceries, retaurants, snacks, etc..."
            };
            context.Add(category);
            await context.SaveChangesAsync();
        }
 private static async Task SeedAccount(FPUser user, ApplicationDbContext context)
 {
     await SeedHouseholdAsync(user, context);
     await SeedAccountsAsync(user, context);
     await SeedCategoriesAsync(user, context);
     await SeedItemsAsync(user, context);
     await SeedTransactionsAsync(user, context);
 }
Example #6
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl      = returnUrl ?? Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                var user = new FPUser {
                    UserName  = Input.Email,
                    Email     = Input.Email,
                    FirstName = Input.FirstName,
                    LastName  = Input.LastName,
                    FileName  = "DefaultAvatar.png",
                    FileData  = await ImageHelper.AssignAvatarAsync("DefaultAvatar.png")
                };
                if (Input.FormFile != null)
                {
                    user.FileName = Input.FormFile.FileName;
                    user.FileData = await _avatarService.ConvertFileToByteArrayAsync(Input.FormFile);
                }
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { area = "Identity", userId = user.Id, code = code, returnUrl = returnUrl },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    if (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl }));
                    }
                    else
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Example #7
0
 public FPUser SoftDeleteObject(FPUser fpUser)
 {
     if (_validator.ValidDeleteObject(fpUser))
     {
         //fpUser.IsInSync = false;
         _repository.SoftDeleteObject(fpUser);
     }
     return(fpUser);
 }
Example #8
0
        public FPTemplate VHasUser(FPTemplate fpTemplate, IFPUserService _fpUserService)
        {
            FPUser fpUser = _fpUserService.GetObjectById(fpTemplate.FPUserId);

            if (fpUser == null)
            {
                fpTemplate.Errors.Add("FPUser", "Tidak ada");
            }
            return(fpTemplate);
        }
Example #9
0
 public FPUser UpdateObject(FPUser fpUser, IEmployeeService _employeeService)
 {
     fpUser.Errors = new Dictionary <String, String>();
     if (_validator.ValidUpdateObject(fpUser, this, _employeeService))
     {
         //fpUser.IsInSync = false;
         _repository.UpdateObject(fpUser);
     }
     return(fpUser);
 }
Example #10
0
        public FPAttLog VHasUser(FPAttLog fpAttLog, IFPUserService _fpUserService)
        {
            FPUser fpUser = _fpUserService.GetObjectById(fpAttLog.FPUserId);

            if (fpUser == null)
            {
                fpAttLog.Errors.Add("Generic", "FPUser Tidak ada");
            }
            return(fpAttLog);
        }
Example #11
0
        public bool IsPINDuplicated(FPUser fpUser)
        {
            if (fpUser.PIN == 0)
            {
                return(false);
            }
            IQueryable <FPUser> objs = _repository.FindAll(x => x.PIN == fpUser.PIN && !x.IsDeleted && x.Id != fpUser.Id);

            return(objs.Count() > 0 ? true : false);
        }
Example #12
0
        public FPUser VHasEmployee(FPUser fpUser, IEmployeeService _employeeService)
        {
            Employee employee = _employeeService.GetObjectById(fpUser.EmployeeId.GetValueOrDefault());

            if (employee == null)
            {
                fpUser.Errors.Add("Employee", "Tidak ada");
            }
            return(fpUser);
        }
        public async Task <string> GetGreetingAsync(FPUser user)
        {
            var houseHold = await _context.HouseHold.FirstOrDefaultAsync(hh => hh.Id == user.HouseHoldId);

            if (houseHold == null)
            {
                return("Hello");
            }
            return(houseHold.Greeting);
        }
Example #14
0
 public FPUser VHasUniquePIN(FPUser fpUser, IFPUserService _fpUserService)
 {
     if (fpUser.PIN < 0 || fpUser.PIN > 65535)
     {
         fpUser.Errors.Add("PIN", "Harus antara 0 sampai 65535");
     }
     else if (_fpUserService.IsPINDuplicated(fpUser))
     {
         fpUser.Errors.Add("PIN", "Tidak boleh ada duplikasi");
     }
     return(fpUser);
 }
Example #15
0
        private async Task LoadAsync(FPUser user)
        {
            var email = await _userManager.GetEmailAsync(user);

            Email = email;

            Input = new InputModel
            {
                NewEmail = email,
            };

            IsEmailConfirmed = await _userManager.IsEmailConfirmedAsync(user);
        }
Example #16
0
        private async Task LoadAsync(FPUser user)
        {
            var userName = await _userManager.GetUserNameAsync(user);

            var phoneNumber = await _userManager.GetPhoneNumberAsync(user);

            Username = userName;

            Input = new InputModel
            {
                PhoneNumber = phoneNumber
            };
        }
Example #17
0
        public string PrintError(FPUser obj)
        {
            string erroroutput = "";
            KeyValuePair <string, string> first = obj.Errors.ElementAt(0);

            erroroutput += first.Key + "," + first.Value;
            foreach (KeyValuePair <string, string> pair in obj.Errors.Skip(1))
            {
                erroroutput += Environment.NewLine;
                erroroutput += pair.Key + "," + pair.Value;
            }
            return(erroroutput);
        }
Example #18
0
 public FPUser CreateObject(FPUser fpUser, IEmployeeService _employeeService)
 {
     fpUser.Errors = new Dictionary <String, String>();
     if (fpUser.PIN == 0)
     {
         fpUser.PIN = GeneratePIN();
     }
     if (_validator.ValidCreateObject(fpUser, this, _employeeService))
     {
         //fpUser.IsInSync = false;
         _repository.CreateObject(fpUser);
     }
     return(fpUser);
 }
        private static async Task SeedHouseholdAsync(FPUser user, ApplicationDbContext context)
        {
            var household = new HouseHold
            {
                Name        = "Demo",
                Greeting    = "Welcome",
                Established = DateTime.Now
            };

            context.Add(household);
            await context.SaveChangesAsync();

            user.HouseHoldId = household.Id;
            await context.SaveChangesAsync();
        }
Example #20
0
        public dynamic Update(FPUser model)
        {
            model.Errors = new Dictionary <string, string>();
            try
            {
                if (!AuthenticationModel.IsAllowed("Edit", Core.Constants.Constant.MenuName.FPUser, Core.Constants.Constant.MenuGroupName.Setting))
                {
                    model.Errors.Add("Generic", "You are Not Allowed to Edit record");

                    return(Json(new
                    {
                        model.Errors
                    }, JsonRequestBehavior.AllowGet));
                }

                var data = _fpUserService.GetObjectById(model.Id);
                data.IsInSync   = (data.PIN == model.PIN && data.Name == model.Name && data.Password == model.Password && data.Card == model.Card && data.Privilege == model.Privilege && data.Group == model.Group && data.TimeZones == model.TimeZones && data.VerifyMode == model.VerifyMode && data.IsEnabled == model.IsEnabled);
                data.EmployeeId = model.EmployeeId;
                data.PIN        = model.PIN;
                data.PIN2       = model.PIN2;
                data.Name       = model.Name;
                data.Password   = model.Password;
                data.Card       = model.Card;
                data.Privilege  = model.Privilege;
                data.Group      = model.Group;
                data.TimeZones  = model.TimeZones;
                data.VerifyMode = model.VerifyMode;
                data.IsEnabled  = model.IsEnabled;
                data.Remark     = model.Remark;

                model = _fpUserService.UpdateObject(data, _employeeService);
            }
            catch (Exception ex)
            {
                LOG.Error("Update Failed", ex);
                model.Errors.Add("Generic", "Error " + ex);

                return(Json(new
                {
                    model.Errors
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                model.Errors
            }));
        }
Example #21
0
        public FPUser UpdateOrCreateObject(FPUser fpUser, IEmployeeService _employeeService)
        {
            //fpUser.Errors = new Dictionary<String, String>();
            FPUser obj = GetObjectById(fpUser.Id);

            if (obj == null)
            {
                CreateObject(fpUser, _employeeService);
                fpUser = GetObjectById(fpUser.Id); // so virtual can be accessed/included
            }
            else
            {
                UpdateObject(fpUser, _employeeService);
            }
            return(fpUser);
        }
Example #22
0
        private async Task LoadSharedKeyAndQrCodeUriAsync(FPUser user)
        {
            // Load the authenticator key & QR code URI to display on the form
            var unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);

            if (string.IsNullOrEmpty(unformattedKey))
            {
                await _userManager.ResetAuthenticatorKeyAsync(user);

                unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);
            }

            SharedKey = FormatKey(unformattedKey);

            var email = await _userManager.GetEmailAsync(user);

            AuthenticatorUri = GenerateQrCodeUri(email, unformattedKey);
        }
Example #23
0
        public async Task <IActionResult> Accept(string email, string code, string firstName, string lastName, IFormFile avatar, string password)
        {
            var invitation = await _context.Invitation.FirstOrDefaultAsync(i => i.Code.ToString() == code);

            byte[] fileData;
            string fileName;

            if (avatar != null)
            {
                fileData = await _fileService.ConvertFileToByteArrayAsync(avatar);

                fileName = avatar.FileName;
            }
            else
            {
                fileData = await _fileService.GetDefaultAvatarFileBytesAsync();

                fileName = _fileService.GetDefaultAvatarFileName();
            }
            var user = new FPUser
            {
                FirstName      = firstName,
                LastName       = lastName,
                FileName       = fileName,
                FileData       = fileData,
                UserName       = email,
                Email          = email,
                HouseHoldId    = invitation.HouseHoldId,
                EmailConfirmed = true
            };

            invitation.Accepted = true;
            // where the magic happens
            await _userManager.CreateAsync(user, password);

            await _userManager.AddToRoleAsync(user, Roles.Member.ToString());

            await _signInManager.SignInAsync(user, false);

            await _context.SaveChangesAsync();

            return(RedirectToAction("Dashboard", "HouseHolds"));
        }
Example #24
0
        public dynamic GetInfo(int Id)
        {
            FPUser model = new FPUser();

            model.Errors = new Dictionary <string, string>();
            try
            {
                model = _fpUserService.GetObjectById(Id);
            }
            catch (Exception ex)
            {
                LOG.Error("GetInfo", ex);

                model.Errors.Add("Generic", "Error " + ex);

                return(Json(new
                {
                    model.Errors
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                model.Id,
                model.EmployeeId,
                EmployeeNIK = model.Employee != null ? model.Employee.NIK : "",
                EmployeeName = model.Employee != null ? model.Employee.Name : "",
                model.PIN,
                model.PIN2,
                model.Privilege,
                model.Name,
                model.Password,
                model.Card,
                model.Group,
                model.TimeZones,
                model.VerifyMode,
                model.IsEnabled,
                model.Remark,
                model.Errors
            }, JsonRequestBehavior.AllowGet));
        }
Example #25
0
        public dynamic UpdateEnable(bool isEnabled, FPUser model)
        {
            model.Errors = new Dictionary <string, string>();
            try
            {
                if (!AuthenticationModel.IsAllowed("Edit", Core.Constants.Constant.MenuName.FPUser, Core.Constants.Constant.MenuGroupName.Setting))
                {
                    model.Errors.Add("Generic", "You are Not Allowed to Edit record");

                    return(Json(new
                    {
                        model.Errors
                    }, JsonRequestBehavior.AllowGet));
                }

                var data = _fpUserService.GetObjectById(model.Id);
                data.IsInSync  = (data.IsEnabled == model.IsEnabled);
                data.IsEnabled = isEnabled;
                model          = _fpUserService.UpdateObject(data, _employeeService);
            }
            catch (Exception ex)
            {
                LOG.Error("Update Failed", ex);
                model.Errors.Add("Generic", "Error " + ex);

                return(Json(new
                {
                    model.Errors
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                model.Errors
            }));
        }
Example #26
0
        public dynamic Delete(FPUser model)
        {
            model.Errors = new Dictionary <string, string>();
            try
            {
                if (!AuthenticationModel.IsAllowed("Delete", Core.Constants.Constant.MenuName.FPUser, Core.Constants.Constant.MenuGroupName.Setting))
                {
                    model.Errors.Add("Generic", "You are Not Allowed to Delete Record");

                    return(Json(new
                    {
                        model.Errors
                    }, JsonRequestBehavior.AllowGet));
                }

                var data = _fpUserService.GetObjectById(model.Id);
                data.IsInSync = false;
                model         = _fpUserService.SoftDeleteObject(data);
            }

            catch (Exception ex)
            {
                LOG.Error("Delete Failed", ex);
                model.Errors.Add("Generic", "Error " + ex);

                return(Json(new
                {
                    model.Errors
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                model.Errors
            }));
        }
        private static async Task SeedTransactionsAsync(FPUser user, ApplicationDbContext context)
        {
            // accounts
            var account = await context.BankAccount
                          .FirstOrDefaultAsync(ba => ba.HouseHoldId == user.HouseHoldId && ba.Name == "Chase");

            var account2 = await context.BankAccount
                           .FirstOrDefaultAsync(ba => ba.HouseHoldId == user.HouseHoldId && ba.Name == "WellsFargo");

            // t1
            var transaction = new Transaction
            {
                Type          = TransactionType.Deposit,
                BankAccountId = account.Id,
                FPUserId      = user.Id,
                Created       = DateTime.Now.AddDays(-14).AddHours(new Random().Next(24)).AddMinutes(new Random().Next(60)).AddSeconds(new Random().Next(60)),
                Memo          = "Biweekly check",
                Amount        = 1871.31M,
                IsDeleted     = false
            };

            account.CurrentBalance += transaction.Amount;

            // so that only one history per day
            var history = await context.History
                          .FirstOrDefaultAsync(
                h => h.BankAccount == account &&
                h.Date.Day == transaction.Created.Day);

            if (history == null)
            {
                History _history = new History
                {
                    BankAccountId = transaction.BankAccountId,
                    Balance       = (decimal)account.CurrentBalance,
                    Date          = transaction.Created
                };
                context.Add(_history);
            }
            else
            {
                history.BankAccountId = transaction.BankAccountId;
                history.Balance       = (decimal)account.CurrentBalance;
                history.Date          = transaction.Created;
                context.Update(history);
            }

            context.Add(transaction);
            context.Update(account);
            await context.SaveChangesAsync();

            // SAVINGS 1
            transaction = new Transaction
            {
                Type          = TransactionType.Deposit,
                BankAccountId = account2.Id,
                FPUserId      = user.Id,
                Created       = DateTime.Now.AddDays(-14).AddHours(new Random().Next(24)).AddMinutes(new Random().Next(60)).AddSeconds(new Random().Next(60)),
                Memo          = "20% of income",
                Amount        = 100,
                IsDeleted     = false
            };
            account2.CurrentBalance += transaction.Amount;

            // so that only one history per day
            history = await context.History
                      .FirstOrDefaultAsync(
                h => h.BankAccount == account2 &&
                h.Date.Day == transaction.Created.Day);

            if (history == null)
            {
                History _history = new History
                {
                    BankAccountId = transaction.BankAccountId,
                    Balance       = (decimal)account2.CurrentBalance,
                    Date          = transaction.Created
                };
                context.Add(_history);
            }
            else
            {
                history.BankAccountId = transaction.BankAccountId;
                history.Balance       = (decimal)account2.CurrentBalance;
                history.Date          = transaction.Created;
                context.Update(history);
            }

            context.Add(transaction);
            context.Update(account2);
            await context.SaveChangesAsync();

            // CategoryItems that belong to demo household
            var items = context.HouseHold.Where(hh => hh.Id == user.HouseHoldId)
                        .Include(hh => hh.Categories).ThenInclude(c => c.CategoryItems).FirstOrDefault()
                        .Categories.SelectMany(c => c.CategoryItems);

            // t2
            var item = items.Where(i => i.Name == "Rent").FirstOrDefault();

            transaction = new Transaction
            {
                Type           = TransactionType.Withdrawal,
                CategoryItemId = item.Id,
                CategoryItem   = item,
                BankAccountId  = account.Id,
                FPUserId       = user.Id,
                Created        = DateTime.Now.AddDays(-13).AddHours(new Random().Next(24)).AddMinutes(new Random().Next(60)).AddSeconds(new Random().Next(60)),
                Memo           = "Monthly rent",
                Amount         = 1200,
                IsDeleted      = false
            };
            account.CurrentBalance -= transaction.Amount;
            transaction.CategoryItem.ActualAmount += transaction.Amount;

            // so that only one history per day
            history = await context.History
                      .FirstOrDefaultAsync(
                h => h.BankAccount == account &&
                h.Date.Day == transaction.Created.Day);

            if (history == null)
            {
                History _history = new History
                {
                    BankAccountId = transaction.BankAccountId,
                    Balance       = (decimal)account.CurrentBalance,
                    Date          = transaction.Created
                };
                context.Add(_history);
            }
            else
            {
                history.BankAccountId = transaction.BankAccountId;
                history.Balance       = (decimal)account.CurrentBalance;
                history.Date          = transaction.Created;
                context.Update(history);
            }

            context.Add(transaction);
            context.Update(account);
            await context.SaveChangesAsync();

            // SAVINGS 2
            transaction = new Transaction
            {
                Type          = TransactionType.Deposit,
                BankAccountId = account2.Id,
                FPUserId      = user.Id,
                Created       = DateTime.Now.AddDays(-13).AddHours(new Random().Next(24)).AddMinutes(new Random().Next(60)).AddSeconds(new Random().Next(60)),
                Memo          = "20% of income",
                Amount        = 100,
                IsDeleted     = false
            };
            account2.CurrentBalance += transaction.Amount;

            // so that only one history per day
            history = await context.History
                      .FirstOrDefaultAsync(
                h => h.BankAccount == account2 &&
                h.Date.Day == transaction.Created.Day);

            if (history == null)
            {
                History _history = new History
                {
                    BankAccountId = transaction.BankAccountId,
                    Balance       = (decimal)account2.CurrentBalance,
                    Date          = transaction.Created
                };
                context.Add(_history);
            }
            else
            {
                history.BankAccountId = transaction.BankAccountId;
                history.Balance       = (decimal)account2.CurrentBalance;
                history.Date          = transaction.Created;
                context.Update(history);
            }

            context.Add(transaction);
            context.Update(account2);
            await context.SaveChangesAsync();

            // t3
            item        = items.Where(i => i.Name == "Repairs").FirstOrDefault();
            transaction = new Transaction
            {
                Type           = TransactionType.Withdrawal,
                CategoryItemId = item.Id,
                CategoryItem   = item,
                BankAccountId  = account.Id,
                FPUserId       = user.Id,
                Created        = DateTime.Now.AddDays(-12).AddHours(new Random().Next(24)).AddMinutes(new Random().Next(60)).AddSeconds(new Random().Next(60)),
                Memo           = "Touch-up paint",
                Amount         = 20,
                IsDeleted      = false
            };
            account.CurrentBalance -= transaction.Amount;
            transaction.CategoryItem.ActualAmount += transaction.Amount;

            // so that only one history per day
            history = await context.History
                      .FirstOrDefaultAsync(
                h => h.BankAccount == account &&
                h.Date.Day == transaction.Created.Day);

            if (history == null)
            {
                History _history = new History
                {
                    BankAccountId = transaction.BankAccountId,
                    Balance       = (decimal)account.CurrentBalance,
                    Date          = transaction.Created
                };
                context.Add(_history);
            }
            else
            {
                history.BankAccountId = transaction.BankAccountId;
                history.Balance       = (decimal)account.CurrentBalance;
                history.Date          = transaction.Created;
                context.Update(history);
            }

            context.Add(transaction);
            context.Update(account);
            await context.SaveChangesAsync();

            // SAVINGS 3
            transaction = new Transaction
            {
                Type          = TransactionType.Deposit,
                BankAccountId = account2.Id,
                FPUserId      = user.Id,
                Created       = DateTime.Now.AddDays(-12).AddHours(new Random().Next(24)).AddMinutes(new Random().Next(60)).AddSeconds(new Random().Next(60)),
                Memo          = "20% of income",
                Amount        = 100,
                IsDeleted     = false
            };
            account2.CurrentBalance += transaction.Amount;

            // so that only one history per day
            history = await context.History
                      .FirstOrDefaultAsync(
                h => h.BankAccount == account2 &&
                h.Date.Day == transaction.Created.Day);

            if (history == null)
            {
                History _history = new History
                {
                    BankAccountId = transaction.BankAccountId,
                    Balance       = (decimal)account2.CurrentBalance,
                    Date          = transaction.Created
                };
                context.Add(_history);
            }
            else
            {
                history.BankAccountId = transaction.BankAccountId;
                history.Balance       = (decimal)account2.CurrentBalance;
                history.Date          = transaction.Created;
                context.Update(history);
            }

            context.Add(transaction);
            context.Update(account2);
            await context.SaveChangesAsync();

            // t4
            item        = items.Where(i => i.Name == "Lightbulbs").FirstOrDefault();
            transaction = new Transaction
            {
                Type           = TransactionType.Withdrawal,
                CategoryItemId = item.Id,
                CategoryItem   = item,
                BankAccountId  = account.Id,
                FPUserId       = user.Id,
                Created        = DateTime.Now.AddDays(-11).AddHours(new Random().Next(24)).AddMinutes(new Random().Next(60)).AddSeconds(new Random().Next(60)),
                Memo           = "white bulbs to replace orange",
                Amount         = 20,
                IsDeleted      = false
            };
            account.CurrentBalance -= transaction.Amount;
            transaction.CategoryItem.ActualAmount += transaction.Amount;

            // so that only one history per day
            history = await context.History
                      .FirstOrDefaultAsync(
                h => h.BankAccount == account &&
                h.Date.Day == transaction.Created.Day);

            if (history == null)
            {
                History _history = new History
                {
                    BankAccountId = transaction.BankAccountId,
                    Balance       = (decimal)account.CurrentBalance,
                    Date          = transaction.Created
                };
                context.Add(_history);
            }
            else
            {
                history.BankAccountId = transaction.BankAccountId;
                history.Balance       = (decimal)account.CurrentBalance;
                history.Date          = transaction.Created;
                context.Update(history);
            }

            context.Add(transaction);
            context.Update(account);
            await context.SaveChangesAsync();

            // SAVINGS 4
            transaction = new Transaction
            {
                Type          = TransactionType.Deposit,
                BankAccountId = account2.Id,
                FPUserId      = user.Id,
                Created       = DateTime.Now.AddDays(-11).AddHours(new Random().Next(24)).AddMinutes(new Random().Next(60)).AddSeconds(new Random().Next(60)),
                Memo          = "20% of income",
                Amount        = 100,
                IsDeleted     = false
            };
            account2.CurrentBalance += transaction.Amount;

            // so that only one history per day
            history = await context.History
                      .FirstOrDefaultAsync(
                h => h.BankAccount == account2 &&
                h.Date.Day == transaction.Created.Day);

            if (history == null)
            {
                History _history = new History
                {
                    BankAccountId = transaction.BankAccountId,
                    Balance       = (decimal)account2.CurrentBalance,
                    Date          = transaction.Created
                };
                context.Add(_history);
            }
            else
            {
                history.BankAccountId = transaction.BankAccountId;
                history.Balance       = (decimal)account2.CurrentBalance;
                history.Date          = transaction.Created;
                context.Update(history);
            }

            context.Add(transaction);
            context.Update(account2);
            await context.SaveChangesAsync();

            // t5
            item        = items.Where(i => i.Name == "Gas").FirstOrDefault();
            transaction = new Transaction
            {
                Type           = TransactionType.Withdrawal,
                CategoryItemId = item.Id,
                CategoryItem   = item,
                BankAccountId  = account.Id,
                FPUserId       = user.Id,
                Created        = DateTime.Now.AddDays(-10).AddHours(new Random().Next(24)).AddMinutes(new Random().Next(60)).AddSeconds(new Random().Next(60)),
                Memo           = "to/from work",
                Amount         = 80,
                IsDeleted      = false
            };
            account.CurrentBalance -= transaction.Amount;
            transaction.CategoryItem.ActualAmount += transaction.Amount;

            // so that only one history per day
            history = await context.History
                      .FirstOrDefaultAsync(
                h => h.BankAccount == account &&
                h.Date.Day == transaction.Created.Day);

            if (history == null)
            {
                History _history = new History
                {
                    BankAccountId = transaction.BankAccountId,
                    Balance       = (decimal)account.CurrentBalance,
                    Date          = transaction.Created
                };
                context.Add(_history);
            }
            else
            {
                history.BankAccountId = transaction.BankAccountId;
                history.Balance       = (decimal)account.CurrentBalance;
                history.Date          = transaction.Created;
                context.Update(history);
            }

            context.Add(transaction);
            context.Update(account);
            await context.SaveChangesAsync();

            // SAVINGS 5
            transaction = new Transaction
            {
                Type          = TransactionType.Deposit,
                BankAccountId = account2.Id,
                FPUserId      = user.Id,
                Created       = DateTime.Now.AddDays(-10).AddHours(new Random().Next(24)).AddMinutes(new Random().Next(60)).AddSeconds(new Random().Next(60)),
                Memo          = "20% of income",
                Amount        = 100,
                IsDeleted     = false
            };
            account2.CurrentBalance += transaction.Amount;

            // so that only one history per day
            history = await context.History
                      .FirstOrDefaultAsync(
                h => h.BankAccount == account2 &&
                h.Date.Day == transaction.Created.Day);

            if (history == null)
            {
                History _history = new History
                {
                    BankAccountId = transaction.BankAccountId,
                    Balance       = (decimal)account2.CurrentBalance,
                    Date          = transaction.Created
                };
                context.Add(_history);
            }
            else
            {
                history.BankAccountId = transaction.BankAccountId;
                history.Balance       = (decimal)account2.CurrentBalance;
                history.Date          = transaction.Created;
                context.Update(history);
            }

            context.Add(transaction);
            context.Update(account2);
            await context.SaveChangesAsync();

            // t6
            item        = items.Where(i => i.Name == "Insurance").FirstOrDefault();
            transaction = new Transaction
            {
                Type           = TransactionType.Withdrawal,
                CategoryItemId = item.Id,
                CategoryItem   = item,
                BankAccountId  = account.Id,
                FPUserId       = user.Id,
                Created        = DateTime.Now.AddDays(-9).AddHours(new Random().Next(24)).AddMinutes(new Random().Next(60)).AddSeconds(new Random().Next(60)),
                Memo           = "government mandate",
                Amount         = 200,
                IsDeleted      = false
            };
            account.CurrentBalance -= transaction.Amount;
            transaction.CategoryItem.ActualAmount += transaction.Amount;

            // so that only one history per day
            history = await context.History
                      .FirstOrDefaultAsync(
                h => h.BankAccount == account &&
                h.Date.Day == transaction.Created.Day);

            if (history == null)
            {
                History _history = new History
                {
                    BankAccountId = transaction.BankAccountId,
                    Balance       = (decimal)account.CurrentBalance,
                    Date          = transaction.Created
                };
                context.Add(_history);
            }
            else
            {
                history.BankAccountId = transaction.BankAccountId;
                history.Balance       = (decimal)account.CurrentBalance;
                history.Date          = transaction.Created;
                context.Update(history);
            }

            context.Add(transaction);
            context.Update(account);
            await context.SaveChangesAsync();

            // SAVINGS 6
            transaction = new Transaction
            {
                Type          = TransactionType.Deposit,
                BankAccountId = account2.Id,
                FPUserId      = user.Id,
                Created       = DateTime.Now.AddDays(-9).AddHours(new Random().Next(24)).AddMinutes(new Random().Next(60)).AddSeconds(new Random().Next(60)),
                Memo          = "20% of income",
                Amount        = 100,
                IsDeleted     = false
            };
            account2.CurrentBalance += transaction.Amount;

            // so that only one history per day
            history = await context.History
                      .FirstOrDefaultAsync(
                h => h.BankAccount == account2 &&
                h.Date.Day == transaction.Created.Day);

            if (history == null)
            {
                History _history = new History
                {
                    BankAccountId = transaction.BankAccountId,
                    Balance       = (decimal)account2.CurrentBalance,
                    Date          = transaction.Created
                };
                context.Add(_history);
            }
            else
            {
                history.BankAccountId = transaction.BankAccountId;
                history.Balance       = (decimal)account2.CurrentBalance;
                history.Date          = transaction.Created;
                context.Update(history);
            }

            context.Add(transaction);
            context.Update(account2);
            await context.SaveChangesAsync();

            // t7
            item        = items.Where(i => i.Name == "Oil Change").FirstOrDefault();
            transaction = new Transaction
            {
                Type           = TransactionType.Withdrawal,
                CategoryItemId = item.Id,
                CategoryItem   = item,
                BankAccountId  = account.Id,
                FPUserId       = user.Id,
                Created        = DateTime.Now.AddDays(-8).AddHours(new Random().Next(24)).AddMinutes(new Random().Next(60)).AddSeconds(new Random().Next(60)),
                Memo           = "5000 miles since last one",
                Amount         = 30,
                IsDeleted      = false
            };
            account.CurrentBalance -= transaction.Amount;
            transaction.CategoryItem.ActualAmount += transaction.Amount;

            // so that only one history per day
            history = await context.History
                      .FirstOrDefaultAsync(
                h => h.BankAccount == account &&
                h.Date.Day == transaction.Created.Day);

            if (history == null)
            {
                History _history = new History
                {
                    BankAccountId = transaction.BankAccountId,
                    Balance       = (decimal)account.CurrentBalance,
                    Date          = transaction.Created
                };
                context.Add(_history);
            }
            else
            {
                history.BankAccountId = transaction.BankAccountId;
                history.Balance       = (decimal)account.CurrentBalance;
                history.Date          = transaction.Created;
                context.Update(history);
            }

            context.Add(transaction);
            context.Update(account);
            await context.SaveChangesAsync();

            // SAVINGS 7
            transaction = new Transaction
            {
                Type          = TransactionType.Deposit,
                BankAccountId = account2.Id,
                FPUserId      = user.Id,
                Created       = DateTime.Now.AddDays(-8).AddHours(new Random().Next(24)).AddMinutes(new Random().Next(60)).AddSeconds(new Random().Next(60)),
                Memo          = "20% of income",
                Amount        = 100,
                IsDeleted     = false
            };
            account2.CurrentBalance += transaction.Amount;

            // so that only one history per day
            history = await context.History
                      .FirstOrDefaultAsync(
                h => h.BankAccount == account2 &&
                h.Date.Day == transaction.Created.Day);

            if (history == null)
            {
                History _history = new History
                {
                    BankAccountId = transaction.BankAccountId,
                    Balance       = (decimal)account2.CurrentBalance,
                    Date          = transaction.Created
                };
                context.Add(_history);
            }
            else
            {
                history.BankAccountId = transaction.BankAccountId;
                history.Balance       = (decimal)account2.CurrentBalance;
                history.Date          = transaction.Created;
                context.Update(history);
            }

            context.Add(transaction);
            context.Update(account2);
            await context.SaveChangesAsync();

            // t8
            item        = items.Where(i => i.Name == "Walmart").FirstOrDefault();
            transaction = new Transaction
            {
                Type           = TransactionType.Withdrawal,
                CategoryItemId = item.Id,
                CategoryItem   = item,
                BankAccountId  = account.Id,
                FPUserId       = user.Id,
                Created        = DateTime.Now.AddDays(-7).AddHours(new Random().Next(24)).AddMinutes(new Random().Next(60)).AddSeconds(new Random().Next(60)),
                Memo           = "groceries",
                Amount         = 150,
                IsDeleted      = false
            };
            account.CurrentBalance -= transaction.Amount;
            transaction.CategoryItem.ActualAmount += transaction.Amount;

            // so that only one history per day
            history = await context.History
                      .FirstOrDefaultAsync(
                h => h.BankAccount == account &&
                h.Date.Day == transaction.Created.Day);

            if (history == null)
            {
                History _history = new History
                {
                    BankAccountId = transaction.BankAccountId,
                    Balance       = (decimal)account.CurrentBalance,
                    Date          = transaction.Created
                };
                context.Add(_history);
            }
            else
            {
                history.BankAccountId = transaction.BankAccountId;
                history.Balance       = (decimal)account.CurrentBalance;
                history.Date          = transaction.Created;
                context.Update(history);
            }

            context.Add(transaction);
            context.Update(account);
            await context.SaveChangesAsync();

            // SAVINGS 8
            transaction = new Transaction
            {
                Type          = TransactionType.Deposit,
                BankAccountId = account2.Id,
                FPUserId      = user.Id,
                Created       = DateTime.Now.AddDays(-7).AddHours(new Random().Next(24)).AddMinutes(new Random().Next(60)).AddSeconds(new Random().Next(60)),
                Memo          = "20% of income",
                Amount        = 100,
                IsDeleted     = false
            };
            account2.CurrentBalance += transaction.Amount;

            // so that only one history per day
            history = await context.History
                      .FirstOrDefaultAsync(
                h => h.BankAccount == account2 &&
                h.Date.Day == transaction.Created.Day);

            if (history == null)
            {
                History _history = new History
                {
                    BankAccountId = transaction.BankAccountId,
                    Balance       = (decimal)account2.CurrentBalance,
                    Date          = transaction.Created
                };
                context.Add(_history);
            }
            else
            {
                history.BankAccountId = transaction.BankAccountId;
                history.Balance       = (decimal)account2.CurrentBalance;
                history.Date          = transaction.Created;
                context.Update(history);
            }

            context.Add(transaction);
            context.Update(account2);
            await context.SaveChangesAsync();

            // t9
            item        = items.Where(i => i.Name == "Restaurants").FirstOrDefault();
            transaction = new Transaction
            {
                Type           = TransactionType.Withdrawal,
                CategoryItemId = item.Id,
                CategoryItem   = item,
                BankAccountId  = account.Id,
                FPUserId       = user.Id,
                Created        = DateTime.Now.AddDays(-6).AddHours(new Random().Next(24)).AddMinutes(new Random().Next(60)).AddSeconds(new Random().Next(60)),
                Memo           = "Arbies",
                Amount         = 18.95M,
                IsDeleted      = false
            };
            account.CurrentBalance -= transaction.Amount;
            transaction.CategoryItem.ActualAmount += transaction.Amount;

            // so that only one history per day
            history = await context.History
                      .FirstOrDefaultAsync(
                h => h.BankAccount == account &&
                h.Date.Day == transaction.Created.Day);

            if (history == null)
            {
                History _history = new History
                {
                    BankAccountId = transaction.BankAccountId,
                    Balance       = (decimal)account.CurrentBalance,
                    Date          = transaction.Created
                };
                context.Add(_history);
            }
            else
            {
                history.BankAccountId = transaction.BankAccountId;
                history.Balance       = (decimal)account.CurrentBalance;
                history.Date          = transaction.Created;
                context.Update(history);
            }

            context.Add(transaction);
            context.Update(account);
            await context.SaveChangesAsync();

            // SAVINGS 9
            transaction = new Transaction
            {
                Type          = TransactionType.Deposit,
                BankAccountId = account2.Id,
                FPUserId      = user.Id,
                Created       = DateTime.Now.AddDays(-6).AddHours(new Random().Next(24)).AddMinutes(new Random().Next(60)).AddSeconds(new Random().Next(60)),
                Memo          = "20% of income",
                Amount        = 100,
                IsDeleted     = false
            };
            account2.CurrentBalance += transaction.Amount;

            // so that only one history per day
            history = await context.History
                      .FirstOrDefaultAsync(
                h => h.BankAccount == account2 &&
                h.Date.Day == transaction.Created.Day);

            if (history == null)
            {
                History _history = new History
                {
                    BankAccountId = transaction.BankAccountId,
                    Balance       = (decimal)account2.CurrentBalance,
                    Date          = transaction.Created
                };
                context.Add(_history);
            }
            else
            {
                history.BankAccountId = transaction.BankAccountId;
                history.Balance       = (decimal)account2.CurrentBalance;
                history.Date          = transaction.Created;
                context.Update(history);
            }

            context.Add(transaction);
            context.Update(account2);
            await context.SaveChangesAsync();

            // t10
            item        = items.Where(i => i.Name == "Snacks").FirstOrDefault();
            transaction = new Transaction
            {
                Type           = TransactionType.Withdrawal,
                CategoryItemId = item.Id,
                CategoryItem   = item,
                BankAccountId  = account.Id,
                FPUserId       = user.Id,
                Created        = DateTime.Now.AddDays(-5).AddHours(new Random().Next(24)).AddMinutes(new Random().Next(60)).AddSeconds(new Random().Next(60)),
                Memo           = "Chips/pretzels",
                Amount         = 5.65M,
                IsDeleted      = false
            };
            account.CurrentBalance -= transaction.Amount;
            transaction.CategoryItem.ActualAmount += transaction.Amount;

            // so that only one history per day
            history = await context.History
                      .FirstOrDefaultAsync(
                h => h.BankAccount == account &&
                h.Date.Day == transaction.Created.Day);

            if (history == null)
            {
                History _history = new History
                {
                    BankAccountId = transaction.BankAccountId,
                    Balance       = (decimal)account.CurrentBalance,
                    Date          = transaction.Created
                };
                context.Add(_history);
            }
            else
            {
                history.BankAccountId = transaction.BankAccountId;
                history.Balance       = (decimal)account.CurrentBalance;
                history.Date          = transaction.Created;
                context.Update(history);
            }

            context.Add(transaction);
            context.Update(account);
            await context.SaveChangesAsync();

            // SAVINGS 10
            transaction = new Transaction
            {
                Type          = TransactionType.Deposit,
                BankAccountId = account2.Id,
                FPUserId      = user.Id,
                Created       = DateTime.Now.AddDays(-5).AddHours(new Random().Next(24)).AddMinutes(new Random().Next(60)).AddSeconds(new Random().Next(60)),
                Memo          = "20% of income",
                Amount        = 100,
                IsDeleted     = false
            };
            account2.CurrentBalance += transaction.Amount;

            // so that only one history per day
            history = await context.History
                      .FirstOrDefaultAsync(
                h => h.BankAccount == account2 &&
                h.Date.Day == transaction.Created.Day);

            if (history == null)
            {
                History _history = new History
                {
                    BankAccountId = transaction.BankAccountId,
                    Balance       = (decimal)account2.CurrentBalance,
                    Date          = transaction.Created
                };
                context.Add(_history);
            }
            else
            {
                history.BankAccountId = transaction.BankAccountId;
                history.Balance       = (decimal)account2.CurrentBalance;
                history.Date          = transaction.Created;
                context.Update(history);
            }

            context.Add(transaction);
            context.Update(account2);
            await context.SaveChangesAsync();
        }
        private static async Task SeedUsersAsync(UserManager <FPUser> userManager, IFPFileService fileService, IConfiguration configuration, ApplicationDbContext context)
        {
            #region Admin
            var user = new FPUser();
            user.UserName  = "******";
            user.Email     = "*****@*****.**";
            user.FirstName = "Mackenzie";
            user.LastName  = "Weaver";
            user.FileData  = await fileService.GetDefaultAvatarFileBytesAsync();

            user.FileName       = fileService.GetDefaultAvatarFileName();
            user.EmailConfirmed = true;
            try
            {
                var test = await userManager.FindByEmailAsync(user.Email);

                if (test == null)
                {
                    await userManager.CreateAsync(user, "Mweaver1!");

                    await userManager.AddToRoleAsync(user, Roles.Admin.ToString());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("========= ERROR ============");
                Console.WriteLine($"Error Seeding {user.Email}");
                Console.WriteLine(ex.Message);
                Console.WriteLine("============================");
                throw;
            }
            #endregion

            #region Head
            user = new FPUser
            {
                UserName       = "******",
                Email          = "*****@*****.**",
                FirstName      = "Antonio",
                LastName       = "Raynor",
                FileData       = await fileService.GetDefaultAvatarFileBytesAsync(),
                FileName       = fileService.GetDefaultAvatarFileName(),
                EmailConfirmed = true
            };
            try
            {
                var test = await userManager.FindByEmailAsync(user.Email);

                if (test == null)
                {
                    await userManager.CreateAsync(user, "Araynor1!");

                    await userManager.AddToRoleAsync(user, Roles.Head.ToString());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("========= ERROR ============");
                Console.WriteLine($"Error Seeding {user.Email}");
                Console.WriteLine(ex.Message);
                Console.WriteLine("============================");
                throw;
            }
            #endregion

            #region Member
            user = new FPUser
            {
                UserName       = "******",
                Email          = "*****@*****.**",
                FirstName      = "Jason",
                LastName       = "Twichell",
                FileData       = await fileService.GetDefaultAvatarFileBytesAsync(),
                FileName       = fileService.GetDefaultAvatarFileName(),
                EmailConfirmed = true
            };
            try
            {
                var test = await userManager.FindByEmailAsync(user.Email);

                if (test == null)
                {
                    await userManager.CreateAsync(user, "Jtwichell1!");

                    await userManager.AddToRoleAsync(user, Roles.Member.ToString());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("========= ERROR ============");
                Console.WriteLine($"Error Seeding {user.Email}");
                Console.WriteLine(ex.Message);
                Console.WriteLine("============================");
                throw;
            }
            #endregion

            #region New
            user = new FPUser
            {
                UserName       = "******",
                Email          = "*****@*****.**",
                FirstName      = "Drew",
                LastName       = "Russell",
                FileData       = await fileService.GetDefaultAvatarFileBytesAsync(),
                FileName       = fileService.GetDefaultAvatarFileName(),
                EmailConfirmed = true
            };
            try
            {
                var test = await userManager.FindByEmailAsync(user.Email);

                if (test == null)
                {
                    await userManager.CreateAsync(user, "Drussell1!");

                    await userManager.AddToRoleAsync(user, Roles.New.ToString());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("========= ERROR ============");
                Console.WriteLine($"Error Seeding {user.Email}");
                Console.WriteLine(ex.Message);
                Console.WriteLine("============================");
                throw;
            }
            #endregion

            #region Demo
            user           = new FPUser();
            user.UserName  = configuration["DemoEmail"];
            user.Email     = configuration["DemoEmail"];
            user.FirstName = "Rock";
            user.LastName  = "Demo";
            user.FileData  = await fileService.GetDefaultAvatarFileBytesAsync();

            user.FileName       = fileService.GetDefaultAvatarFileName();
            user.EmailConfirmed = true;
            try
            {
                var test = await userManager.FindByEmailAsync(user.Email);

                if (test == null)
                {
                    await userManager.CreateAsync(user, configuration["DemoPassword"]);

                    await userManager.AddToRoleAsync(user, Roles.Head.ToString());

                    await userManager.AddToRoleAsync(user, Roles.Demo.ToString());
                    await SeedAccount(user, context);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("========= ERROR ============");
                Console.WriteLine($"Error Seeding {user.Email}");
                Console.WriteLine(ex.Message);
                Console.WriteLine("============================");
                throw;
            }
            #endregion
        }
        private static async Task SeedItemsAsync(FPUser user, ApplicationDbContext context)
        {
            var item = new CategoryItem
            {
                CategoryId   = context.Category.FirstOrDefault(c => c.HouseHoldId == user.HouseHoldId && c.Name == "House").Id,
                Name         = "Rent",
                Description  = "Monthly rent / mortgage",
                TargetAmount = 1200,
                ActualAmount = 0
            };

            context.Add(item);
            await context.SaveChangesAsync();

            item = new CategoryItem
            {
                CategoryId   = context.Category.FirstOrDefault(c => c.HouseHoldId == user.HouseHoldId && c.Name == "House").Id,
                Name         = "Repairs",
                Description  = "Supplies for any damages done to house",
                TargetAmount = 100,
                ActualAmount = 0
            };
            context.Add(item);
            await context.SaveChangesAsync();

            item = new CategoryItem
            {
                CategoryId   = context.Category.FirstOrDefault(c => c.HouseHoldId == user.HouseHoldId && c.Name == "House").Id,
                Name         = "Lightbulbs",
                Description  = "Supplies for any damages done to house",
                TargetAmount = 20,
                ActualAmount = 0
            };
            context.Add(item);
            await context.SaveChangesAsync();

            item = new CategoryItem
            {
                CategoryId   = context.Category.FirstOrDefault(c => c.HouseHoldId == user.HouseHoldId && c.Name == "Car").Id,
                Name         = "Gas",
                Description  = "Monthly gasoline needed to drive around town",
                TargetAmount = 100,
                ActualAmount = 0
            };
            context.Add(item);
            await context.SaveChangesAsync();

            item = new CategoryItem
            {
                CategoryId   = context.Category.FirstOrDefault(c => c.HouseHoldId == user.HouseHoldId && c.Name == "Car").Id,
                Name         = "Insurance",
                Description  = "Government requirement",
                TargetAmount = 200,
                ActualAmount = 0
            };
            context.Add(item);
            await context.SaveChangesAsync();

            item = new CategoryItem
            {
                CategoryId   = context.Category.FirstOrDefault(c => c.HouseHoldId == user.HouseHoldId && c.Name == "Car").Id,
                Name         = "Oil Change",
                Description  = "Only needed once every three months",
                TargetAmount = (decimal)(29.99 / 3),
                ActualAmount = 0
            };
            context.Add(item);
            await context.SaveChangesAsync();

            item = new CategoryItem
            {
                CategoryId   = context.Category.FirstOrDefault(c => c.HouseHoldId == user.HouseHoldId && c.Name == "Food").Id,
                Name         = "Walmart",
                Description  = "General groceries",
                TargetAmount = 400,
                ActualAmount = 0
            };
            context.Add(item);
            await context.SaveChangesAsync();

            item = new CategoryItem
            {
                CategoryId   = context.Category.FirstOrDefault(c => c.HouseHoldId == user.HouseHoldId && c.Name == "Food").Id,
                Name         = "Restaurants",
                Description  = "Eating out",
                TargetAmount = 100,
                ActualAmount = 0
            };
            context.Add(item);
            await context.SaveChangesAsync();

            item = new CategoryItem
            {
                CategoryId   = context.Category.FirstOrDefault(c => c.HouseHoldId == user.HouseHoldId && c.Name == "Food").Id,
                Name         = "Snacks",
                Description  = "Lil extras every now and then",
                TargetAmount = 50,
                ActualAmount = 0
            };
            context.Add(item);
            await context.SaveChangesAsync();
        }
Example #30
0
        public bool isValid(FPUser obj)
        {
            bool isValid = !obj.Errors.Any();

            return(isValid);
        }