public ActionResult CancelTichur(TCanData can) { Cache.gen_lock.WaitOne(); try { using (TimchurDatabaseEntities ent = new TimchurDatabaseEntities()) { Tichurim tic = ent.Tichurim.Where(x => x.TichurNumber == can.id).FirstOrDefault(); foreach (SuppliersTichurim sti in tic.SuppliersTichurim) { if (sti.Suppliers.SuppliersClusetrs.Where(x2 => x2.ClusetrID == tic.ClusterID).First().LastTimeInList == tic.DateTimeCreated) { sti.Suppliers.SuppliersClusetrs.Where(x2 => x2.ClusetrID == tic.ClusterID).First().LastTimeInList = sti.Suppliers.SuppliersClusetrs.Where(x2 => x2.ClusetrID == tic.ClusterID).First().FormarLastTimeInList; } } tic.UpdatedUserID = ent.Users.Where(x => x.IDCardNumber == User.Identity.Name).First().ID; tic.DateTimeUpdated = DateTime.Now; tic.StatusID = 2; tic.UpdatedComment = can.comment; ent.SaveChanges(); Cache.gen_lock.ReleaseMutex(); return(Json("ביטול תיחור הצליח")); } } catch (Exception e) { Cache.gen_lock.ReleaseMutex(); return(Json("ביטול תיחור נכשל")); } }
/// <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); }
public ActionResult GetByTichurNumber(TNData data) { using (TimchurDatabaseEntities ent = new TimchurDatabaseEntities()) { Users use = ent.Users.Where(x => x.IDCardNumber == User.Identity.Name).First(); bool f = User.IsInRole("Admin"); string uni_fin = User.IsInRole("Admin") ? data.unit_field : use.UnitID.ToString(); int tem = 0; if (uni_fin != null) { tem = Int32.Parse(uni_fin); } if (tem == 0 || ent.Tichurim.Where(x => x.UnitID == tem && x.TichurNumber == data.id && (f || x.StatusID == 1)).Count() == 0) { GenModel failRes = new GenModel(); failRes.data = new List <string[]>(); failRes.data.Add(new string[] { "תיחור אינו קיים בתוך השרת(או תחת היחידה הנתונה של המשתמש או שהוכנסה)" }); failRes.Status = "error"; return(Json(failRes)); } if (!User.IsInRole("User")) { if (data.unit_field == null) { GenModel failRes = new GenModel(); failRes.data = new List <string[]>(); failRes.data.Add(new string[] { "אנא בחר ערך בשדה יחידה" }); failRes.Status = "error"; return(Json(failRes)); } } Tichurim tic = ent.Tichurim.Where(x => x.UnitID == tem && x.TichurNumber == data.id && (f || x.StatusID == 1)).First(); if (ent.UnitsAuctions.Where(x => x.UnitID == tem && x.AuctionID == tic.Clusetrs.AuctionID).Count() > 0) { if (User.IsInRole("User")) { Cache.gen_lock.WaitOne(); ent.Tichurim.Where(x => x.UnitID == tem && x.TichurNumber == data.id && x.StatusID == 1).First().DateTimeSelected = DateTime.Now; ent.SaveChanges(); Cache.gen_lock.ReleaseMutex(); } tic = ent.Tichurim.Where(x => x.UnitID == tem && x.TichurNumber == data.id && (f || x.StatusID == 1)).First(); GenModel Res = new GenModel(); Res.Status = "K"; Res.data = new List <string[]>(); Res.data.Add(new string[] { "מספר שורה", "מס' בתוצאת שליפה", "יחידה", "מס' מכרז", "שם מכרז", "תיחור", "מספר סל", "שם סל", "שם ספק", "ח.פ", "איש קשר", "אימייל", "טלפון", "תאריך ושעה" }); int i = 0; foreach (SuppliersTichurim st in tic.SuppliersTichurim) { Suppliers sup = ent.Suppliers.Where(x => x.ID == st.SupplierID).First(); i++; Res.data.Add(new string[] { i.ToString(), st.PositionInList.ToString(), tic.Units.Name, tic.Clusetrs.Auctions.AuctionNumber, tic.Clusetrs.Auctions.Name, tic.TichurNumber, tic.Clusetrs.DisplayNumber.Value.ToString(), tic.Clusetrs.Name, sup.Name, sup.CompanyNumber, sup.ContactName, sup.EmailAddress, sup.PhoneNumber, tic.DateTimeCreated.Value.ToString() }); } return(Json(Res)); } else { GenModel failRes = new GenModel(); failRes.data = new List <string[]>(); failRes.data.Add(new string[] { "משתמש אינו רשאי לצפות בתיחור" }); failRes.Status = "error"; return(Json(failRes)); } } }
public EndResultTichur Execute(TichurInfo info, string user_id) { Cache.gen_lock.WaitOne(); TablePullResult TRE; try { PullSuppList pull = new ExtractSuppList(); TRE = pull.TichurAlgorithem(info); } catch (Exception e) { EndResultTichur res = new EndResultTichur(); res.Status = "error"; res.data = new List <string[]>(); res.data.Add(new string[] { "תיחור כבר קיים בתוך המערכת" }); Cache.gen_lock.ReleaseMutex(); return(res); } 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(); SuppliersClusetrs scl = supa.SuppliersClusetrs.Where(x => x.ClusetrID == info.CluestrID).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.CluestrID; 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) { } } 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.Clusetrs.Auctions.AuctionNumber, tich.Clusetrs.Auctions.Name, tich.TichurNumber, tich.Clusetrs.DisplayNumber.Value.ToString(), tich.Clusetrs.Name, supa.Name, supa.CompanyNumber, supa.ContactName, supa.EmailAddress, supa.PhoneNumber, tich.DateTimeCreated.ToString() }); ent2.SuppliersTichurim.Add(suptic); i++; } ent2.SaveChanges(); } catch (Exception e) { } } Cache.gen_lock.ReleaseMutex(); return(res2); }