示例#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"));
        }
示例#2
0
        public JsonResult UpdateUser(VM_AspNetUser aUser)
        {
            AspNetUser aspNetUser = unitOfWork.AspNetUserRepository.GetByID(aUser.Id);

            aspNetUser.Id           = aUser.Id;
            aspNetUser.UserFullName = aUser.UserFullName;
            aspNetUser.UserName     = aUser.UserName;
            aspNetUser.PhoneNumber  = aUser.PhoneNo;
            aspNetUser.Email        = aUser.Email;
            tblRestaurantUser aRestaurantUser =
                unitOfWork.RestaurantUserRepository.Get(a => a.UserId == aUser.Id).FirstOrDefault();

            aRestaurantUser.EditedBy       = SessionManger.LoggedInUser(Session);
            aRestaurantUser.EditedDateTime = DateTime.Now;
            //PASSOWRD save+ UserName & Email uniQ check required

            var EmailExist = unitOfWork.AspNetUserRepository.Get()
                             .Where(x => x.Email == aUser.Email && x.Id != aUser.Id).ToList();
            var UserNameExist = unitOfWork.AspNetUserRepository.Get()
                                .Where(x => x.UserName == aUser.UserName && x.Id != aUser.Id).ToList();

            try
            {
                if (!EmailExist.Any())
                {
                    if (!UserNameExist.Any())
                    {
                        //UPDATE

                        unitOfWork.RestaurantUserRepository.Update(aRestaurantUser);
                        unitOfWork.AspNetUserRepository.Update(aspNetUser);
                        unitOfWork.Save();
                        return(Json(new { success = true, successMessage = "User has updated Successfully." }, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        return(Json(new { success = false, errorMessage = "This user name already exist." }, JsonRequestBehavior.AllowGet));
                    }
                }
                else
                {
                    return(Json(new { success = false, errorMessage = "This email already exist." }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception exception)
            {
                return(Json(new { success = false, errorMessage = exception.Message }, JsonRequestBehavior.AllowGet));
            }
        }
示例#3
0
        public JsonResult DeleteUser(string Id)
        {
            try
            {
                AspNetUser        aUser = unitOfWork.AspNetUserRepository.GetByID(Id);
                tblRestaurantUser rUser =
                    unitOfWork.RestaurantUserRepository.Get().Where(x => x.UserId == Id).FirstOrDefault();
                if (aUser == null)
                {
                    return(Json(new { success = false, errorMessage = "User Delete Failed." }, JsonRequestBehavior.AllowGet));
                }
                unitOfWork.RestaurantUserRepository.Delete(rUser);
                unitOfWork.AspNetUserRepository.Delete(aUser);

                unitOfWork.Save();
                return(Json(new { success = true, message = "User Delete Successfull." }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, errorMessage = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
示例#4
0
        //[ValidateAntiForgeryToken]
        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);

                    RestaurantEntities RestaurantCal = new RestaurantEntities();
                    AspNetUser         anu           = new AspNetUser();

                    //AspNetUser userId = RestaurantCal.AspNetRoles.Select(a => a.Name == model.UserName).FirstOrDefault();
                    AspNetUser searchUser   = RestaurantCal.AspNetUsers.Where(a => a.UserName == model.UserName).FirstOrDefault();
                    decimal    restaurentId = SessionManger.RestaurantOfLoggedInUser(Session);
                    if (result.Succeeded)
                    {
                        using (RestaurantEntities rc = new RestaurantEntities())
                        {
                            try
                            {
                                tblRestaurantUser RestaurantUser = new tblRestaurantUser();


                                RestaurantUser.UserId          = searchUser.Id;
                                RestaurantUser.restaurant_id   = restaurentId;
                                RestaurantUser.RestaurantId    = Int32.Parse(SessionManger.RestaurantOfLoggedInUser(Session).ToString());
                                RestaurantUser.CreatedBy       = SessionManger.LoggedInUser(Session);
                                RestaurantUser.CreatedDateTime = DateTime.Now;
                                RestaurantUser.EditedBy        = null;
                                RestaurantUser.EditedDateTime  = null;
                                // RestaurantUser.is_admin = 0;
                                //RestaurantUser.is_loggedIn = null;
                                //RestaurantUser.last_logged_time = null;
                                //RestaurantUser.approve_by = null;
                                //RestaurantUser.approve_date = null;
                                rc.tblRestaurantUsers.Add(RestaurantUser);
                                rc.SaveChanges();

                                return(Json(new { success = true, successMessage = "User has created Successfully." }));
                            }
                            catch (Exception)
                            {
                                throw;
                            }
                        }
                    }
                    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));
            }


            return(View(model));
        }