public Task CreateTask(Data.Model.Task modelTask) { var task = new Task { TaskId = modelTask.TaskId, Subject = modelTask.Subject, StartDate = modelTask.StartDate, DateCompleted = modelTask.DateCompleted, DueDate = modelTask.DueDate, CreatedDate = modelTask.CreatedDate, Status = _statusMapper.CreateStatus(modelTask.Status), Priority = _priorityMapper.CreatePriority(modelTask.Priority), Categories = modelTask .Categories .Select(_categoryMapper.CreateCategory) .ToList(), Assignees = modelTask .Users .Select(_userMapper.CreateUser) .ToList() }; task.Links = new List<Link> { new Link { Title = "self", Rel = "self", Href = "/api/tasks/" + task.TaskId }, new Link { Title = "Categories", Rel = "categories", Href = "/api/tasks/" + task.TaskId + "/categories" }, new Link { Title = "Assignees", Rel = "users", Href = "/api/tasks/" + task.TaskId + "/users" } }; return task; }
public HttpResponseMessage Post(HttpRequestMessage request, Task task) { var currentUser = _session.Get<Data.Model.User>(_userSession.UserId); var modelTask = new Data.Model.Task { CreatedDate = _dateTime.UtcNow, CreatedBy = currentUser, Subject = task.Subject, DateCompleted = task.DateCompleted, DueDate = task.DueDate, StartDate = task.StartDate, Priority = _session.Get<Data.Model.Priority>(task.Priority.PriorityId), Status = _session.Get<Data.Model.Status>(task.Status.StatusId) }; foreach (var category in task.Categories) { var modelCategory = _session.Get<Data.Model.Category>(category.CategoryId); modelTask.Categories.Add(modelCategory); } foreach (var user in task.Assignees) { var modelUser = _session.Get<Data.Model.User>(user.UserId); modelTask.Users.Add(modelUser); } _session.SaveOrUpdate(modelTask); var newTask = _taskMapper.CreateTask(modelTask); var href = newTask.Links.First(x => x.Rel == "self").Href; var response = request.CreateResponse(HttpStatusCode.Created, newTask); response.Headers.Add("Location", href); return response; }
public Task Put(HttpRequestMessage request, Task task) { var modelTask = _taskFetcher.GetTask(task.TaskId); modelTask.Subject = task.Subject; modelTask.DateCompleted = task.DateCompleted; modelTask.DueDate = task.DueDate; modelTask.StartDate = task.StartDate; modelTask.Priority = _session.Get<Data.Model.Priority>(task.Priority.PriorityId); modelTask.Status = _session.Get<Data.Model.Status>(task.Status.StatusId); modelTask.Categories.Clear(); foreach (var category in task.Categories) { var modelCategory = _session.Get<Data.Model.Category>(category.CategoryId); modelTask.Categories.Add(modelCategory); } modelTask.Users.Clear(); foreach (var user in task.Assignees) { var modelUser = _session.Get<Data.Model.User>(user.UserId); modelTask.Users.Add(modelUser); } _session.SaveOrUpdate(modelTask); return _taskMapper.CreateTask(modelTask); }