public static int CreateProject(project prj) { int id = -1; SanityDataModelDataContext context = new SanityDataModelDataContext(ConnectionString); try { context.projects.InsertOnSubmit(prj); context.SubmitChanges(); id = prj.ID; } catch (Exception ex) { } return id; }
// PUT api/values/5 public HttpResponseMessage Put(int id, [FromBody]serProject prj) { bool sucessful = false; DataManager.ConnectionString = connectionString; if (prj != null) { project project = new project() { ID=prj.ID, Description = prj.Description, Notes = prj.Notes, JobNumber = prj.JobNumber, Created = prj.Created == DateTime.MinValue ? (DateTime?)null : prj.Created }; sucessful = DataManager.UpdateProject(project); } if (sucessful) { return Request.CreateResponse(HttpStatusCode.OK); } else { return Request.CreateResponse(HttpStatusCode.InternalServerError); } }
// POST api/values public HttpResponseMessage Post([FromBody]serProject prj) { DataManager.ConnectionString = connectionString; int id = -1; if (prj != null) { project project = new project() { Description = prj.Description, Notes = prj.Notes, JobNumber = prj.JobNumber, Created = DateTime.Now }; id = DataManager.CreateProject(project); } if (id > -1) { return Request.CreateResponse(HttpStatusCode.OK); } else { return Request.CreateResponse(HttpStatusCode.InternalServerError); } }
partial void Deleteproject(project instance);
partial void Updateproject(project instance);
partial void Insertproject(project instance);
public static bool UpdateProject(project prj) { bool sucessful = false; SanityDataModelDataContext context = new SanityDataModelDataContext(ConnectionString); var qry = from P in context.projects where P.ID == prj.ID select P; project p = qry.FirstOrDefault(); if(p!=null) { p.Created = prj.Created; p.Description = prj.Description; p.JobNumber = prj.JobNumber; p.Notes = prj.Notes; context.SubmitChanges(); sucessful = true; } return sucessful; }