Ejemplo n.º 1
0
        // GET: Users
        public ActionResult Index()
        {
            ListUserViewModels user;

            List<ListUserViewModels> model = new List<ListUserViewModels>();

            foreach (var item in db.Users.ToList().OrderBy(item => item.UserName))
            {
                int count = 0;
                if (db.UserSessions.Where(us => us.UserId == item.Id).ToList() != null)
                {
                    count = db.UserSessions.Where(us => us.UserId == item.Id).ToList().Count;
                }
                user = new ListUserViewModels();
                user.Id = item.Id;
                user.UserName = item.UserName;
                user.Email = item.Email;
                user.AccessFailedCount = item.AccessFailedCount;
                user.AccessDate = count > 0 ?
                    db.UserSessions.Where(us => us.UserId == item.Id).ToList()[0].AccessDate : DateTime.Now;
                user.IsOnLine = count > 0 ?
                    db.UserSessions.Where(us => us.UserId == item.Id).ToList()[0].IsOnLine : false;
                user.IsOnLineImg = count > 0 ?
                    db.UserSessions.Where(us => us.UserId == item.Id).ToList()[0].IsOnLine ? "/Content/img/online.jpg" : "/Content/img/offline.jpg" : "/Content/img/offline.jpg";
                user.IpAddress = count > 0 ?
                    db.UserSessions.Where(us => us.UserId == item.Id).ToList()[0].IpAddress : string.Empty;

                model.Add(user);
            } 

            return View(model.ToList());
        }
Ejemplo n.º 2
0
        // GET: Users/Details/5
        public ActionResult Details(string id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            User user = db.Users.Find(id);
            List<UserSession> usersession = db.UserSessions.Where(us => us.UserId == user.Id).ToList();

            if (user == null)
            {
                return HttpNotFound();
            }

            int count = 0;
            if (usersession.Count > 0)
            {
                count = usersession.Count;
            }
            
            ListUserViewModels model = new ListUserViewModels
            {
                
                Id = user.Id,
                UserName = user.UserName,
                Email = user.Email,
                EmailConfirmed = user.EmailConfirmed,
                EmailConfirmedImg = user.EmailConfirmed ? "/Content/img/ok.png" : "/Content/img/nook.png",
                PhoneNumber = user.PhoneNumber == null ? "-" : user.PhoneNumber,
                PhoneNumberConfirmed = user.PhoneNumberConfirmed,
                PhoneNumberConfirmedImg = user.PhoneNumberConfirmed ? "/Content/img/ok.png" : "/Content/img/nook.png",
                AccessFailedCount = user.AccessFailedCount,
                AccessDate = count > 0 ?  usersession[0].AccessDate : DateTime.Now,
                IsOnLine = count > 0 ? usersession[0].IsOnLine : false,
                IsOnLineImg = count > 0 ? usersession[0].IsOnLine ? "/Content/img/online.jpg" : "/Content/img/offline.jpg" : "/Content/img/offline.jpg",
                IpAddress = count > 0 ? usersession[0].IpAddress : string.Empty
            };

            return View(model);
        }
Ejemplo n.º 3
0
        // GET: Users/Delete/5
        public ActionResult Delete(string id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            User user = db.Users.Find(id);
            if (user == null)
            {
                return HttpNotFound();
            }

            ListUserViewModels model = new ListUserViewModels
            {
                Id = user.Id,
                UserName = user.UserName,
                Email = user.Email,
                EmailConfirmed = user.EmailConfirmed,
                EmailConfirmedImg = user.EmailConfirmed ? "/Content/img/ok.png" : "/Content/img/nook.png",
                PhoneNumber = user.PhoneNumber == null ? "-" : user.PhoneNumber,
                PhoneNumberConfirmed = user.PhoneNumberConfirmed,
                PhoneNumberConfirmedImg = user.PhoneNumberConfirmed ? "/Content/img/ok.png" : "/Content/img/nook.png",
                AccessFailedCount = user.AccessFailedCount
            };

            return View(model);
        }