public ActionResult Delete(SaveTaskViewModel model) { var task = _taskService.Get(model.Id); if (task == null) { return(new HttpStatusCodeResult(400, "Error deleting task [id = " + model.Id + "]!")); } _taskService.Delete(task.Id); return(Json(new { Message = "Task deleted!" })); }
public ActionResult Save(SaveTaskViewModel model) { if (model.Summary == null || model.Summary.Length < 10) { return(new HttpStatusCodeResult(400, "Your summary is to short!")); } var user = _userService.Get(User.Identity.Name); var timezone = TimeZoneInfo.FindSystemTimeZoneById(user.TimeZoneId); model.From = DateTime.SpecifyKind(model.From, DateTimeKind.Unspecified); model.To = DateTime.SpecifyKind(model.To, DateTimeKind.Unspecified); model.From = TimeZoneInfo.ConvertTime(model.From, timezone, TimeZoneInfo.Utc); model.To = TimeZoneInfo.ConvertTime(model.To, timezone, TimeZoneInfo.Utc); var userId = _userService.Get(User.Identity.Name).Id; Task task; if (model.Id == -1) { task = new Task() { From = model.From.ToUniversalTime(), To = model.To.ToUniversalTime(), Summary = model.Summary, ProjectId = model.ProjectId, UserId = userId }; int id = _taskService.Add(task); return(Json(new { Message = "Task created!", Id = id })); } task = _taskService.Get(model.Id); if (task == null) { return(new HttpStatusCodeResult(400, "Error updating task [id = " + model.Id + "]!")); } task.Summary = model.Summary; task.From = model.From; task.To = model.To; task.ProjectId = model.ProjectId; _taskService.Update(task); return(Json(new { Message = "Task updated!", Id = task.Id })); }