Ejemplo n.º 1
0
        public PaycheckBudgetResponse AddBudget(PaycheckBudgetViewModel budgetViewModel)
        {
            var budget = new Budget
            {
                BudgetAmount = budgetViewModel.Amount,
                BudgetDate   = budgetViewModel.Date
            };

            foreach (var budgetItem in budgetViewModel.BudgetItems)
            {
                budget.BudgetItems.Add(new BudgetItem
                {
                    Amount      = budgetItem.Amount,
                    Description = budgetItem.Description,
                    IsPaid      = budgetItem.IsPaid,
                    DueDate     = budgetItem.DueDate,
                    DatePaid    = budgetItem.DueDate                  // When adding a new budget, the date paid has to have a valid date, so give it the due date.
                });
            }

            _db.Budgets.AddObject(budget);
            _db.SaveChanges();

            return(GetCurrentBudgets());
        }
Ejemplo n.º 2
0
        public ActionResult Create([Bind(Include = "CategoryID,CategoryName")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
Ejemplo n.º 3
0
        public void LogUserLogin(User currentUser, ExpenseTrackerEntities _db, HttpContext currentContext)
        {
            //currentUser.LastLoggedIn = DateTime.Now;
            currentUser.LAST_ACCESS_IP = ExpenseTracker.Utilities.Web.GetClientIPAddress(currentContext);

            _db.SaveChanges();
        }
Ejemplo n.º 4
0
        public void Add(DTO.ExpenseGroup newItem)
        {
            Entities.ExpenseGroup newEntity = _mapper.CreateEntityFromDTO(newItem) as Entities.ExpenseGroup;

            db.ExpenseGroups.Add(newEntity);

            db.SaveChanges();
        }
Ejemplo n.º 5
0
        public ActionResult Create([Bind(Include = "ItemId,ItemName,ItemCategory,ItemAmount,ExpeseDate,CategoryId,UserId")] Item item)
        {
            if (ModelState.IsValid)
            {
                //  var  = User.Identity.Name;

                item.UserId       = db.Users.Where(x => x.UserName == User.Identity.Name).FirstOrDefault().UserId;
                item.ItemCategory = db.Categories.Where(x => x.CategoryID == item.CategoryId).FirstOrDefault().CategoryName;
                db.Items.Add(item);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId = new SelectList(db.Categories, "CategoryID", "CategoryName", item.CategoryId);
            ViewBag.UserId     = new SelectList(db.Users, "UserId", "UserName", item.UserId);
            return(View(item));
        }
Ejemplo n.º 6
0
        public void Add(T newItem)
        {
            Entities.IEntity newEntity = _mapper.CreateEntityFromDTO(newItem);

            Type entityType = newEntity.GetType();

            db.Set(entityType).Add(newEntity);

            db.SaveChanges();
        }
Ejemplo n.º 7
0
 public override bool ValidateUser(string username, string password)
 {
     using (ExpenseTrackerEntities _db = new ExpenseTrackerEntities())
     {
         try
         {
             var user = _db.Users.FirstOrDefault(u => u.UserEmail == username);
             user.UserPassword = password;
             _db.SaveChanges();
             if (user != null)
             {
                 //Update on every login validation success
                 this.LogUserLogin(user, _db, HttpContext.Current);
                 return(true);
             }
         }
         catch (Exception ex)
         {
         }
         return(false);
     }
 }
Ejemplo n.º 8
0
        public ActionResult Index(User user)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    user.UserRole = "U";
                    _context.Users.Add(user);

                    _context.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View("Index"));
                }
            }

            catch (Exception e1)
            {
                return(RedirectToAction("Index"));
            }
        }