コード例 #1
0
        //
        // GET: /Member/Delete/5
        public ActionResult Delete(int id)
        {
            var dao = new UserService();
            var users = dao.GetUsers();
            var singleUser = users.SingleOrDefault(u => u.UserID == id);

            var model = new UserModel()
            {
                UserId = singleUser.UserID,
                FirstName = singleUser.FirstName,
                LastName = singleUser.LastName,
                Phone = singleUser.Phone,
                Email = singleUser.Email,
                AddDate = singleUser.AddDate,
                ModifiedDate = singleUser.ModifiedDate,
                BirthDate = singleUser.BirthDate,
                IsActive = singleUser.IsActive,
            };

            return View(model);
        }
コード例 #2
0
        public JsonResult GetUsersJson()
        {
            var dao = new UserService();

            var users = dao.GetUsers();
            var listModel = AutoMapper.Mapper.Map<List<User>, List<UserLiteModel>>(users);

            listModel.Insert(0, new UserLiteModel() { UserId = 0, FullName = "Wybierz użytkownika" });

            return this.Json(new { Items = listModel });
        }
コード例 #3
0
        public ActionResult Index()
        {
            var userService = new UserService();
            List<User> users = userService.GetUsers();

            //var firstUser = users.FirstOrDefault(u => u.FirstName == "Czesław");

            // nie moze byc nulla
            //var single = users.SingleOrDefault(u => u.UserID == 1);

            //if (single != null)
            //{
            //    var email = single.Email;
            //}

            //int sss = users.Where(u => u.FirstName.ToUpper().Contains("CZE")).Sum(u => u.LastName.Length);

            //mapowanie bez automappera
            var members = users
                .Select(u =>
                    new UserViewModel
                    {
                        UserId = u.UserID,
                        FirstName = u.FirstName,
                        LastName = u.LastName,
                        BirthDate = u.BirthDate,
                        Phone = u.Phone,
                        ModifiedDate = u.ModifiedDate,
                        Email = u.Email,
                        IsActive = u.IsActive,
                        HasBooks = u.HasBooks,
                    }
            ).ToList();

            return View(members);
        }
コード例 #4
0
 public void GetUsersTest()
 {
     var dao = new UserService();
     var users = dao.GetUsers();
     Assert.IsNotNull(users);
 }