Exemple #1
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();
            }
        }
Exemple #2
0
        public ActionResult Edit(string id)
        {
            TodoItem todoItem = DBHandler.getTodoItemById(int.Parse(id));
            if (todoItem == null)
                RedirectToAction("Index");

            TodoItemDTO todoItemDTO = new TodoItemDTO();

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

            SelectListItem completedSelectItem = todoItemDTO.Completed.Where(p => int.Parse(p.Value) == todoItemDTO.SelectedCompletedId).FirstOrDefault();
            if (completedSelectItem != null)
                completedSelectItem.Selected = true;

            SelectListItem selectItem = todoItemDTO.Categories.Where(p => int.Parse(p.Value) == todoItem.CategoryId).FirstOrDefault();
            if (selectItem != null)
                selectItem.Selected = true;

            ViewData.Model = todoItemDTO;
            return View();
        }
Exemple #3
0
 public ActionResult Edit(TodoItemDTO oTodo, string id)
 {
     DBHandler.EditTodoItem(oTodo, int.Parse(id));
     return RedirectToAction("Index");
 }
Exemple #4
0
 public ActionResult Create(TodoItemDTO oTodo)
 {
     DBHandler.saveTodoItem(oTodo);
     return RedirectToAction("Index");
 }
Exemple #5
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();
            }
        }