public HttpResponseMessage SaveMstProject(MstProject project) { try { var MstProjectData = from d in db.MstProjects where d.Id == Convert.ToInt32(project.Id) select d; if (MstProjectData.Any()) { if (MstProjectData.FirstOrDefault().IsLocked == false) { var currentUser = from d in db.MstUsers where d.AspNetId == User.Identity.GetUserId() select d; if (currentUser.Any()) { var UpdateProjectData = MstProjectData.FirstOrDefault(); UpdateProjectData.ProjectCode = project.ProjectCode; UpdateProjectData.Project = project.Project; UpdateProjectData.Address = project.Address; UpdateProjectData.Status = project.Status; UpdateProjectData.ProjectLogo = project.ProjectLogo; UpdateProjectData.UpdatedBy = currentUser.FirstOrDefault().Id; UpdateProjectData.UpdatedDateTime = DateTime.Now; db.SubmitChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } } else { return(Request.CreateResponse(HttpStatusCode.OK)); } } catch (Exception e) { Debug.WriteLine(e); return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }
public Int32 PostMstProject(MstProject project) { try { var currentUser = from d in db.MstUsers where d.AspNetId == User.Identity.GetUserId() select d; if (currentUser.Any()) { string projectCode = "0001"; var projects = from d in db.MstProjects.OrderByDescending(d => d.Id) select d; if (projects.Any()) { Int32 nextProjectCode = Convert.ToInt32(projects.FirstOrDefault().ProjectCode) + 1; projectCode = padNumWithZero(nextProjectCode, 4); } Data.MstProject newMstProject = new Data.MstProject() { ProjectCode = projectCode, Project = project.Project, Address = project.Address, Status = project.Status, ProjectLogo = project.ProjectLogo, IsLocked = project.IsLocked, CreatedBy = currentUser.FirstOrDefault().Id, CreatedDateTime = DateTime.Now, UpdatedBy = currentUser.FirstOrDefault().Id, UpdatedDateTime = DateTime.Now }; db.MstProjects.InsertOnSubmit(newMstProject); db.SubmitChanges(); return(newMstProject.Id); } else { return(0); } } catch (Exception e) { Debug.WriteLine(e); return(0); } }