public static decimal?GetUserLoggedIn(string userId) { decimal?loggedIn = 0; HanifWorkShop_DBEntity WorkShopEn = new HanifWorkShop_DBEntity(); loggedIn = WorkShopEn.tblWorkShopUsers.Where(a => a.UserId == userId).Select(a => a.is_loggedIn).FirstOrDefault(); return(loggedIn); }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { TempData["errorMessage"] = string.Empty; if (ModelState.IsValid) { var user = await UserManager.FindAsync(model.UserName, model.Password); if (user != null) { await SignInAsync(user, model.RememberMe); using (HanifWorkShop_DBEntity rc = new HanifWorkShop_DBEntity()) { try { tblWorkShopUser WorkShopUser = new tblWorkShopUser(); var workShop = unitOfWork.WorkShopInformationRepository.Get().Where(x => x.short_name == model.AgencyName).FirstOrDefault(); WorkShopUser.UserId = user.Id; WorkShopUser.is_loggedIn = 1; WorkShopUser.last_logged_time = DateTime.Now; WorkShopUser.workShop_id = workShop.workShop_id; unitOfWork.WorkShopUserRepository.Update(WorkShopUser); unitOfWork.Save(); SessionManger.SetLoggedInTime(Session, DateTime.Now); SessionManger.SetLoggedInUser(Session, model.UserName, workShop.workShop_id); return(Redirect("/#Index")); // return Json(new { success = true, successMessage = "Successfully User Created" }); } catch (Exception) { return(Redirect("/#Login")); throw; } } //return RedirectToLocal(returnUrl); } else { ModelState.AddModelError("", "Invalid username or password."); TempData["errorMessage"] = "Invalid username or password."; //return View(model); View(model); //System.Threading.Thread.SpinWait(60); return(Redirect("/#Login")); } } // If we got this far, something failed, redisplay form //return View(model); TempData["errorMessage"] = "Invalid username or password."; //return View(model); View(model); //System.Threading.Thread.SpinWait(60); return(Redirect("/#Login")); }
public static bool isUserLoggedIn() { decimal?loggedIn = 0; string userId = HttpContext.Current.User.Identity.GetUserId(); HanifWorkShop_DBEntity WorkShopEn = new HanifWorkShop_DBEntity(); loggedIn = WorkShopEn.tblWorkShopUsers.Where(a => a.UserId == userId).Select(a => a.is_loggedIn).FirstOrDefault(); if (loggedIn == 1) { return(true); } else { return(false); } }
public GenericRepository(HanifWorkShop_DBEntity context) { this.context = context; this.dbSet = context.Set <TEntity>(); }
public SPRepository(HanifWorkShop_DBEntity context) { context = this.context; }
public CustomRepository(HanifWorkShop_DBEntity context) { this.context = context; }
//[ValidateAntiForgeryToken] //public async Task<ActionResult> Register(RegisterViewModel model) //{ // if (ModelState.IsValid) // { // var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; // var result = await UserManager.CreateAsync(user, model.Password); // if (result.Succeeded) // { // await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false); // // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // // Send an email with this link // // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); // return RedirectToAction("Index", "Home"); // } // AddErrors(result); // } // // If we got this far, something failed, redisplay form // return View(model); //} public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var results = await UserManager.FindByNameAsync(model.UserName); if (results != null) { return(Json(new { success = false, errorMessage = "This User Name already exists" }, JsonRequestBehavior.AllowGet)); } else { // Create User var user = new ApplicationUser() { UserName = model.UserName, Email = model.Email, PhoneNumber = model.PhoneNumber }; var result = await UserManager.CreateAsync(user, model.Password); HanifWorkShop_DBEntity AgencyCal = new HanifWorkShop_DBEntity(); AspNetUser anu = new AspNetUser(); //AspNetUser userId = RestaurantCal.AspNetRoles.Select(a => a.Name == model.UserName).FirstOrDefault(); AspNetUser searchUser = AgencyCal.AspNetUsers.Where(a => a.UserName == model.UserName).FirstOrDefault(); decimal workShopId = SessionManger.WorkShopOfLoggedInUser(Session); if (result.Succeeded) { using (HanifWorkShop_DBEntity rc = new HanifWorkShop_DBEntity()) { try { tblWorkShopUser AgencyUser = new tblWorkShopUser(); AgencyUser.UserId = searchUser.Id; AgencyUser.workShop_id = workShopId; AgencyUser.WorkShopId = Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString()); AgencyUser.CreatedBy = SessionManger.LoggedInUser(Session); AgencyUser.CreatedDateTime = DateTime.Now; AgencyUser.EditedBy = null; AgencyUser.EditedDateTime = null; // RestaurantUser.is_admin = 0; //RestaurantUser.is_loggedIn = null; //RestaurantUser.last_logged_time = null; //RestaurantUser.approve_by = null; //RestaurantUser.approve_date = null; rc.tblWorkShopUsers.Add(AgencyUser); rc.SaveChanges(); return(Json(new { success = true, successMessage = "User has created Successfully." }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { success = false, errorMessage = ex }, JsonRequestBehavior.AllowGet)); } } } else { return(Json(new { success = false, errorMessage = "This Email has already taken." }, JsonRequestBehavior.AllowGet)); } } } else { return(Json(new { success = false, errorMessage = "Model is not Valid." }, JsonRequestBehavior.AllowGet)); } }