private void SignInAsync(LoginModel user, bool isPersistent) { AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie); using (var conn = new TimchurDatabaseEntities()) { Users User = conn.Users.Where(s => (s.IDCardNumber).ToString() == user.Username).FirstOrDefault <Users>(); string role = "User"; if (User.Roles.ID == 1) { role = "User"; } else { role = "Admin"; } var identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, User.IDCardNumber), new Claim(ClaimTypes.GivenName, User.FullName), new Claim(ClaimTypes.Role, role) }, "ApplicationCookie"); SingletonCache.Instance().last_msg[User.IDCardNumber] = null; AuthenticationManager.SignIn( new AuthenticationProperties() { IsPersistent = isPersistent }, identity); } //צריך להוסיף להוציא שם מהמסד }
/// <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()); }
public void AddAuctionOperation() { int?id = -1; Cache.gen_lock.WaitOne(); try { using (TimchurDatabaseEntities entity = new TimchurDatabaseEntities()) { entity.Auctions.Add(((Auctions)SingletonCache.Instance().Storage[Context.User.Identity.Name])); 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) { 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 SendNotification() { if (SingletonCache.Instance().last_msg[Context.User.Identity.Name] != null) { string message = (string)(SingletonCache.Instance().last_msg[Context.User.Identity.Name].Clone()); SingletonCache.Instance().last_msg[Context.User.Identity.Name] = null; Clients.Caller.broadcastNotification(message); } }
public ActionResult EditAuction(Auctions auc) { if (ModelState.IsValid) { SingletonCache.Instance().Storage[User.Identity.Name] = auc; return(RedirectToAction("EAuctionLoadingScreen", "Main")); } else { return(View(auc)); } }
public ActionResult EditClusetr(Clusetrs clu) { if (ModelState.IsValid) { SingletonCache.Instance().Storage[User.Identity.Name] = clu; return(RedirectToAction("EClusetrLoadingScreen", "Main")); } else { return(View(clu)); } }
public ActionResult EditUnit(UnitFModel uni) { if (ModelState.IsValid) { SingletonCache.Instance().Storage[User.Identity.Name] = uni; return(RedirectToAction("EUnitLoadingScreen", "Main")); } else { return(View(uni)); } }
public void Configuration(IAppBuilder app) { app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = "ApplicationCookie", LoginPath = new PathString("/Login/Index"), ExpireTimeSpan = TimeSpan.FromMinutes(3) }); SingletonCache.Instance(); // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=316888 app.MapSignalR(); }
public ActionResult EditSupplier(SupplierFModel sup) { if (ModelState.IsValid) { SingletonCache.Instance().Storage[User.Identity.Name] = sup; return(RedirectToAction("ESupplierLoadingScreen", "Main")); } else { return(View(sup)); } }
public ActionResult EditUser(Users use) { if (ModelState.IsValid) { SingletonCache.Instance().Storage[User.Identity.Name] = use; return(RedirectToAction("EUserLoadingScreen", "Main")); } else { return(View(use)); } }
/// <summary> /// Saves the stored creation of a unit into the database, /// and sends a cache message of the operation's completion status. /// </summary> public void AddUnitOperation() { int?id = -1; Cache.gen_lock.WaitOne(); UnitFModel mf = ((UnitFModel)SingletonCache.Instance().Storage[Context.User.Identity.Name]); try { using (TimchurDatabaseEntities entity = new TimchurDatabaseEntities()) { entity.Units.Add(mf.unit); entity.SaveChanges(); } using (TimchurDatabaseEntities entity2 = new TimchurDatabaseEntities()) { string strm = mf.unit.Name; id = entity2.Units.Where(x => x.Name == strm).First().ID; if (mf.Limitations != null) { foreach (int i in mf.Limitations) { UnitsAuctions ua = new UnitsAuctions(); ua.AuctionID = i; ua.UnitID = id; entity2.UnitsAuctions.Add(ua); } } entity2.SaveChanges(); } 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()); }
protected override bool AuthorizeCore(HttpContextBase context) { var isAuthorized = base.AuthorizeCore(context); if (!isAuthorized) { return(false); } var claimsIdentity = context.User.Identity as System.Security.Claims.ClaimsIdentity; var name = claimsIdentity.FindFirst(System.Security.Claims.ClaimTypes.Name); string[] prem_list = SingletonCache.Instance().role_map[Name].Split(','); string role = claimsIdentity.FindFirst(System.Security.Claims.ClaimTypes.Role).Value; //redirection to error page in this case if (!prem_list.Contains(role)) { return(false); } return(true); }
/// <summary> /// Saves the stored creation of a cluster into the database, /// and sends a cache message of the operation's completion status. /// </summary> public void AddClusterOperation() { int?id = -1; Cache.gen_lock.WaitOne(); try { using (TimchurDatabaseEntities entity = new TimchurDatabaseEntities()) { entity.Clusters.Add(((Clusters)SingletonCache.Instance().Storage[Context.User.Identity.Name])); entity.SaveChanges(); } using (TimchurDatabaseEntities entity2 = new TimchurDatabaseEntities()) { byte strm = ((Clusters)(SingletonCache.Instance().Storage[Context.User.Identity.Name])).DisplayNumber.Value; id = entity2.Clusters.Where(x => x.DisplayNumber == 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 ActionResult AddSupplier(SupplierFModel sup) { if (ModelState.IsValid) { using (TimchurDatabaseEntities entity = new TimchurDatabaseEntities()) { int cou = entity.Suppliers.Count(x => x.Name == sup.supliers.Name); if (cou != 0) { ModelState.AddModelError("Exist", "יחידה בעלת מספר זה כבר קיים."); return(View(sup)); } else { SingletonCache.Instance().Storage[User.Identity.Name] = sup; return(RedirectToAction("SupplierLoadingScreen", "Main")); } } } else { return(View(sup)); } }
public ActionResult AddUnit(UnitFModel uni) { if (ModelState.IsValid) { using (TimchurDatabaseEntities entity = new TimchurDatabaseEntities()) { int cou = entity.Units.Count(x => x.Name == uni.unit.Name); if (cou != 0) { ModelState.AddModelError("Exist", "יחידה בעלת מספר זה כבר קיים."); return(View(uni)); } else { SingletonCache.Instance().Storage[User.Identity.Name] = uni; return(RedirectToAction("UnitLoadingScreen", "Main")); } } } else { return(View(uni)); } }
public ActionResult AddClusetr(Clusetrs clu) { if (ModelState.IsValid) { using (TimchurDatabaseEntities entity = new TimchurDatabaseEntities()) { int cou = entity.Clusetrs.Count(x => x.DisplayNumber == clu.DisplayNumber); if (cou != 0) { ModelState.AddModelError("Exist", "ספק בעל מספר זה כבר קיים."); return(View(clu)); } else { SingletonCache.Instance().Storage[User.Identity.Name] = clu; return(RedirectToAction("ClusetrLoadingScreen", "Main")); } } } else { return(View(clu)); } }
public ActionResult AddAuction(Auctions auc) { if (ModelState.IsValid) { using (TimchurDatabaseEntities entity = new TimchurDatabaseEntities()) { int cou = entity.Auctions.Count(x => x.AuctionNumber == auc.AuctionNumber); if (cou != 0) { ModelState.AddModelError("Exist", "מכרז בעל מספר זה כבר קיים."); return(View(auc)); } else { SingletonCache.Instance().Storage[User.Identity.Name] = auc; return(RedirectToAction("AuctionLoadingScreen", "Main")); } } } else { return(View(auc)); } }
public ActionResult AddUser(Users use) { if (ModelState.IsValid) { using (TimchurDatabaseEntities entity = new TimchurDatabaseEntities()) { int cou = entity.Users.Count(x => x.IDCardNumber == use.IDCardNumber); if (cou != 0) { ModelState.AddModelError("Exist", "המשתמש בעל תעודת הזהות הזאת כבר קיים."); return(View(use)); } else { SingletonCache.Instance().Storage[User.Identity.Name] = use; return(RedirectToAction("UserLoadingScreen", "Main")); } } } else { return(View(use)); } }
public void AddSupplierOperation() { int?id = -1; Cache.gen_lock.WaitOne(); SupplierFModel mf = ((SupplierFModel)SingletonCache.Instance().Storage[Context.User.Identity.Name]); try { using (TimchurDatabaseEntities entity = new TimchurDatabaseEntities()) { if (mf.ActualEmail == null) { mf.supliers.EmailAddress = ""; } else { mf.supliers.EmailAddress = mf.ActualEmail; } mf.supliers.PhoneNumber = mf.Prefix + mf.ActualNumber; entity.Suppliers.Add(mf.supliers); entity.SaveChanges(); } using (TimchurDatabaseEntities entity2 = new TimchurDatabaseEntities()) { string strm = mf.supliers.Name; id = entity2.Suppliers.Where(x => x.Name == strm).First().ID; if (mf.Limitions != null) { foreach (int i in mf.Limitions) { SuppliersClusetrs ua = new SuppliersClusetrs(); ua.ClusetrID = i; ua.SupplierID = id; ua.FormarLastTimeInList = new DateTime(2000, 1, 1); ua.LastTimeInList = new DateTime(2000, 1, 1); ua.StatusID = 1; entity2.SuppliersClusetrs.Add(ua); } } entity2.SaveChanges(); } 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()); }