/// <summary> /// Saves the stored update of a unit into the database, /// and sends a cache message of the operation's completion status. /// </summary> public void editUnitOperation() { int?id = -1; Cache.gen_lock.WaitOne(); UnitFModel mf = null; if (SingletonCache.Instance().Storage.ContainsKey(Context.User.Identity.Name)) { mf = ((UnitFModel)SingletonCache.Instance().Storage[Context.User.Identity.Name]); } try { using (TimchurDatabaseEntities entity = new TimchurDatabaseEntities()) { var original = entity.Units.Find(mf.unit.ID); if (original != null) { entity.UnitsAuctions.RemoveRange(entity.UnitsAuctions.Where(x => x.UnitID == mf.unit.ID)); if (mf.Limitations != null) { foreach (int i in mf.Limitations) { UnitsAuctions ua = new UnitsAuctions(); ua.AuctionID = i; ua.UnitID = mf.unit.ID; entity.UnitsAuctions.Add(ua); } } entity.Entry(original).CurrentValues.SetValues(((UnitFModel)SingletonCache.Instance().Storage[Context.User.Identity.Name]).unit); entity.SaveChanges(); } } using (TimchurDatabaseEntities entity2 = new TimchurDatabaseEntities()) { int strm = mf.unit.ID; id = entity2.Units.Where(x => x.ID == strm).First().ID; } SingletonCache.Instance().last_msg[Context.User.Identity.Name] = "בפעולה האחרונה, יחידה עודכה במערכת"; } catch (Exception e) { System.Diagnostics.Trace.Write(e.ToString()); SingletonCache.Instance().last_msg[Context.User.Identity.Name] = "בפעולה האחרונה, עדכון יחידה נכשל במערכת"; } SingletonCache.Instance().Storage[Context.User.Identity.Name] = null; Cache.gen_lock.ReleaseMutex(); string str = Context.User.Identity.Name; string msg = ""; if (SingletonCache.Instance().last_msg.Keys.Contains(str)) { msg = SingletonCache.Instance().last_msg[str]; } string to_s = string.Format("סטאטוס:" + msg); Clients.Caller.sendMessage(id.Value.ToString()); }
/// <summary> /// Saves the stored update of an auction into the database, /// and sends a cache message of the operation's completion status. /// </summary> public void EditAuctionOperation() { int?id = -1; Cache.gen_lock.WaitOne(); try { using (TimchurDatabaseEntities entity = new TimchurDatabaseEntities()) { var original = entity.Auctions.Find(((Auctions)SingletonCache.Instance().Storage[Context.User.Identity.Name]).ID); if (original != null) { Auctions curr = ((Auctions)SingletonCache.Instance().Storage[Context.User.Identity.Name]); entity.Entry(original).CurrentValues.SetValues(((Auctions)SingletonCache.Instance().Storage[Context.User.Identity.Name])); entity.SaveChanges(); } entity.SaveChanges(); } using (TimchurDatabaseEntities entity2 = new TimchurDatabaseEntities()) { string strm = ((Auctions)(SingletonCache.Instance().Storage[Context.User.Identity.Name])).AuctionNumber; id = entity2.Auctions.Where(x => x.AuctionNumber == strm).First().ID; } SingletonCache.Instance().last_msg[Context.User.Identity.Name] = "בפעולה האחרונה, מכרז עודכן במערכת"; } catch (Exception e) { System.Diagnostics.Trace.Write(e.ToString()); SingletonCache.Instance().last_msg[Context.User.Identity.Name] = "בפעולה האחרונה, עדכון מכרז נכשל"; } SingletonCache.Instance().Storage[Context.User.Identity.Name] = null; Cache.gen_lock.ReleaseMutex(); string str = Context.User.Identity.Name; string msg = ""; if (SingletonCache.Instance().last_msg.Keys.Contains(str)) { msg = SingletonCache.Instance().last_msg[str]; } string to_s = string.Format("סטאטוס:" + msg); Clients.Caller.sendMessage(id.Value.ToString()); }
public void EditClusetrOperation() { int?id = -1; Cache.gen_lock.WaitOne(); try { using (TimchurDatabaseEntities entity = new TimchurDatabaseEntities()) { var original = entity.Clusetrs.Find(((Clusetrs)SingletonCache.Instance().Storage[Context.User.Identity.Name]).ID); if (original != null) { entity.Entry(original).CurrentValues.SetValues(((Clusetrs)SingletonCache.Instance().Storage[Context.User.Identity.Name])); entity.SaveChanges(); } entity.SaveChanges(); } using (TimchurDatabaseEntities entity2 = new TimchurDatabaseEntities()) { byte strm = ((Clusetrs)(SingletonCache.Instance().Storage[Context.User.Identity.Name])).DisplayNumber.Value; id = entity2.Clusetrs.Where(x => x.DisplayNumber == strm).First().ID; } SingletonCache.Instance().last_msg[Context.User.Identity.Name] = "בפעולה האחרונה,סל עודכן במערכת"; } catch (Exception e) { SingletonCache.Instance().last_msg[Context.User.Identity.Name] = "בפעולה האחרונה,עדכון סל נכשל"; } Cache.gen_lock.ReleaseMutex(); string str = Context.User.Identity.Name; string msg = ""; if (SingletonCache.Instance().last_msg.Keys.Contains(str)) { msg = SingletonCache.Instance().last_msg[str]; } string to_s = string.Format("סטאטוס:" + msg); Clients.Caller.sendMessage(id.Value.ToString()); }
public void editSupplierOperation() { int?id = -1; Cache.gen_lock.WaitOne(); SupplierFModel mf = ((SupplierFModel)SingletonCache.Instance().Storage[Context.User.Identity.Name]); try { using (TimchurDatabaseEntities entity = new TimchurDatabaseEntities()) { var original = entity.Suppliers.Find(mf.supliers.ID); if (original != null) { if (mf.Limitions != null) { foreach (int i in mf.Limitions) { SuppliersClusetrs ua = new SuppliersClusetrs(); if (entity.SuppliersClusetrs.Where(x => x.ClusetrID == i && x.SupplierID == mf.supliers.ID).Count() > 0) { entity.SuppliersClusetrs.Where(x => x.ClusetrID == i && x.SupplierID == mf.supliers.ID).First().StatusID = 1; } else { ua.ClusetrID = i; ua.SupplierID = id; ua.FormarLastTimeInList = new DateTime(2000, 1, 1); ua.LastTimeInList = new DateTime(2000, 1, 1); ua.StatusID = 1; entity.SuppliersClusetrs.Add(ua); } } } foreach (SuppliersClusetrs sc in entity.SuppliersClusetrs.Where(x => !mf.Limitions.Contains(x.ClusetrID) && x.SupplierID == mf.supliers.ID)) { sc.StatusID = 2; } if (mf.ActualEmail == null) { mf.supliers.EmailAddress = ""; } else { mf.supliers.EmailAddress = mf.ActualEmail; } mf.supliers.PhoneNumber = mf.Prefix + mf.ActualNumber; entity.Entry(original).CurrentValues.SetValues(((SupplierFModel)SingletonCache.Instance().Storage[Context.User.Identity.Name]).supliers); entity.SaveChanges(); } } using (TimchurDatabaseEntities entity2 = new TimchurDatabaseEntities()) { int strm = mf.supliers.ID; id = entity2.Suppliers.Where(x => x.ID == strm).First().ID; } SingletonCache.Instance().last_msg[Context.User.Identity.Name] = "בפעולה האחרונה,יחידה עודכה במערכת"; } catch (Exception e) { SingletonCache.Instance().last_msg[Context.User.Identity.Name] = "בפעולה האחרונה,הוספת יחידה נכשלה במערכת"; } Cache.gen_lock.ReleaseMutex(); string str = Context.User.Identity.Name; string msg = ""; if (SingletonCache.Instance().last_msg.Keys.Contains(str)) { msg = SingletonCache.Instance().last_msg[str]; } string to_s = string.Format("סטאטוס:" + msg); Clients.Caller.sendMessage(id.Value.ToString()); }