public void createPostulant() { Postulant trueValue = new Postulant { Name = "Ejemplo", Lastname = "Ejemplo", Birthday = "1997-10-20", Dni = "40234567", Email = "*****@*****.**", PhoneHome = "43569789", PhoneMobile = "1134536789", GitHub = "MiGithub", LinkedIn = "MiLinkedIn", IdState = 1, Iteration = 1, Country = 1 }; Postulant toTest = fnc.createPostulant(baseForm); Assert.AreEqual(trueValue.Name, toTest.Name); Assert.AreEqual(trueValue.Lastname, toTest.Lastname); Assert.AreEqual(trueValue.Birthday, toTest.Birthday); Assert.AreEqual(trueValue.Dni, toTest.Dni); Assert.AreEqual(trueValue.Email, toTest.Email); Assert.AreEqual(trueValue.PhoneHome, toTest.PhoneHome); Assert.AreEqual(trueValue.PhoneMobile, toTest.PhoneMobile); Assert.AreEqual(trueValue.GitHub, toTest.GitHub); Assert.AreEqual(trueValue.LinkedIn, toTest.LinkedIn); Assert.AreEqual(trueValue.IdState, toTest.IdState); Assert.AreEqual(trueValue.Iteration, toTest.Iteration); Assert.AreEqual(trueValue.Country, toTest.Country); }
public ActionResult Post([FromBody] Form form) { if (this.ModelState.IsValid) { Postulant postulant = fnc.createPostulant(form); //Aca valida datos y guarda en db int IdPostulantDb = dbm.InsertPostulant(postulant); int IdStudyform = fnc.validateIdStudy(form); int IdStudiesStateform = fnc.validateIdStudyState(form); Studies studies = fnc.createStudies(form, IdPostulantDb, IdStudyform, IdStudiesStateform); dbm.InsertStudies(studies); var formString = JsonConvert.SerializeObject(form); var barray = Encoding.UTF8.GetBytes(formString); Attached attached = new Attached { Name = "InitForm.txt", Link = barray, IdTypeAttached = 1 }; dbm.InsertAttached(attached, IdPostulantDb); return(Ok()); } else { return(BadRequest()); } }
//PUT api/Management/Postulant/Modif public Postulant Update([FromBody] Postulant postulant) { if (postulant.Id != 0) { return(dbm.UpdatePostulant(postulant)); } else { return(postulant); } }
// INSERTA VALORES // public void Insert(Postulant postulant) { var sql = "insert into Postulant (Name, Age, IdCountry) values (@Name, @Age, @IdCountry)"; using (var conn = new SqlConnection(connStr)) { conn.Open(); conn.Execute(sql, new { @Name = postulant.Name, @Age = postulant.Age, @IdCountry = postulant.Country.IdCountry }); // Creo nuevo obj para relacionar los valores conn.Close(); } }
public ActionResult Post([FromBody] Postulant postulant) { if (ModelState.IsValid && (postulant.Name.IndexOf(" ") != -1)) // Si hay un espacio en el nombre (nombre + apellido) lo agrega { repository.Insert(postulant); } else { return(NotFound()); // Si no, devuelve 404. } return(Ok()); }
public ActionResult Put([FromBody] Postulant postulant) { if (ModelState.IsValid && (postulant.Name.IndexOf(" ") != -1)) { repository.Update(postulant); } else { return(NotFound()); } return(Ok()); }
// ACTUALIZA VALORES // public Postulant Update(Postulant postulant) { var sql = "update Postulant set Name = @Name, Age = @Age, IdCountry = @IdCountry where Id = @Id"; using (var conn = new SqlConnection(connStr)) { conn.Open(); conn.Execute(sql, new { @Name = postulant.Name, @Age = postulant.Age, @IdCountry = postulant.Country.IdCountry, @Id = postulant.Id }); conn.Close(); } return(this.GetPostulant(postulant.Id)); }
public Postulant UpdatePostulant(Postulant postulant) { var sql = "UPDATE Postulant SET Name = @Name, Lastname = @Lastname, Dni = @Dni, Email = @Email, Birthday = @Birthday, PhoneHome = @PhoneHome, PhoneMobile = @PhoneMobile, GitHub = @GitHub, LinkedIn = @LinkedIn WHERE Id = @Id"; using (var conn = new SqlConnection(connStr)) { conn.Open(); conn.Execute(sql, postulant); conn.Close(); } return(this.GetPostulant(postulant.Id)); }
public void Delete(int id) { _log.LogInformation($"Searching postulant {id}"); Postulant postulant = _postulantRepository.Query().Where(_ => _.Id == id).FirstOrDefault(); if (postulant == null) { throw new DeletePostulantNotFoundException(id); } _log.LogInformation($"Deleting postulant {id}"); _postulantRepository.Delete(postulant); _unitOfWork.Complete(); }
//POST api/Management/Address public ActionResult InsertAddress([FromBody] Addressget addressget) { Postulant post = dbm.GetPostulant(addressget.IdPostulant); if (this.ModelState.IsValid && post.IdAddress == 0) { dbm.InsertAddress(addressget); return(Ok()); } else { return(BadRequest()); } }
private string connStr = @"Server=(localdb)\MSSQLLocalDB;Database=exercise;Integrated Security=true"; // conección a DB public Postulant GetPostulant(int id) { var sql = "select * from Postulant u inner join Country c on c.IdCountry = u.IdCountry where Id = @Id"; // creo variable para no tener que tipear la query using (var conn = new SqlConnection(connStr)) { conn.Open(); Postulant postulant = conn .Query <Postulant, Country, Postulant>(sql, param: new { Id = id }, map: GetCountry, splitOn: "IdCountry") // Mapea relaciones entre Sql .FirstOrDefault(); conn.Close(); return(postulant); } }
//POSTULANT public int InsertPostulant(Postulant postulant) { var sql = "INSERT INTO Postulant (Name, Lastname, Dni, Email, Birthday, PhoneHome, PhoneMobile, Github, Linkedin, IdState, Iteration, Country) VALUES (@Name, @Lastname, @Dni, @Email, @Birthday, @PhoneHome, @PhoneMobile, @Github, @Linkedin, @IdState, @Iteration, @Country)"; var sql2 = "SELECT * FROM Postulant WHERE Dni = @Dni"; int Id = 0; using (var conn = new SqlConnection(connStr)) { conn.Open(); conn.Execute(sql, postulant); string dni = postulant.Dni; Id = (int)conn.Query <Postulant>(sql2, param: (object)new { @Dni = dni }).FirstOrDefault().Id; conn.Close(); } return(Id); }
//CREATE public Postulant createPostulant(Form form) { Postulant postulant = new Postulant { Name = form.Name, Lastname = form.Lastname, Dni = form.Dni, Birthday = form.Birth, Email = form.Email, PhoneHome = form.PhoneHome, PhoneMobile = form.PhoneMobile, GitHub = form.GitHub, LinkedIn = form.LinkedIn, IdState = 1, Iteration = 1, Country = 1 }; return(postulant); }
private Postulant GetCountry(Postulant postulant, Country country) { postulant.Country = country; return(postulant); }