/// <summary> /// Create a new project. /// </summary> /// <remarks> /// Request is redirected to the location of the newly added project. /// </remarks> /// <param name="newProject">New project.</param> /// <returns>201 Created</returns> public void Add(Project newProject) { // Clone the object sent from the client. var project = new Project(_user); project.Summary = newProject.Summary; project.Description = newProject.Description; project.JournalEntries = newProject.JournalEntries; project.Resources = newProject.Resources; project = _ctx.Save<Project>(project); if (WebOperationContext.Current != null) { WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Created; WebOperationContext.Current.OutgoingResponse.Location = "/project/" + project.Id; } }
/// <summary> /// Save changes to a project. /// </summary> /// <param name="id">Unique identifier for the project.</param> /// <param name="project">Updated project.</param> /// <exception cref="System.Exception">Returns 304 NotModified if an exception occurs /// while saving the project.</exception> public void Update(string id, Project project) { var previous = GetProject(id); if (previous != null) Delete(id); try { _ctx.Save<Project>(project); } catch (Exception ex) { if (previous != null) _ctx.Save<Project>(previous); if (WebOperationContext.Current != null) { WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.NotModified; } Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write(ex); } }