public JsonResult InsertAndUpdate(ValidationVM validationsVM, int id) { try { var json = JsonConvert.SerializeObject(validationsVM); var buffer = System.Text.Encoding.UTF8.GetBytes(json); var byteContent = new ByteArrayContent(buffer); byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); if (validationsVM.Id == 0) { var result = client.PostAsync("validations", byteContent).Result; return(Json(result)); } else if (validationsVM.Id == id) { var result = client.PutAsync("validations/" + id, byteContent).Result; return(Json(result)); } return(Json(404)); } catch (Exception ex) { throw ex; } }
public IActionResult CreateValidation([FromBody] ValidationVM Validation) { var create = _ValidationRepository.Create(Validation); if (create > 0) { return(Ok(create)); } return(BadRequest("Create Validation is failed")); }
public IActionResult EditValidation(int Id, ValidationVM Validation) { var edit = _ValidationRepository.Update(Validation, Id); if (edit > 0) { return(Ok(edit)); } return(BadRequest("Edit Validation is failed")); }
public int Create(ValidationVM validation) { using (SqlConnection connection = new SqlConnection(_configuration.GetConnectionString("myConn"))) { var procName = "SP_InsertValidation"; parameters.Add("Action", validation.Action); parameters.Add("supervisor", validation.supervisorId); parameters.Add("form", validation.formId); var insertValidation = connection.Execute(procName, parameters, commandType: CommandType.StoredProcedure); return(insertValidation); } }
public JsonResult GetById(int Id) { ValidationVM validationsVM = null; var resTask = client.GetAsync("validations/" + Id); resTask.Wait(); var result = resTask.Result; if (result.IsSuccessStatusCode) { var json = JsonConvert.DeserializeObject(result.Content.ReadAsStringAsync().Result).ToString(); validationsVM = JsonConvert.DeserializeObject <ValidationVM>(json); } else { ModelState.AddModelError(string.Empty, "Server Error."); } return(Json(validationsVM)); }