Example #1
0
        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 (RestaurantEntities rc = new RestaurantEntities())
                    {
                        try
                        {
                            tblRestaurantUser RestaurantUser = new tblRestaurantUser();
                            var resturant = unitOfWork.RestaurantRepository.Get().Where(x => x.short_name == model.RestaurantName).FirstOrDefault();
                            RestaurantUser.UserId           = user.Id;
                            RestaurantUser.is_loggedIn      = 1;
                            RestaurantUser.last_logged_time = DateTime.Now;
                            RestaurantUser.restaurant_id    = resturant.restaurant_id;
                            //rc.tblAdminUsers.Attach(RestaurantUser);
                            //var entry = rc.Entry(RestaurantUser);
                            //entry.State = EntityState.Modified;
                            //rc.SaveChanges();
                            unitOfWork.AdminUserRepository.Update(RestaurantUser);
                            unitOfWork.Save();
                            SessionManger.SetLoggedInTime(Session, DateTime.Now);

                            SessionManger.SetLoggedInUser(Session, model.UserName, resturant.restaurant_id);
                            return(Redirect("/#Index"));
                            // return Json(new { success = true, successMessage = "Successfully User Created" });
                        }
                        catch (Exception ex)
                        {
                            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 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"));
        }