public char updateFacilitie(Facilitie fas, string conn) { SqlConnection connection = new SqlConnection(conn); string sqlStoredProcedure = "SP_Update_Facilitie"; SqlCommand sqlCommand = new SqlCommand(sqlStoredProcedure, connection); sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.Parameters.Add("@ID", SqlDbType.Int).Value = fas.IdFacilitie; sqlCommand.Parameters.Add("@Description", SqlDbType.Char, size: 1000).Value = fas.Description; sqlCommand.Parameters.Add("@Name", SqlDbType.Char, size: 100).Value = fas.Name; SqlParameter resultUpdate = new SqlParameter("@R", " "); resultUpdate.Direction = ParameterDirection.Output; resultUpdate.SqlDbType = SqlDbType.Char; resultUpdate.Size = 1; sqlCommand.Parameters.Add(resultUpdate); sqlCommand.Connection.Open(); sqlCommand.ExecuteNonQuery(); string result = sqlCommand.Parameters["@R"].Value.ToString(); return(result[0]); }
public Facilitie getFacilitie(Facilitie fas, string conn) { SqlConnection connection = new SqlConnection(conn); string sqlStoredProcedure = "SP_Retrieve_Facilitie"; SqlCommand sqlCommand = new SqlCommand(sqlStoredProcedure, connection); sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.Parameters.Add("@Facilitie", SqlDbType.Int).Value = fas.IdFacilitie; sqlCommand.Connection.Open(); sqlCommand.ExecuteNonQuery(); SqlDataReader reader = sqlCommand.ExecuteReader(); if (reader.HasRows) { reader.Read(); fas.Name = reader.GetString(0); fas.Description = reader.GetString(1); } else { fas.IdFacilitie = -1; fas.Name = "No facilitie found"; fas.Description = "No facilitie description"; } sqlCommand.Connection.Close(); return(fas); }
public List <Facilitie> getFacilitieCombo(string conn) { SqlConnection connection = new SqlConnection(conn); string sqlStoredProcedure = "SP_Retrieve_Facilitie_Combo_Box"; SqlCommand sqlCommand = new SqlCommand(sqlStoredProcedure, connection); sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.Connection.Open(); sqlCommand.ExecuteNonQuery(); SqlDataReader reader = sqlCommand.ExecuteReader(); List <Facilitie> roomList = new List <Facilitie>(); if (reader.HasRows) { while (reader.Read()) { Facilitie facilitie = new Facilitie(); facilitie.IdFacilitie = reader.GetInt32(0); facilitie.Name = reader.GetString(1); roomList.Add(facilitie); } } sqlCommand.Connection.Close(); return(roomList); }
public ActionResult RetrieveFacilitie(string id) { Facilitie fas = new Facilitie(); fas.IdFacilitie = Int16.Parse(id); fas = this.data.getFacilitie(fas, this.conn); return(Json(fas)); }
public ActionResult updateFacilitie(string id, string nam, string desc) { Facilitie fas = new Facilitie(); fas.IdFacilitie = Int16.Parse(id); fas.Name = nam; fas.Description = desc; return(Json(this.data.updateFacilitie(fas, this.conn))); }
public int createFacilite(string conn, Facilitie facilitie) { SqlConnection connection = new SqlConnection(conn); string sqlStoredProcedure = "SP_Create_Facilitie"; SqlCommand sqlCommand = new SqlCommand(sqlStoredProcedure, connection); sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.Parameters.Add(new SqlParameter("@Name", facilitie.Name)); sqlCommand.Parameters.Add(new SqlParameter("@Description_", facilitie.Description)); SqlParameter resultCreate = new SqlParameter("@R", ""); resultCreate.Direction = ParameterDirection.Output; sqlCommand.Parameters.Add(resultCreate); SqlParameter idNewFacilitie = new SqlParameter("@Facilitie", 0); idNewFacilitie.Direction = ParameterDirection.Output; sqlCommand.Parameters.Add(idNewFacilitie); sqlCommand.Connection.Open(); sqlCommand.ExecuteNonQuery(); string result = sqlCommand.Parameters["@R"].Value.ToString(); int idNewFacilitie2 = Int32.Parse(sqlCommand.Parameters["@Facilitie"].Value.ToString()); if (result.Equals("y")) { return(idNewFacilitie2); } else { return(-1); } }
public List <Facilitie> getAllFacilities(string conn) { SqlConnection connection = new SqlConnection(conn); string sqlStoredProcedure = "SP_Retrieve_Facilitie_All"; SqlCommand cmdFacilitie = new SqlCommand(sqlStoredProcedure, connection); cmdFacilitie.CommandType = CommandType.StoredProcedure; cmdFacilitie.Connection.Open(); cmdFacilitie.ExecuteNonQuery(); SqlDataReader reader = cmdFacilitie.ExecuteReader(); List <Facilitie> facilities = new List <Facilitie>(); if (reader.HasRows) { while (reader.Read()) { Facilitie facilitie = new Facilitie(); facilitie.idFacilitie = reader.GetString(0); facilitie.name = reader.GetString(1); facilitie.description_ = reader.GetString(2); ImageContext context = new ImageContext(); facilitie.image = context.getImageByType(connUCR, Int32.Parse(facilitie.idFacilitie), 'F'); facilities.Add(facilitie); } } cmdFacilitie.Connection.Close(); return(facilities); }
public ActionResult CreateFacilitie() { //Estos If se necesitan en todos los controllers del modulo administrativo //Este pregunta si existe una cookie con el id del admin, esta se crea SI este inicia sesion con naturalidad. //Tambien pregunta si el adminId no es nulo, esto para evitar un caso raro donde la galleta exista pero no el id. if (Request.Cookies["Admin"] != null && Request.Cookies["Admin"]["adminId"] != null) { int access = int.Parse(Request.Cookies["Admin"]["adminId"]); //Si el id en la galleta es mayor a 0 es un administrador normal, pero si es menor a 0 es un // codigo que se asigna cuando no pudo autenticar if (access > 0) { string name = Request.Form["txtNameFacilitie"].ToString(); string description = Request.Form["txtDescription"].ToString(); Facilitie facilitie = new Facilitie(); facilitie.Name = name; facilitie.Description = description; if (name.Length > 1 && description.Length > 1) { int result = facilitieC.createFacilite(conn, facilitie); if (result != -1) { HttpCookie cookie = new HttpCookie("idFacilitie"); cookie["idNewFacilitie"] = result.ToString(); cookie.Expires = DateTime.Now.AddSeconds(10); Response.Cookies.Add(cookie); return(RedirectToAction("Index")); } else { HttpCookie cookie = new HttpCookie("error"); cookie["errorCreate"] = "error"; cookie.Expires = DateTime.Now.AddSeconds(4); Response.Cookies.Add(cookie); return(RedirectToAction("Index")); } } else { HttpCookie cookie = new HttpCookie("errorData"); cookie["errorData"] = "error"; cookie.Expires = DateTime.Now.AddSeconds(4); Response.Cookies.Add(cookie); return(RedirectToAction("Index")); } } else { //Este else retorna al index de logueo con un -2, el -2 le dice al index que este usuario intentó // entrar de forma no autorizada al modulo y se le presentará un mensaje sobre eso. Request.Cookies["Admin"]["adminId"] = "-2"; return(RedirectToAction("Index", "Login")); //Cambio de redirect, este es mejor } } else { //Este else es en caso de que la cookie no exista, se crea y se le da el codigo -2 para devolverlo a // loguearse al index. HttpCookie galleta = new HttpCookie("Admin"); galleta["adminId"] = "-2"; galleta.Expires = DateTime.Now.AddMinutes(1); Response.Cookies.Add(galleta); return(RedirectToAction("Index", "Login")); //Cambio de redirect, este es mejor } }