public bool IsCorrect(UserInfo UsI, int numOfToken) { string ELogin; string EPassword; string EToken; //Get encrypted data from DB table (Login, Password, Token) using (HelloBlogEntities db = new HelloBlogEntities()) { var DataFromDB = db.LoginData.Where(r => r.Id == 1).FirstOrDefault(); EToken = db.TokenCard.Where(r => r.Id == numOfToken).FirstOrDefault().Token.ToString(); ELogin = DataFromDB.Login.ToString(); EPassword = DataFromDB.Password.ToString(); } //Encrypt Data From DB in multithreading style using Tasks Task <string> task1 = Task.Factory.StartNew(() => DecryptMyStuff(ELogin)); Task <string> task2 = Task.Factory.StartNew(() => DecryptMyStuff(Regex.Replace(EPassword, @"\s+", ""))); Task <string> task3 = Task.Factory.StartNew(() => DecryptMyStuff(EToken)); Task.WaitAll(); //After Tasks is completed results are inicialization to the strings variables if (Task.WhenAll().IsCompleted) { ELogin = task1.Result; EPassword = task2.Result; EToken = task3.Result; } //Checking if login, password, token are corrects, and if correct return true return(UsI.Name == ELogin && UsI.Password == EPassword && UsI.Token == EToken ? true : false); }
public ActionResult EditPost(int?id) { Posts postToEdit = new Posts(); if (id != null) { HelloBlogEntities db = new HelloBlogEntities(); postToEdit = db.Posts.Where(x => x.ID == id).SingleOrDefault(); if (postToEdit == null) { ViewBag.MessageToShow = "Post o podanym ID nie istnieje w bazie danych"; } } return(View(postToEdit)); }
public ActionResult EditPost(Posts p, bool LinkPicEdit) { using (HelloBlogEntities db = new HelloBlogEntities()) { var item = db.Posts.Where(x => x.ID == p.ID).FirstOrDefault(); if (!LinkPicEdit) { checkPic(p); } item.PicImg = p.PicImg ?? item.PicImg; item.Title = p.Title ?? item.Title; item.Body = p.Body ?? item.Body; db.SaveChanges(); } return(RedirectToAction("EditPost")); }
public ActionResult AddNewPostToHB(Posts p, bool Today, bool LinkPic) { if (!LinkPic) { checkPic(p); } if (Today) { p.DateTime = DateTime.Now; } using (HelloBlogEntities db = new HelloBlogEntities()) { db.Posts.Add(p); db.SaveChanges(); } return(RedirectToAction("AddNewPostToHB")); }