public HttpResponseMessage DeleteBasItemCategoryRow(dynamic obj) { int ItemType = (int)obj.ItemType; if (ItemType == 2) { t_item_group itemGroup = new t_item_group() { ItemGroupID = obj.ItemGroupID }; var result = new DBHelper <t_item_group>().Remove(itemGroup); return(Json(true, result == 1 ? "删除成功!" : "删除失败")); } else { t_item_category itemCategory = new t_item_category() { ItemCategoryID = obj.ItemCategoryID }; var result = new DBHelper <t_item_category>().Remove(itemCategory); return(Json(true, result == 1 ? "删除成功!" : "删除失败")); } }
public HttpResponseMessage SaveBasItemGroupForm(t_item_group obj) { using (TransactionScope transaction = new TransactionScope()) { DBHelper <t_item_group> dbhelp = new DBHelper <t_item_group>(); DateTime dt = DateTime.Now; //事务 var result = 0; var ItemGroupID = db.t_item_group.Where(w => w.Code == obj.Code && w.CorpID == userInfo.CorpID); try { if (obj.ItemGroupID == 0) { string Code = ""; result = AutoIncrement.AutoIncrementResult("ItemGroup", out Code); obj.CreateTime = dt; obj.CreateUser = (int)userInfo.UserID; obj.UPdateTime = dt; obj.UpdateUser = (int)userInfo.UserID; obj.CorpID = userInfo.CorpID; obj.Code = Code; if (ItemGroupID.ToList().Count() > 0) { throw new Exception("编码重复!"); } } else { obj.UPdateTime = dt; obj.UpdateUser = (int)userInfo.UserID; if (ItemGroupID.ToList().Count() > 1) { throw new Exception("编码重复!"); } } result = result + (obj.ItemGroupID == 0 ? dbhelp.Add(obj) : dbhelp.Update(obj)); //提交事务 transaction.Complete(); return(Json(true, "保存成功!")); } catch (Exception ex) { return(Json(false, "保存失败!" + ex.Message)); } } }