// GET api/assignment public IEnumerable<AssignmentModel> Get() { using (BasicDao context = new BasicDao()) { var allAssignments = context.GetAll<ProjectAssignment>().Select(x => new AssignmentModel() { Id = x.Id, PersonId = x.PersonId, PersonUsername = x.Person.Username, ProjectId = x.ProjectId }).ToList(); return allAssignments; } }
// POST api/assignment public ProjectAssignment Post(AssignmentModel model) { using (BasicDao context = new BasicDao()) { ProjectAssignment newAssignment = new ProjectAssignment(); newAssignment.PersonId = model.PersonId; newAssignment.ProjectId = model.ProjectId; context.Insert(newAssignment); return newAssignment; } }
internal void CreateProject(ProjectModel projectModel) { using (BasicDao context = new BasicDao()) { Project newProject = new Project(); newProject.Name = projectModel.Name; newProject.Code = projectModel.Code; newProject.Budget = projectModel.Budget; newProject.Remarks = projectModel.Remarks; context.Insert(newProject); } }
internal void CreatePerson(PersonModel personModel) { using (BasicDao context = new BasicDao()) { Person newPerson = new Person(); newPerson.Username = personModel.Username; newPerson.Password = personModel.Password; newPerson.FirstName = personModel.FirstName; newPerson.LastName = personModel.LastName; context.Insert(newPerson); } }
// DELETE api/assignment/5 public void Delete(int id) { using (BasicDao context = new BasicDao()) { context.Delete<ProjectAssignment>(id); } }
internal void PopulateProjects() { using (BasicDao context = new BasicDao()) { Projects = context.db.Projects.Select(x => new ProjectModel() { Id=x.Id, Name=x.Name, Budget=x.Budget }).ToList(); } }