public iwn_products CreateProduct(GoodsGood[] gd, out string msg) { msg = ""; iwn_products res = new iwn_products(); try { foreach (var good in gd) { res = new iwn_products(); res.guid = Guid.NewGuid(); res.name = good.Name; res.price = good.Value; res.articul = good.Articul; res.currency = good.Currency; var producer = _db.GetProducers().FirstOrDefault(x => x.code == good.Producer.Code); if (producer == null) { iwn_producers newProducer = new iwn_producers(); newProducer.name = good.Producer.Name; newProducer.code = good.Producer.Code; int i = _db.SaveProducer(newProducer); res.producerID = i; } else { res.producerID = producer.id; } var type = _db.GetProductTypes().FirstOrDefault(x => x.code == good.GoodType.Code); if (type == null) { iwn_productType newType = new iwn_productType(); newType.name = good.Producer.Name; newType.code = good.Producer.Code; int i = _db.SaveProductType(newType); res.productTypeID = i; } else { res.productTypeID = type.id; } _db.SaveProduct(res); } } catch (Exception e) { _debug(e, new { }, "Ошибка возникла при создании элемента"); res = null; } return(res); }
public iwn_products CreateProduct(Dictionary <string, string> parameters, out string msg) { msg = ""; iwn_products res; try { res = new iwn_products(); res.guid = Guid.NewGuid(); foreach (var key in parameters.Keys) { switch (key) { case "articul": res.articul = parameters[key]; break; case "price": res.price = RDL.Convert.StrToDecimal(parameters[key], 0); break; case "name": res.name = parameters[key]; break; case "currency": res.currency = parameters[key]; break; case "producerID": res.producerID = RDL.Convert.StrToInt(parameters[key], 1); break; case "productTypeID": res.productTypeID = RDL.Convert.StrToInt(parameters[key], 1); break; } } _db.SaveProduct(res); } catch (Exception e) { _debug(e, new { }, "Ошибка возникла при создании элемента"); res = null; } return(res); }