public IEnumerable <ExpenseCategory> GetAllCategories()
 {
     using (var ctx = new ManageExpensesContext2())
     {
         return(ctx.ExpenseCategiries.ToList());
     }
 }
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory(CreateKernel()));
            using (var ctx = new ManageExpensesContext2())
            {
                //var user = new User()
                //{

                //    FirstName = "Agnieszka",
                //    LastName = "KOwalska",
                //    Login = "******",
                //    Password = "******",
                //    DateOfBirth = DateTime.Now.AddYears(-10)
                //};
                //ctx.Users.Add(user);
                //ctx.SaveChanges();

                var users = ctx.Users.ToList();
            }
        }
        public void Update(EditExpenseCategoryModel model)
        {
            using (var ctx = new ManageExpensesContext2())
            {
                var category = ctx.ExpenseCategiries.Where(c => c.Id == model.Id).Single();

                category.Name = model.Name;
                ctx.SaveChanges();
            }
        }
Example #4
0
        public void Delete(long id)
        {
            using (var ctx = new ManageExpensesContext2())
            {
                var userToDelete = ctx.Users.Where(u => u.Id == id).Single();
                ctx.Users.Remove(userToDelete);

                ctx.SaveChanges();
            }
        }
 public EditExpenseCategoryModel GetCategoryById(long id)
 {
     using (var ctx = new ManageExpensesContext2())
     {
         return(ctx.ExpenseCategiries.Where(c => c.Id == id)
                .Select(c => new EditExpenseCategoryModel
         {
             Id = c.Id,
             Name = c.Name
         }).Single());
     }
 }
 public void Edit(EditExpenseCategoryModel model)
 {
     using (var ctx = new ManageExpensesContext2())
     {
         ExpenseCategory category = ctx.ExpenseCategiries.SingleOrDefault(c => c.Id == model.Id);
         if (category != null)
         {
             category.Name = model.Name;
         }
         ctx.SaveChanges();
     }
 }
        public void Add(AddExpenseCategoryModel model)
        {
            using (var ctx = new ManageExpensesContext2())
            {
                ExpenseCategory category = new ExpenseCategory
                {
                    Name = model.Name
                };

                ctx.ExpenseCategiries.Add(category);
                ctx.SaveChanges();
            }
        }
Example #8
0
 public IEnumerable <UserListItemModel> GetAllUsers()
 {
     using (var ctx = new ManageExpensesContext2())
     {
         return(ctx.Users.Select(u => new UserListItemModel
         {
             Id = u.Id,
             Login = u.Login,
             FirstName = u.FirstName,
             LastName = u.LastName
         }).ToList());
     }
 }
Example #9
0
        public void Update(EditUserModel model)
        {
            using (var ctx = new ManageExpensesContext2())
            {
                var user = ctx.Users.Where(u => u.Id == model.Id).Single();

                user.FirstName = model.FirstName;
                user.LastName  = model.LastName;
                user.Password  = model.Password;

                ctx.SaveChanges();
            }
        }
        public void Remove(long id)
        {
            using (var ctx = new ManageExpensesContext2())
            {
                var expenseToRemove = ctx.Expenses.SingleOrDefault(e => e.Id == id);
                if (expenseToRemove != null)
                {
                    ctx.Expenses.Remove(expenseToRemove);
                }

                ctx.SaveChanges();
            }
        }
 public IEnumerable <ExpenseListItemModel> GetExpensesForCurrentUser(long categoryId)
 {
     using (var ctx = new ManageExpensesContext2())
     {
         return(ctx.Expenses.Where(e => e.Category.Id == categoryId).Select(e => new ExpenseListItemModel
         {
             Id = e.Id,
             Name = e.Name,
             CategoryName = e.Category.Name,
             Value = e.Value
         }).ToList());
     }
 }
Example #12
0
        public void Add(AddUserModel model)
        {
            using (var ctx = new ManageExpensesContext2())
            {
                var user = new User()
                {
                    FirstName   = model.FirstName,
                    LastName    = model.LastName,
                    Login       = model.Login,
                    Password    = model.Password,
                    DateOfBirth = model.DateOfBirth
                };

                ctx.Users.Add(user);
                ctx.SaveChanges();
            }
        }
Example #13
0
        public EditUserModel GetUserById(long id)
        {
            using (var ctx = new ManageExpensesContext2())
            {
                return(ctx.Users.Where(u => u.Id == id)
                       .Select(u => new EditUserModel
                {
                    Id = u.Id,
                    FirstName = u.FirstName,
                    LastName = u.LastName,
                    Password = u.Password
                }).Single());
            }


            //IList<User> result = new List<User>();
            //foreach(var user in _users)
            //{
            //	if (user.Id == id)
            //		result.Add(user);
            //}
        }
        public void Add(AddExpenseModel model)
        {
            using (var ctx = new ManageExpensesContext2())
            {
                var currentUserId = _currentUserProvider.GetCurrentUserId();
                var user          = ctx.Users.Find(currentUserId);

                ExpenseCategory category = ctx.ExpenseCategiries.SingleOrDefault(ec => ec.Id == model.CategoryId);
                //User user = ctx.Users.SingleOrDefault(u => u.Id == model.UserId);


                Expense expense = new Expense()
                {
                    User     = user,
                    Category = category,
                    Name     = model.Name,
                    Value    = model.Value
                };
                ctx.Expenses.Add(expense);
                ctx.SaveChanges();
            }
        }