public UserModel CreateUser(UserModel user)
        {
            var usr = Mapper.Map<UserModel, Data.Graph.Employee>(user);
            usr.Password = SecurityRepository.GetHashFromPassword(user.PasswordString);
            usr = SecurityRepository.SaveOrUpdateUser(usr);

            return Mapper.Map<Data.Graph.Employee, UserModel>(usr);
        }
 public void SignOut(UserModel employee, int locationId)
 {
     var log = GetEmployeeLogFromCache(locationId, false);
     if (null != log.Where(l => l.Employee.Id == employee.Id).FirstOrDefault())
     {
         var graph = Mapper.Map<UserModel, Data.Graph.Employee>(employee);
         SecurityRepository.UpdateEmployeeLog(graph, locationId);
     }
 }
 public void SignIn(UserModel employee, int locationId)
 {
     //Don't allow multiple sign-ins per day/location
     var log = GetEmployeeLogFromCache(locationId, false);
     if (null == log.Where(l => l.Employee.Id == employee.Id).FirstOrDefault())
     {
         var graph = Mapper.Map<UserModel, Data.Graph.Employee>(employee);
         SecurityRepository.InsertEmployeeLog(graph, locationId);
     }
 }
        public UserModel UpdateUser(UserModel user)
        {
            var usr = Mapper.Map<UserModel, Data.Graph.Employee>(user);
            var existing = SecurityRepository.GetUser(usr.Id);

            //Allow for changing password
            if (!string.IsNullOrEmpty(user.PasswordString))
            {
                existing.Password = SecurityRepository.GetHashFromPassword(user.PasswordString);
            }
            existing.FirstName = usr.FirstName;
            existing.IsEmployed = usr.IsEmployed;
            existing.LastName = usr.LastName;
            existing.Name = usr.Name;
            existing.Rate = usr.Rate;
            existing.RoleName = usr.RoleName;
            existing.LocationId = usr.LocationId;
            existing.CanLogin = usr.CanLogin;

            usr = SecurityRepository.SaveOrUpdateUser(existing);

            return Mapper.Map<Data.Graph.Employee, UserModel>(usr);
        }
        public ActionResult NewUser(UserModel user, UserFilterModel filter)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    EmployeeServices.CreateUser(user);
                    return RedirectToAction("UserListing", filter.GenerateUserAccessRoute());
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
                ModelState.AddModelError(String.Empty, Constants.ServerError);
            }

            // Invalid - redisplay with errors
            var model = new UserDetailModel()
            {
                Action = "NewUser",
                User = user,
                Filter = filter,
                Roles = LookupServices.GetRoleOptions(user.RoleName)
            };

            ViewBag.Locations = LocationServices.GetLocationLookup(true, -1);
            return View("UserDetail", model);
        }