public static bool insertFormUser(TaskFormUserDTO pFormUser) { using (SqlConnection connection = new SqlConnection(WebConfigurationManager.ConnectionStrings["connectionRRHHDatabase"].ConnectionString)) { SqlCommand command = new SqlCommand("usp_insert_formUser", connection); command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.Add("@taskForm_id", SqlDbType.Int); command.Parameters["@taskForm_id"].Value = pFormUser.taskForm_id; command.Parameters.Add("@user_id", SqlDbType.Int); command.Parameters["@user_id"].Value = pFormUser.user_id; command.Parameters.Add("@userLog", SqlDbType.Int); command.Parameters["@userLog"].Value = pFormUser.userLog; command.Connection.Open(); string result = command.ExecuteScalar().ToString(); if (result != "0") { return(true); } }; return(false); }
public static bool updateFormUser(TaskFormUserDTO pFormUser) { using (SqlConnection connection = new SqlConnection(WebConfigurationManager.ConnectionStrings["connectionRRHHDatabase"].ConnectionString)) { SqlCommand command = new SqlCommand("usp_update_form", connection); command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.Add("@taskForm_id", SqlDbType.BigInt); command.Parameters["@taskForm_id"].Value = pFormUser.taskForm_id; command.Parameters.Add("@user_id", SqlDbType.Int); command.Parameters["@user_id"].Value = pFormUser.user_id; command.Parameters.Add("@isAnswered", SqlDbType.Bit); command.Parameters["@isAnswered"].Value = pFormUser.isAnswered; command.Parameters.Add("@answered_date", SqlDbType.DateTime); command.Parameters["@answered_date"].Value = pFormUser.answered_date; command.Parameters.Add("@userLog", SqlDbType.Int); command.Parameters["@userLog"].Value = pFormUser.userLog; command.Connection.Open(); string result = command.ExecuteNonQuery().ToString(); if (result != "0") { return(true); } }; return(false); }
public static List <TaskFormUserDTO> getFormUsers(string taskForm_id) { List <TaskFormUserDTO> formUsers = new List <TaskFormUserDTO>(); using (SqlConnection connection = new SqlConnection(WebConfigurationManager.ConnectionStrings["connectionRRHHDatabase"].ConnectionString)) { SqlCommand command = new SqlCommand("usp_get_formUsers", connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@taskForm_id", SqlDbType.Int); command.Parameters["@taskForm_id"].Value = taskForm_id; command.Connection.Open(); SqlDataReader rdr = command.ExecuteReader(); while (rdr.Read()) { TaskFormUserDTO formUSer = new TaskFormUserDTO(); formUSer.user_id = rdr["user_id"].ToString(); formUSer.taskForm_id = rdr["taskForm_id"].ToString(); formUSer.isAnswered = rdr["isAnswered"].ToString(); formUSer.name = rdr["name"].ToString(); formUSer.sLastName = rdr["sLastName"].ToString(); formUSer.fLastName = rdr["fLastName"].ToString(); formUSer.userName = rdr["userName"].ToString(); formUSer.email = rdr["email"].ToString(); byte[] photo = (byte[])rdr["photoData"]; formUSer.photoData = Convert.ToBase64String(photo); formUsers.Add(formUSer); } }; return(formUsers); }
public IHttpActionResult putFormUser(TaskFormUserDTO pFormUser) { if (!TaskFormData.updateFormUser(pFormUser)) { return(BadRequest()); } return(Ok()); }
public async Task <bool> deleteFormUser(TaskFormUserDTO formUserDTO) { using (var client = new HttpClient()) { client.BaseAddress = new Uri(_BaseAddress); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", getToken()); HttpResponseMessage response = client.DeleteAsync("api/tasks/formUsers/?taskForm_id=" + formUserDTO.taskForm_id + "&user_id=" + formUserDTO.user_id + "&userLog=" + formUserDTO.userLog).Result; return(response.IsSuccessStatusCode); } }
public async Task <bool> putFormUSer(TaskFormUserDTO pFormUser) { using (var client = new HttpClient()) { client.BaseAddress = new Uri(_BaseAddress); var userJson = new JavaScriptSerializer().Serialize(pFormUser); HttpContent contentPost = new StringContent(userJson, Encoding.UTF8, "application/json"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", getToken()); HttpResponseMessage response = client.PutAsync("api/tasks/formUsers", contentPost).Result; return(response.IsSuccessStatusCode); } }
public ActionResult _DeleteFormUser(string taskForm_id, string user_id) { TaskFormUserDTO formUser = new TaskFormUserDTO(); formUser.taskForm_id = taskForm_id; formUser.user_id = user_id; formUser.userLog = Request.Cookies["user_id"].Value; if (taskProvider.deleteFormUser(formUser).Result) { return(new HttpStatusCodeResult(200)); } return(new HttpStatusCodeResult(404, "Can't find that")); }
public IHttpActionResult deleteFormUser(string userLog, string user_id, string taskForm_id) { TaskFormUserDTO formUser = new TaskFormUserDTO(); formUser.userLog = userLog; formUser.user_id = user_id; formUser.taskForm_id = taskForm_id; if (!TaskFormData.deleteFormUser(formUser)) { return(BadRequest()); } return(Ok()); }
public ActionResult _AddFormUser(string taskForm_id, List <string> selected_userForm_id) { if (ModelState.IsValid) { List <TaskFormUserDTO> actualUsers = taskProvider.getFormUsers(taskForm_id).Result; if (actualUsers.Count < 1) { List <TaskFormUserDTO> users = new List <TaskFormUserDTO>(); if (selected_userForm_id.Count > 1) { return(new HttpStatusCodeResult(404, "Solamente se permite agregar un usuario")); } else { foreach (var responsable_id in selected_userForm_id) { TaskFormUserDTO formUser = new TaskFormUserDTO(); formUser.user_id = responsable_id; formUser.taskForm_id = taskForm_id; formUser.userLog = Request.Cookies["user_id"].Value; users.Add(formUser); } List <TaskFormUserDTO> addedUsers = taskProvider.postFormUsers(users).Result; int addedCount = addedUsers.Count; int errorCount = users.Count - addedCount; TaskFormDTO taskForm = taskProvider.getTaskForm(taskForm_id).Result; TaskDTO taskDTO = taskProvider.getTask(taskForm.id_task).Result; var result = new { usersAdded = addedCount, usersError = errorCount, viewHtml = PartialView("/Views/Tasks/_Tasks/_TaskDetails/_TaskFormUsersList.cshtml", new Model.AddFormUsersModel(taskDTO, taskForm)).RenderToString() }; return(Json(result)); } } else { return(new HttpStatusCodeResult(404, "Solamente se permite agregar un usuario")); } } return(new HttpStatusCodeResult(404, "Error, no se agregó ningun usuario")); }