public string OperatorGoodListSave(string list_name, string list_id) { var operatorGoodListResponse = new OperatorGoodListResponse(); try { var data = new OperatorGoodListCreateRequest { Operator = JwtProps.GetOperator(), GoodList = list_id.Split(',').Select(n => Convert.ToInt32(n)).ToList(), GoodListName = list_name }; HttpResponseMessage responseMessage = HttpClientService.PostAsync("api/values/SaveOperatorGoodList", data).Result; if (responseMessage.IsSuccessStatusCode) { operatorGoodListResponse = responseMessage.Content.ReadAsAsync <OperatorGoodListResponse>().Result; if (operatorGoodListResponse.ErrorCode == 0 && string.IsNullOrEmpty(operatorGoodListResponse.Message)) { return(JsonConvert.SerializeObject(new { success = true })); } return(JsonConvert.SerializeObject(operatorGoodListResponse)); } operatorGoodListResponse.ErrorCode = 10; operatorGoodListResponse.Message = "Ошибка получения данных"; } catch (Exception ex) { operatorGoodListResponse.ErrorCode = 2; operatorGoodListResponse.Message = ex.Message; } return(JsonConvert.SerializeObject(operatorGoodListResponse)); }
/// <summary> /// Сохраняет список магазинов в БД /// </summary> /// <param name="request"></param> /// <returns></returns> public OperatorGoodListResponse SaveOperatorGoodList(OperatorGoodListCreateRequest request) { var returnValue = new OperatorGoodListResponse(); _cnn.Open(); SqlCommand cmd = _cnn.CreateCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "OperatorCreateGoodList"; cmd.Parameters.AddWithValue("@caption", request.GoodListName); cmd.Parameters.AddWithValue("@operator", request.Operator); cmd.Parameters.Add("@errormessage", SqlDbType.NVarChar, 100); cmd.Parameters["@errormessage"].Direction = ParameterDirection.Output; cmd.Parameters.Add("@result", SqlDbType.Int); cmd.Parameters["@result"].Direction = ParameterDirection.ReturnValue; if (request.GoodList != null && request.GoodList.Count > 0) { using (var table = new DataTable()) { table.Columns.Add("id", typeof(int)); foreach (var item in request.GoodList) { DataRow row = table.NewRow(); row["id"] = item; table.Rows.Add(row); } var items = new SqlParameter("@items", SqlDbType.Structured) { TypeName = "dbo.IdItem", Value = table }; cmd.Parameters.Add(items); } } try { cmd.ExecuteNonQuery(); returnValue.ErrorCode = Convert.ToInt32(cmd.Parameters["@result"].Value); returnValue.Message = Convert.ToString(cmd.Parameters["@errormessage"].Value); } catch (Exception e) { returnValue.ErrorCode = 3; returnValue.Message = e.Message; } finally { _cnn.Close(); } return(returnValue); }
public OperatorGoodListResponse OperatorGoodListSave(OperatorGoodListCreateRequest request) { return(_operatorGoodService.SaveOperatorGoodList(request)); }