public int Add(ItemsAddRequest model) { using (SqlConnection conn = new SqlConnection(ConnectionString)) { conn.Open(); SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = "dbo.Items_Insert"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Color", model.Color); cmd.Parameters.AddWithValue("@SizeId", model.SizeId); cmd.Parameters.AddWithValue("@ReviewStarsId", model.ReviewStarsId); cmd.Parameters.AddWithValue("@ItemName", model.ItemName); cmd.Parameters.AddWithValue("@ItemDetails", model.ItemDetails); cmd.Parameters.AddWithValue("@ItemTypeId", model.ItemTypeId); cmd.Parameters.AddWithValue("@ImageUrl", model.ImageUrl); cmd.Parameters.AddWithValue("@Gender", model.Gender); cmd.Parameters.AddWithValue("@Price", model.Price); cmd.Parameters.AddWithValue("@ItemBrand", model.ItemBrand); SqlParameter idParam = cmd.Parameters.Add("@Id", SqlDbType.Int); idParam.Direction = ParameterDirection.Output; cmd.ExecuteNonQuery(); return((int)idParam.Value); } }
public async Task <ActionResult <ItemsResult> > AddItems([FromBody] ItemsAddRequest request) { if (!await _authManager.HasSitePermissionsAsync(request.SiteId, Types.SitePermissions.SettingsStyleRelatedField)) { return(Unauthorized()); } foreach (var item in request.Items) { var itemInfo = new RelatedFieldItem { Id = 0, SiteId = request.SiteId, RelatedFieldId = request.RelatedFieldId, Label = item.Key, Value = item.Value, ParentId = request.ParentId }; await _relatedFieldItemRepository.InsertAsync(itemInfo); } await _authManager.AddAdminLogAsync("批量添加联动字段项"); var tree = await _relatedFieldItemRepository.GetCascadesAsync(request.SiteId, request.RelatedFieldId, 0); return(new ItemsResult { Tree = tree }); }
public ActionResult <int> Add(ItemsAddRequest model) { try { ItemsService service = new ItemsService(); int id = service.Add(model); return(Ok(id)); } catch (Exception ex) { return(StatusCode(500, ex.Message.ToString())); } }