public ActionResult Create([Bind(Include = "Id,Name")] DefaultCategory defaultCategory)
        {
            if (ModelState.IsValid)
            {
                db.DefaultCategories.Add(defaultCategory);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(defaultCategory));
        }
        public ActionResult Create([Bind(Include = "Id,Name,IsActive,IsChosen")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
        public void Update(Category item)
        {
            category = GetById(item.Id);

            if (category == null)
            {
                throw new ArgumentNullException("Spending Category not found");
            }

            defaultCategory = defaultCategoryRepo.GetByName(category);
            if (defaultCategory != null)
            {
                throw new Exception("You cannot change Default Category");
            }

            category.Name     = item.Name;
            category.IsActive = true;

            using (var context = new BudgetWatcherContext())
            {
                context.Categories.Attach(category);
                context.Entry(category).State = EntityState.Modified;
                context.SaveChanges();
            }
        }
Beispiel #4
0
        public void Add(Spending item)
        {
            spending.Description  = item.Description;
            spending.SpendingDate = DateTime.Now;
            spending.MoneySpent   = item.MoneySpent;

            using (var context = new BudgetWatcherContext())
            {
                context.Spendings.Add(spending);
                context.SaveChanges();
            }
        }
 public void Delete(Category item)
 {
     category          = GetById(item.Id);
     category.IsActive = false;
     category.IsChosen = false;
     using (var context = new BudgetWatcherContext())
     {
         context.Categories.Attach(category);
         context.Entry(category).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Beispiel #6
0
        public void Add(User item)
        {
            user.Email     = item.Email;
            user.Password  = item.Password;
            user.FirstName = item.FirstName;
            user.LastName  = item.LastName;

            using (var context = new BudgetWatcherContext())
            {
                context.Users.Add(user);
                context.SaveChanges();
            }
        }
Beispiel #7
0
        public void Delete(Budget item)
        {
            budget = GetById(item.Id);

            if (budget == null)
            {
                throw new ArgumentNullException("Budget not found");
            }

            using (var context = new BudgetWatcherContext())
            {
                context.Budgets.Attach(budget);
                context.Budgets.Remove(budget);
                context.SaveChanges();
            }
        }
Beispiel #8
0
        public void ChangeBalance(Budget item)
        {
            budget = GetById(item.Id);
            if (budget == null)
            {
                throw new ArgumentNullException("Budget not found");
            }
            budget.Balance = item.Balance;

            using (var context = new BudgetWatcherContext())
            {
                context.Budgets.Attach(budget);
                context.Entry(budget).State = EntityState.Modified;
                context.SaveChanges();
            }
        }
Beispiel #9
0
        public void Delete(User item)
        {
            user = GetById(item.Id);

            if (user == null)
            {
                throw new ArgumentNullException("Please choose existing user to delete");
            }

            using (var context = new BudgetWatcherContext())
            {
                context.Users.Attach(user);
                context.Users.Remove(user);
                context.SaveChanges();
            }
        }
Beispiel #10
0
        public void Update(Spending item)
        {
            spending = GetById(item.Id);

            if (spending == null)
            {
                throw new ArgumentNullException("Ooops, something wrong occured :)");
            }

            spending.Description  = item.Description;
            spending.SpendingDate = DateTime.Now;
            spending.MoneySpent   = item.MoneySpent;

            using (var context = new BudgetWatcherContext())
            {
                context.Spendings.Attach(spending);
                context.Entry(spending).State = EntityState.Modified;
                context.SaveChanges();
            }
        }
        public void Add(Category item)
        {
            defaultCategory = defaultCategoryRepo.GetByName(item);

            if (defaultCategory != null)
            {
                item.DefaultCategories.Add(defaultCategory);
            }
            else
            {
                item.DefaultCategories.Add(null);
            }

            category.Name     = item.Name;
            category.IsActive = true;
            category.IsChosen = item.IsChosen;

            using (var context = new BudgetWatcherContext())
            {
                context.Categories.Add(category);
                context.SaveChanges();
            }
        }
Beispiel #12
0
        public void Update(User item)
        {
            user = GetById(item.Id);

            if (user != null)
            {
                user.Email     = item.Email;
                user.Password  = item.Password;
                user.FirstName = item.FirstName;
                user.LastName  = item.LastName;
            }
            else
            {
                throw new ArgumentNullException("The user is not found");
            }

            using (var context = new BudgetWatcherContext())
            {
                context.Users.Attach(user);
                context.Entry(user).State = EntityState.Modified;
                context.SaveChanges();
            }
        }