Exemplo n.º 1
0
        public int? CreateUpdateUser(UserViewModel userViewModel)
        {
            User user = null;

            if (userViewModel.UserId > 0)
            {
                user = _repository.Find<User>(x => x.UserID == userViewModel.UserId);
                if (user == null)
                    return null;

                user.UserName = userViewModel.UserName;
                user.Email = userViewModel.Email;
                user.Address = userViewModel.Address;
                user.Password = userViewModel.Password;
                user.ContactNo = userViewModel.ContactNo;
                user.Zip = userViewModel.Zip;
                user.RoleId = userViewModel.RoleId;
                user.ModifiedBy = userViewModel.Last_ModifiedBy;
                user.ModifiedDate = DateTime.Now;

                _repository.Modify<User>(user);
                return user.UserID;
            }

            Mapper.CreateMap<UserViewModel, User>();
            user = Mapper.Map<UserViewModel, User>(userViewModel);

            user.CreatedDate = DateTime.Now;
            user.CreatedBy = userViewModel.CreatedBy;
            user.Active = true;
            user.IsDeleted = false;

            return _repository.Insert<User>(user);
        }
        public ActionResult LogIn(UserViewModel userModel)
        {
            var result = _accountComponent.CheckLogin(userModel);
            if (result == null)
            {
                ModelState.AddModelError("", "User name or password is incorrect.");
                return View("LogIn");
            }
            else
            {
                Session["UserDetail"] = result;
                GetAllPermissions(result.Role);
                FormsAuthentication.SetAuthCookie(new JavaScriptSerializer().Serialize(result), false);

                if (result.Role == Convert.ToInt32(EnumUtility.Role.Admin))
                {
                    return RedirectToAction("Customer", "Customer");
                }
                else
                {
                    return RedirectToAction("Customer", "Customer");
                }
               
            }
        }
        public ActiveUser CheckLogin(UserViewModel userModel)
        {

            var userData = _repository.Find<User>(x => x.UserName == userModel.UserName && x.Password== userModel.Password && x.Active == true);
            if (userData == null)
                return null;


            

            ActiveUser activeUser = new ActiveUser()
            {
                UserId = userData.UserID,
                Role = userData.RoleId,
                UserName = userData.UserName,
               
            };

            return activeUser;
        }
Exemplo n.º 4
0
 public ActionResult CreateUpdateUser(UserViewModel userViewModel)
 {
     if (userViewModel.UserId == Convert.ToInt32(EnumUtility.Role.Admin))
     {
         userViewModel.RoleId = Convert.ToInt32(EnumUtility.Role.Admin);
     }
     ActiveUser activeUser = new JavaScriptSerializer().Deserialize<ActiveUser>(System.Web.HttpContext.Current.User.Identity.Name);
     userViewModel.CreatedBy = activeUser.UserId;
     userViewModel.Last_ModifiedBy = activeUser.UserId;
     var result = _userComponent.CreateUpdateUser(userViewModel);
     return Json(result, JsonRequestBehavior.AllowGet);
 }
Exemplo n.º 5
0
 public ActionResult CreateUpdateUserPopup(int id)
 {
     var user = _userComponent.GetUser(id);
     var rolelist = _userComponent.GetAllRole();
     if (user == null)
         user = new UserViewModel();
     user.Rolelist = new SelectList(_userComponent.GetAllRole(), "RoleId", "Role1");
     return PartialView("/Views/Shared/Partials/_User.cshtml", user);
 }