Пример #1
0
 public ActionResult Create(DateTime date)
 {
     TodoItem todoItem = new TodoItem();
     todoItem.StartTime = date;
     todoItem.UserId = User.Identity.Name;
     todoItem.Done = false;
     todoItem.SortNum = 0;
     var priorities = Enum.GetValues(typeof(Priority)).Cast<Priority>().Select(e => new { Value = (int)e, Text = e.ToString() });
     ViewData["PriorityId"] = new SelectList(priorities, "Value", "Text");
     return PartialView("_TodoItemForm", todoItem);
 }
Пример #2
0
        public ActionResult Details(int id)
        {
            TodoItem todoItem = _repositoryTodoItem.Query.FirstOrDefault(c => c.Id == id);

            if (todoItem == null)
            {
                todoItem = new TodoItem();
                todoItem.StartTime = DateTime.Now;
                todoItem.UserId = User.Identity.Name;
                todoItem.Done = false;
                todoItem.SortNum = 0;
                return PartialView("_TodoItemForm", todoItem);
            }

            return PartialView("_TodoItemDetails", todoItem);
        }
Пример #3
0
 public ActionResult Edit(int id)
 {
     TodoItem todoItem = _repositoryTodoItem.Query.FirstOrDefault(c => c.Id == id);
     if (todoItem.Done == true)
     {
         return PartialView("_TodoItemDetails", todoItem);
     }
     if (todoItem == null)
     {
         todoItem = new TodoItem();
         todoItem.StartTime = DateTime.Now;
         todoItem.UserId = User.Identity.Name;
         todoItem.Done = false;
         todoItem.SortNum = 0;
     }
     var priorities = Enum.GetValues(typeof(Priority)).Cast<Priority>().Select(e => new { Value = (int)e, Text = e.ToString() });
     ViewData["PriorityId"] = new SelectList(priorities, "Value", "Text", todoItem.PriorityId);
     return PartialView("_TodoItemForm", todoItem);
 }
Пример #4
0
        public JsonResult Save(TodoItem todoItem)
        {
            string Message = "";
            try
            {
                if (ModelState.IsValid)
                {
                    if (todoItem.Id == 0)
                    {
                        if (String.IsNullOrEmpty(todoItem.Title))
                        {
                            Message = "Title field must not be empty";
                            return Json(new { Success = false, Msg = Message });
                        }
                        Message = "Task was successfully created!";
                        _repositoryTodoItem.Add(todoItem);
                    }
                    else if (todoItem.Id > 0)
                    {
                        if (todoItem.UserId != User.Identity.Name)
                        {
                            Message = "You have no rights in changing this task. you have not created it!";
                            return Json(new { Success = false, Msg = Message });
                        }
                        Message = "Task was successfully updated.";
                        _repositoryTodoItem.Edit(todoItem);
                    }
                    _repositoryTodoItem.SaveChanges();

                    return Json(new { Success = todoItem.Id >= 0, Msg = Message });
                }
                else
                {
                    Message = "You have entered data in invalid form. Common problem is invalid datetime. Preferred datetime format is: dd:mm:yyyy hh:mm.";
                }
            }
            catch (DataException)
            {
                Message = "An error occured while saving changes.";
            }

            return Json(new { Success = false, Msg = Message });
        }