Esempio n. 1
0
        //
        // GET: /Member/Create
        public ActionResult Create()
        {
            var model = new UserModel()
            {
                AddDate = DateTime.Now,
                BirthDate = DateTime.Today.AddYears(-5),
                IsActive = true
            };

            return View(model);
        }
Esempio n. 2
0
        public ActionResult Create(UserModel user)
        {
            if (ModelState.IsValid)
            {
                if (user.BirthDate > DateTime.Now)
                {
                    ModelState.AddModelError("BirthDate", "Jesteś z przyszłości?");
                    return View(user);
                }

                try
                {
                    var dao = new UserService();

                    var u = new User
                    {
                        FirstName = user.FirstName,
                        LastName = user.LastName,
                        BirthDate = user.BirthDate,
                        Email = user.Email,
                        Phone = user.Phone,
                        AddDate = user.AddDate,
                        IsActive = user.IsActive
                    };

                    var err = dao.CreateUser(u);
                    if (err != null)
                    {
                        ModelState.AddModelError("", "Wystąpił problem podczas dodawania nowego użytkownika.");
                        return View(user);
                    }

                    return RedirectToAction("Index");
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                    return View(user);
                }
            }
            else
            {
                return View(user);
            }
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        public ActionResult Edit(int id, UserModel user)
        {
            if (ModelState.IsValid)
            {
                if (user.BirthDate > DateTime.Now)
                {
                    ModelState.AddModelError("BirthDate", "Jesteś z przyszłości?");
                    return View(user);
                }

                try
                {
                    var dao = new UserService();

                    var u = new User
                    {
                        UserID = id,
                        FirstName = user.FirstName,
                        LastName = user.LastName,
                        BirthDate = user.BirthDate,
                        Email = user.Email,
                        Phone = user.Phone,
                        AddDate = user.AddDate,
                        ModifiedDate = DateTime.Now,
                        IsActive = user.IsActive
                    };

                    var err = dao.UpdateUser(u);
                    if (err != null)
                    {
                        ModelState.AddModelError("", "Wystąpił problem podczas dodawania nowego użytkownika.");
                        return View(user);
                    }

                    return RedirectToAction("Index");
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                    return View(user);
                }
            }
            else
            {
                return View(user);
            }

            //try
            //{
            //    // TODO: Add update logic here

            //    return RedirectToAction("Index");
            //}
            //catch
            //{
            //    return View();
            //}
        }
Esempio n. 5
0
        public ActionResult Delete(int id, UserModel user)
        {
            if (ModelState.IsValid)
            {

                try
                {
                    var dao = new UserService();

                    var u = new User
                    {
                        UserID = id,
                        FirstName = user.FirstName,
                        LastName = user.LastName,
                        BirthDate = user.BirthDate,
                        Email = user.Email,
                        Phone = user.Phone,
                        AddDate = user.AddDate,
                        ModifiedDate = DateTime.Now,
                        IsActive = false
                    };

                    var err = dao.UpdateUser(u);
                    if (err != null)
                    {
                        ModelState.AddModelError("", "Wystąpił problem podczas usuwania użytkownika.");
                        return View(user);
                    }

                    return RedirectToAction("Index");
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                    return View(user);
                }
            }
            else
            {
                return View(user);
            }
        }