// GET api/<controller> public List<DeveloperTO> GetAllDevelopers() { List<DeveloperTO> developers = new List<DeveloperTO>(); using (var db = new WamAppEntities1()) { var devs = from d in db.Developers select d; foreach(Developer d in devs) { DeveloperTO dev = new DeveloperTO { id = d.Id, password = d.password, username = d.username }; developers.Add(dev); } } /* DeveloperTO d1 = new DeveloperTO { id=123, username = "******", password = "******" }; DeveloperTO d2 = new DeveloperTO { id=234, username = "******", password = "******" }; DeveloperTO d3 = new DeveloperTO { id=345, username = "******", password = "******" }; developers.Add(d1); developers.Add(d2); developers.Add(d3); * */ return developers; }
// GET api/<controller>/5 public DeveloperTO GetDeveloper(int id) { DeveloperTO d4 = null;// new DeveloperTO { id = id, username = "******" + id, password = "******" }; using (var db = new WamAppEntities1()) { Developer dev = db.Developers.Find(id); d4 = new DeveloperTO { id = dev.Id, username = dev.username, password = dev.password }; } return d4; }
public DeveloperTO GetDeveloperByUsername(string username) { DeveloperTO d5 = null; using (var db = new WamAppEntities1()) { var devs = from d in db.Developers where d.username==username select d; Developer dd = devs.FirstOrDefault(); if(dd != null) d5 = new DeveloperTO { id = dd.Id, password = dd.password, username = dd.username }; } return d5; }
// PUT api/<controller>/5 public string PutDeveloper(int id, DeveloperTO developer) { using (var db = new WamAppEntities1()) { Developer dev = db.Developers.Find(id); dev.password = developer.password; db.SaveChanges(); } return developer.username + " " + id; }
// POST api/<controller> public string PostDeveloper(DeveloperTO developer) { using(var db = new WamAppEntities1()) { Developer newDeveloper = new Developer(); newDeveloper.username = developer.username; newDeveloper.password = developer.password; db.Developers.Add(newDeveloper); db.SaveChanges(); } return developer.username; }