public XElement GetRecruitById(string recruitId) { // criar um recruta que vai ser recuperado Recruits recruit = new Recruits(); // convert id para int32 int int_RecruitId = Convert.ToInt32(recruitId); // validar o ID e recuperar o recruta da base de dados if (!string.IsNullOrEmpty(recruitId)) { recruit = db.Recruits.Where(x => x.Id.Equals(int_RecruitId)).FirstOrDefault(); } else { return(new XElement("")); } // criar o elemento xml para devolver o recruta XElement xElem = new XElement("recruit", new XElement("id", recruit.Id), new XElement("name", recruit.Name), new XElement("email", recruit.Email), new XElement("platoonid", recruit.PlatoonId) ); return(xElem); }
/// <summary> /// método para remover um recruta da base de dados /// TODO: lidar com possíveis dependências antes de apagar /// </summary> /// <param name="id"></param> /// <returns></returns> public XElement DeleteRecruit(string id) { XElement xElem = new XElement("isDeleted"); if (!string.IsNullOrEmpty(id)) { int recruitId = Convert.ToInt32(id); Recruits recruit = db.Recruits.Where(x => x.Id.Equals(recruitId)).FirstOrDefault(); db.Recruits.Remove(recruit); db.SaveChanges(); xElem.Value = "true"; return(xElem); } xElem.Value = "false"; return(xElem); }
/// <summary> /// método para inserir um recruta na base de dados /// </summary> /// <param name="name"></param> /// <param name="email"></param> /// <param name="platoonId"></param> /// <returns></returns> public XElement InsertRecruit(string name, string email, string platoonId) { XElement xElem = new XElement("isInserted"); // validar parâmetros e dar entrada do registo if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(email) && !string.IsNullOrEmpty(platoonId)) { Recruits recruit = new Recruits { Name = name, Email = email, PlatoonId = Convert.ToInt32(platoonId) }; db.Recruits.Add(recruit); db.SaveChanges(); xElem.Value = "true"; return(xElem); } xElem.Value = "false"; return(xElem); }
/// <summary> /// método para actualizar o recruta /// </summary> /// <param name="id"></param> /// <param name="name"></param> /// <param name="email"></param> /// <param name="platoonId"></param> /// <returns></returns> public XElement UpdateRecruit(string id, string name, string email, string platoonId) { XElement xElem = new XElement("isUpdated"); // validar os parâmetros e actualizar o registo if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(email) && !string.IsNullOrEmpty(platoonId)) { int recruitId = Convert.ToInt32(id); Recruits recruit = db.Recruits.Where(x => x.Id.Equals(recruitId)).FirstOrDefault(); recruit.Name = name; recruit.Email = email; recruit.PlatoonId = Convert.ToInt32(platoonId); db.Entry(recruit).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); xElem.Value = "true"; return(xElem); } xElem.Value = "false"; return(xElem); }
/// <summary> /// método para inserir um recruta na base de dados /// </summary> /// <param name="name"></param> /// <param name="email"></param> /// <param name="platoonId"></param> /// <returns></returns> public XElement InsertRecruit(string name, string email, string platoonId) { XElement xElem = new XElement("isInserted"); // validar parâmetros e dar entrada do registo if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(email) && !string.IsNullOrEmpty(platoonId)) { Recruits recruit = new Recruits { Name = name, Email = email, PlatoonId = Convert.ToInt32(platoonId) }; db.Recruits.Add(recruit); db.SaveChanges(); xElem.Value = "true"; return xElem; } xElem.Value = "false"; return xElem; }
public XElement GetRecruitById(string recruitId) { // criar um recruta que vai ser recuperado Recruits recruit = new Recruits(); // convert id para int32 int int_RecruitId = Convert.ToInt32(recruitId); // validar o ID e recuperar o recruta da base de dados if (!string.IsNullOrEmpty(recruitId)) { recruit = db.Recruits.Where(x => x.Id.Equals(int_RecruitId)).FirstOrDefault(); } else { return new XElement(""); } // criar o elemento xml para devolver o recruta XElement xElem = new XElement("recruit", new XElement("id", recruit.Id), new XElement("name", recruit.Name), new XElement("email", recruit.Email), new XElement("platoonid", recruit.PlatoonId) ); return xElem; }