Ejemplo n.º 1
0
        public ActionResult Add(ToDo.userlogin userlogin, string user_password2)
        {
            if (!user_password2.Equals(userlogin.password))
            {
                ModelState.AddModelError("passwordVertify", "Password must be same.");
            }

            using (var dc = new todo_listEntities())
            {
                int countoflogin = dc.userlogins.Where(x => x.login.Equals(userlogin.login)).Count();
                if (countoflogin != 0)
                {
                    ModelState.AddModelError("login", "Login is already exist");
                }
            }

            if (ModelState.IsValid)
            {
                userlogin.password = EncryptHelper.encryptPassword(userlogin.password);
                using (var dc = new todo_listEntities())
                {
                    dc.userlogins.Add(userlogin);
                    dc.SaveChanges();
                }

                return(RedirectToAction("Index", "Login"));
            }
            else
            {
                return(View("Index", userlogin));
            }
        }
Ejemplo n.º 2
0
        public ActionResult Delete(item item)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Login"));
            }

            using (var dc = new todo_listEntities())
            {
                var i = dc.items.SingleOrDefault(it => it.iditem == item.iditem);
                dc.items.Remove(i);
                dc.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
        public ActionResult Singin(String login, String password, String remember)
        {
            bool remem = remember != null;

            if (new ToDoMemberShipProvider().ValidateUser(login, EncryptHelper.encryptPassword(password)))
            {
                using (var dc = new todo_listEntities())
                {
                    userlogin user     = dc.userlogins.FirstOrDefault(u => u.login.Equals(login));
                    var       myCookie = new HttpCookie("myCookie");
                    myCookie.Values.Add("id", user.iduser.ToString());
                    Response.Cookies.Add(myCookie);
                    FormsAuthentication.SetAuthCookie(login, remem);
                }
                return(RedirectToAction("Index", "Home"));
            }

            TempData["error"] = "Login or password is invalid";
            return(RedirectToAction("Index", "Login"));
        }
Ejemplo n.º 4
0
        public String ajaxCheck(DataModel model)
        {
            if (!User.Identity.IsAuthenticated)
            {
                RedirectToAction("Index", "Login");
            }

            List <item> items = null;

            using (var dc = new todo_listEntities())
            {
                item updateItem = dc.items.Where(i => i.iditem == model.iditem).FirstOrDefault();
                updateItem.done = Convert.ToSByte(model.value);
                dc.SaveChanges();

                items = dc.items.Include(m => m.userlogin).ToList();
            }
            // return new JsonResult {Data = items, JsonRequestBehavior = JsonRequestBehavior.AllowGet};
            return("{\"msg\":\"success\"}");
        }
Ejemplo n.º 5
0
        public ActionResult Index()
        {
            List <item> itemsList = null;

            using (var dc = new todo_listEntities())
            {
                ViewBag.name = User.Identity.Name;
                int id = getUserId();
                itemsList = dc.items.ToList().Where(m => m.userlogin.iduser == id).ToList();
                List <String> agoTimes = new List <string>();
                foreach (item item in itemsList)
                {
                    agoTimes.Add(TimeAgo(item.creationTime));
                }


                ViewBag.agotime = agoTimes;
            };
            return(View(itemsList));
        }
Ejemplo n.º 6
0
        public ActionResult Add(String description)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Login"));
            }

            var i = new item();

            i.description  = description;
            i.done         = 0;
            i.id_userlogin = getUserId();
            i.creationTime = DateTime.Now;
            using (var dc = new todo_listEntities())
            {
                dc.items.Add(i);
                dc.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }