/// <summary> /// Performs the extraction and returns the result. /// </summary> /// <param name="info">Specifics of the information required for the extraction.</param> /// <param name="user_id">ID of the user requesting the extraction.</param> /// <returns></returns> public EndResultTichur Execute(TichurInfo info, string user_id) { Cache.gen_lock.WaitOne(); TablePullResult TRE; // Attempting extraction try { PullSuppList pull = new ExtractSuppList(); TRE = pull.TichurExtract(info); } // Extraction failed, catching cause of error catch (Exception e) { EndResultTichur res = new EndResultTichur(); res.Status = "error"; res.data = new List <string[]>(); res.data.Add(new string[] { e.Message }); Cache.gen_lock.ReleaseMutex(); return(res); } // Assuming extraction completed successfully, // Captures the data and updates the database entity accordingly before returning. using (Database.TimchurDatabaseEntities ent = new Database.TimchurDatabaseEntities()) { DateTime tic_date = DateTime.Now; try { foreach (string sup in TRE.table) { int sid = Int32.Parse(sup); Suppliers supa = ent.Suppliers.Where(x => x.ID == sid).First(); SuppliersClusters scl = supa.SuppliersClusters.Where(x => x.ClusterID == info.ClusterID).First(); scl.FormarLastTimeInList = scl.LastTimeInList; scl.LastTimeInList = tic_date; } Users user = ent.Users.Where(x => x.IDCardNumber == user_id).First(); Tichurim tichur = new Tichurim(); tichur.UnitID = info.UnitID; tichur.ClusterID = info.ClusterID; tichur.TichurNumber = info.TichurNumber; tichur.StatusID = 1; tichur.DateTimeCreated = DateTime.Now; tichur.DateTimeSelected = DateTime.Now; tichur.DateTimeUpdated = DateTime.Now; tichur.CreatedUserID = user.ID; tichur.UpdatedUserID = user.ID; tichur.UpdatedComment = "Created"; ent.Tichurim.Add(tichur); ent.SaveChanges(); } catch (Exception e) { Trace.Write(e.Message); } } EndResultTichur res2 = new EndResultTichur(); res2.Status = "K"; res2.data = new List <string[]>(); using (Database.TimchurDatabaseEntities ent2 = new Database.TimchurDatabaseEntities()) { try { int i = 0; Tichurim tich = ent2.Tichurim.Where(x => x.TichurNumber == info.TichurNumber && x.StatusID == 1).First(); foreach (string supp in TRE.table) { int sup_id = Int32.Parse(supp); SuppliersTichurim suptic = new SuppliersTichurim(); suptic.TichurID = tich.ID; suptic.SupplierID = sup_id; suptic.PositionInList = byte.Parse(i.ToString()); Suppliers supa = ent2.Suppliers.Where(x => x.ID == sup_id).First(); res2.data.Add(new string[] { i.ToString(), suptic.PositionInList.Value.ToString(), tich.Units.Name, tich.Clusters.Auctions.AuctionNumber, tich.Clusters.Auctions.Name, tich.TichurNumber, tich.Clusters.DisplayNumber.Value.ToString(), tich.Clusters.Name, supa.Name, supa.CompanyNumber, supa.ContactName, supa.EmailAddress, supa.PhoneNumber, tich.DateTimeCreated.Value.ToString("yyyy:MM:dd:HH:mm:ss") }); ent2.SuppliersTichurim.Add(suptic); i++; } ent2.SaveChanges(); } catch (Exception e) { Trace.Write(e.Message); } } Cache.gen_lock.ReleaseMutex(); return(res2); }
/// <summary> /// Saves the stored update of a supplier into the database, /// and sends a cache message of the operation's completion status. /// </summary> 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.Limitations != null) { foreach (int i in mf.Limitations) { SuppliersClusters ua = new SuppliersClusters(); if (entity.SuppliersClusters.Where(x => x.ClusterID == i && x.SupplierID == mf.supliers.ID).Count() > 0) { entity.SuppliersClusters.Where(x => x.ClusterID == i && x.SupplierID == mf.supliers.ID).First().StatusID = 1; } else { ua.ClusterID = i; ua.SupplierID = mf.supliers.ID; ua.FormarLastTimeInList = new DateTime(2000, 1, 1); ua.LastTimeInList = new DateTime(2000, 1, 1); ua.StatusID = 1; entity.SuppliersClusters.Add(ua); } } } foreach (SuppliersClusters sc in entity.SuppliersClusters.Where(x => !mf.Limitations.Contains(x.ClusterID) && 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) { 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()); }