Esempio n. 1
0
        public ActionResult Create(Budget budget)
        {
            string        currentUser = Session["UserId"].ToString();
            int           uid         = Int32.Parse(currentUser);
            List <Budget> budgetList  = db.GetBudgetList();


            if (Session["UserName"] == null)
            {
                return(RedirectToAction("Login", "Authentication"));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    budget.UserId = int.TryParse(Session["UserId"].ToString(), out var result) ? result : -1;
                    if (budgetList.Where(a => a.UserId == uid).Count() >= 1)
                    {
                        //Wyciagniecie 2 wstecz
                        //var _budget = budgetList.Where(a => a.UserId == uid).OrderByDescending(a => a.BudgetId).Take(2).OrderBy(a => a.BudgetId).FirstOrDefault();
                        var _budget = budgetList.Where(a => a.UserId == uid).OrderByDescending(a => a.BudgetId).FirstOrDefault();
                        _budget.EndBudgetDate = budget.SalaryDate.Value.AddDays(-1);
                    }
                    db.Budgets.Add(budget);
                    db.SaveChanges();
                    return(RedirectToAction("List", "Budget"));
                }
                return(View(budget));
            }
        }
 public ActionResult Create(Expense expense)
 {
     if (ModelState.IsValidField("Typ") && ModelState.IsValidField("Nazwa wydatku") && ModelState.IsValidField("Data zrealizowania wydatku"))
     {
         expense.UserId = int.TryParse(Session["UserId"].ToString(), out var result) ? result : -1;
         db.Expenses.Add(expense);
         db.SaveChanges();
         return(RedirectToAction("List", "Expense"));
     }
     return(View(expense));
 }
Esempio n. 3
0
        public ActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                string data1 = user.Password;
                string data2 = user.ConfirmPassword;
                user.Password        = helper.EncryptedPassword(data1, "h@sheD");
                user.ConfirmPassword = helper.EncryptedPassword(data2, "h@sheD");
                db.Users.Add(user);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            return(View(user));
        }
Esempio n. 4
0
 public static void saveNewTodoItem(TodoItem oTodoItem)
 {
     using (var db = new OrganizerDBContext()){
         db.TodoItems.Add(oTodoItem);
         db.Entry(oTodoItem).State = System.Data.EntityState.Added;
         db.SaveChanges();
     }
 }
Esempio n. 5
0
 public static void updateTodoItem(TodoItem oTodoItem)
 {
     using (var db = new OrganizerDBContext())
     {
         db.TodoItems.Attach(oTodoItem);
         db.Entry(oTodoItem).State = System.Data.EntityState.Modified;
         db.SaveChanges();
     }
 }
Esempio n. 6
0
        public static void deleteTodoItemById(int id)
        {
            TodoItem todoItem = getAppUserByUserName(HttpContext.Current.User.Identity.Name).ThingsTodo.FirstOrDefault(p => p.Id == id);

            using (var db = new OrganizerDBContext()){
                db.Entry(todoItem).State = System.Data.EntityState.Deleted;
                db.SaveChanges();
            }
        }
Esempio n. 7
0
        public static void saveTodoItem(TodoItemDTO todoItemDTO)
        {
            using (var db = new OrganizerDBContext()){
                AppUser appUser =
                    db.
                    AppUsers.
                    Include("ThingsTodo").
                    Single(p => p.UserName == HttpContext.Current.User.Identity.Name);
                appUser.ThingsTodo.Add(
                    new TodoItem {
                    CategoryId = todoItemDTO.SelectedCategoryId, Title = todoItemDTO.Title, Completed = false
                }
                    );


                db.AppUsers.Attach(appUser);
                db.Entry(appUser).State = System.Data.EntityState.Modified;
                db.SaveChanges();
            }
        }
Esempio n. 8
0
        public static bool registerUser(RegisterDTO oDTO)
        {
            if (!isUserNameUnique(oDTO.UserName))
            {
                return(false);
            }


            using (var db = new OrganizerDBContext())
            {
                AppUser oAppUser = new AppUser();
                oAppUser.UserName = oDTO.UserName;
                oAppUser.Password = PasswordHash.CreateHash(oDTO.Password);

                db.AppUsers.Add(oAppUser);
                db.Entry(oAppUser).State = System.Data.EntityState.Added;
                db.SaveChanges();
            }
            return(true);
        }
Esempio n. 9
0
        public static void EditTodoItem(TodoItemDTO todoItemDTO, int todoItemId)
        {
            TodoItem todoItem =
                getAppUserByUserName(HttpContext.Current.User.Identity.Name).
                ThingsTodo.
                FirstOrDefault(p => p.Id == todoItemId);

            if (todoItem == null)
            {
                throw new Exception("Access denied");
            }


            todoItem.CategoryId = todoItemDTO.SelectedCategoryId;
            todoItem.Completed  = todoItemDTO.SelectedCompletedId == 0 ? false : true;
            todoItem.Title      = todoItemDTO.Title;

            using (var db = new OrganizerDBContext())
            {
                db.TodoItems.Attach(todoItem);
                db.Entry(todoItem).State = System.Data.EntityState.Modified;
                db.SaveChanges();
            }
        }