// Assign price class to items //public dynamic PostsalesdetailsPrice(JArray pPostedData) //{ // var fitem = ""; // var fclass = ""; // foreach (JObject item in pPostedData.Children<JObject>()) // { // fitem = item["fitem"].ToString(); // fclass = item["fpriceclass"].ToString(); // item["fprice"] = _db.itemsalesprices.Where(t => t.fitem == fitem && t.fclass == fclass).FirstOrDefault().fsaleprice; // } // return new // { // plist = pPostedData // }; //} // Save customer favorites public dynamic PostFavorites(JArray pPostedData) { bool mCommit = true; var customeritemsinsert = new List<customeritem>(); customeritem ctrx; // Update using transaction using (TransactionScope transaction = new TransactionScope()) { try { foreach (JObject mrow in pPostedData) { string fitem = (string)mrow["fitem"]; string fcid = (string)mrow["fcid"]; // Only new items if (_db.customeritems.Where(t => t.fcid == fcid && t.fitem == fitem).Count() == 0) // See if exists { ctrx = new customeritem(); ctrx.fcid = fcid; ctrx.fitem = fitem; ctrx.flockprice = 0; ctrx.flastprice = 0; customeritemsinsert.Add(ctrx); } } ofDBSave(customeritemsinsert, _db.customeritems, "I"); // Insert _db.SaveChanges(); } catch (InvalidCastException e) { mCommit = false; } if (mCommit) transaction.Complete(); } return new { success = mCommit }; }
// Save customer favorites public dynamic PostFavorites(JArray pPostedData) { bool mCommit = true; var customeritemsinsert = new List<customeritem>(); customeritem ctrx; // Update using transaction using (TransactionScope transaction = new TransactionScope()) { try { foreach (JObject mrow in pPostedData) { string fitem = (string)mrow["fitem"]; int fcid = (int)mrow["fcid"]; // Find if inventory item var mim = (from iu in _db.itemunits.Where(t => t.fitem == fitem) from im in _db.itemmasters.Where(t => t.fimid == iu.fimid) select new { im.ftype }).ToList().FirstOrDefault(); // Only for 'I'nvnetory Type if (mim.ftype == "I") { // Only new items if (_db.customeritems.Where(t => t.fcid == fcid && t.fitem == fitem).Count() == 0) // See if exists { ctrx = new customeritem(); ctrx.fcid = fcid; ctrx.fitem = fitem; customeritemsinsert.Add(ctrx); } } } ofDBSave(customeritemsinsert, _db.customeritems, "I"); // Insert _db.SaveChanges(); } catch (InvalidCastException e) { mCommit = false; } if (mCommit) transaction.Complete(); } return new { success = mCommit }; }