public IActionResult Edit(int goodsId, string goodsName, string goodsDescription) { var goods = new GoodsBase { GoodsId = goodsId, GoodsName = goodsName, GoodsDescription = goodsDescription }; _repository.UpdateGoods(goods); return(RedirectToAction(nameof(Details), new { Id = goodsId })); }
public IActionResult Create(string goodsName, string goodsDescription) { GoodsBase model = new GoodsBase() { GoodsName = goodsName, GoodsDescription = goodsDescription }; _repository.AddGoods(model); //return Redirect("/Goods"); // 리스트 페이지로 이동 return(RedirectToAction(nameof(Index))); }
[Consumes("application/json")] // application/xml public IActionResult Post([FromBody] GoodsBase model) // Deserialize, 생성 전용 DTO 클래스 사용 가능 { // 예외 처리 방법 if (model == null) { return(BadRequest()); // Status: 400 Bad Request } try { // 예외 처리 if (model.GoodsName == null || model.GoodsName.Length < 1) { ModelState.AddModelError("GoodsName", "제품명을 입력해야 합니다."); } // 모델 유효성 검사 if (!ModelState.IsValid) { return(BadRequest(ModelState)); // 400 에러 출력 } var m = _repository.AddGoods(model); // 저장 //return Ok(m); // 200 OK //return CreatedAtRoute("GetGoodsById", new { id = m.GoodsId }, m); // Status: 201 Created if (DateTime.Now.Second % 2 == 0) //[!] 2가지 방식 중 원하는 방식 사용 { //return CreatedAtAction("GetGoodsById", new { id = m.GoodsId }, m); return(CreatedAtRoute("GetGoodsById", new { id = m.GoodsId }, m)); // Status: 201 Created } else { var uri = Url.Link("GetGoodsById", new { id = m.GoodsId }); return(Created(uri, m)); // 201 Created } } catch (Exception ex) { return(BadRequest($"에러가 발생했습니다. {ex.Message}")); } }
public Dictionary <string, string> GetChild2ParentGoodsInfo(out Dictionary <string, GoodsBase> ID2goods_dict) { Dictionary <string, string> child2parent = new Dictionary <string, string>(); ID2goods_dict = new Dictionary <string, GoodsBase>(); DataTable dt = ExecuteDataTable(@"select goods_id,name,ean,goods.code,category,selling_price,selling_vip_price,purchasing_price,units,product_parent_id,product_num,sell_status,goods_category.category_name from goods left join goods_category on goods.category = goods_category.id order by goods.code"); if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { GoodsBase goods = new GoodsBase(); goods.GoodsID = dt.Rows[i]["goods_id"].ToString(); goods.GoodsName = dt.Rows[i]["name"].ToString(); goods.Ean = dt.Rows[i]["ean"].ToString(); goods.Code = dt.Rows[i]["code"].ToString(); goods.CategoryID = dt.Rows[i]["category"].ToString(); goods.CategoryName = dt.Rows[i]["category_name"].ToString(); goods.ParentID = dt.Rows[i]["product_parent_id"].ToString(); goods.Units = dt.Rows[i]["units"].ToString(); goods.SellPrice = Convert.ToDecimal(dt.Rows[i]["selling_price"]); goods.PurchasingPrice = Convert.ToDecimal(dt.Rows[i]["purchasing_price"]); goods.VIPPrice = Convert.ToDecimal(dt.Rows[i]["selling_vip_price"]); goods.SplitNum = Convert.ToDecimal(dt.Rows[i]["product_num"]); goods.SellState = (int)dt.Rows[i]["sell_status"]; ID2goods_dict.Add(goods.GoodsID, goods); if (!string.IsNullOrEmpty(goods.ParentID)) { child2parent.Add(goods.GoodsID, goods.ParentID); } } } return(child2parent); }
[HttpPut("{id:int}")] // HttpPatch == 부분 업데이트 public IActionResult Put(int id, [FromBody] GoodsBase model) { if (model == null) { return(BadRequest()); } try { var oldModel = _repository.GetGoodsById(id); if (oldModel == null) { return(NotFound($"{id}번 데이터가 없습니다.")); } model.GoodsId = id; _repository.UpdateGoods(model); // 수정 return(NoContent()); // 204: 이미 넘어온 정보에 모든 값을 가지고 있기에... } catch (Exception ex) { return(BadRequest($"데이터가 업데이트되지 않았습니다. {ex.Message}")); } }
//public ItemInfoUI() //{ // GameObject info = Instantiate(infoPrefab); //} public void Ini() { EventTriggerListener.Get(btn_close).onClick = CloseItemInfo; //基本属性 goodsUIBase = new GoodsBase(); goodsUIBase.nameText = InfoPlane.transform.Find("Title/Text").GetComponent <Text>(); goodsUIBase.goodsIMG = InfoPlane.transform.Find("IMG/Image").GetComponent <Image>(); goodsUIBase.MaterialtypeText = InfoPlane.transform.Find("TextInfo/MaterialType").GetComponent <Text>(); goodsUIBase.numText = InfoPlane.transform.Find("TextInfo/Num").GetComponent <Text>(); goodsUIBase.qualityText = InfoPlane.transform.Find("TextInfo/Quality").GetComponent <Text>(); goodsUIBase.priceText = InfoPlane.transform.Find("TextInfo/Price").GetComponent <Text>(); //物品效果 goodsUIBase.effect = ScrollPages.transform.Find("PageList/Page1/Effect/EffectName/Text").GetComponent <Text>(); //物品属性 goodsUIBase.propertys = new GameObject[4]; for (int i = 0; i < 4; i++) { goodsUIBase.propertys[i] = ScrollPages.transform.Find("PageList/Page1/Property/List").GetChild(i).gameObject; } //物品类型 goodsUIBase.typeText = ScrollPages.transform.Find("PageList/Page2/Type/TypeList/Text").GetComponent <Text>(); //物品描述 goodsUIBase.des = ScrollPages.transform.Find("PageList/Page2/Info/TextBox/Text").GetComponent <Text>(); //初始化 effect = new Materiral.Effect(); Propertys = new ArrayList(); //按钮效果 EventTriggerListener.Get(btn_close).onClick = CloseItemInfo; }
public void SetGoods(GoodsBase good) { this.m_Goods = good; }