示例#1
0
        public ActionResult Create(Task taskModel)
        {
            try
            {
                // TODO: Add insert logic here
                if (ModelState.IsValid)
                {
                    if (DateTime.Compare(taskModel.date_plan, DateTime.Today) >= 0)
                    {
                        var db = new DatabaseDataContext();
                        var task = new Task();
                        var userCon = db.Users.SingleOrDefault(u => u.user_id == user);

                        task.header = taskModel.header;
                        task.text = taskModel.text;
                        task.date_plan = taskModel.date_plan;
                        task.user = user;
                        task.done = false;

                        task.User1 = userCon;
                        db.Tasks.InsertOnSubmit(task);
                        db.SubmitChanges();

                        return RedirectToAction("Index", new { id = task.user, done = false });
                    }else
                        ModelState.AddModelError("", "Date must be more than today");
                }
                return View(taskModel);
            }
            catch
            {
                return View(taskModel);
            }
        }
示例#2
0
        public ActionResult Create(User userModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (userModel.password == userModel.conformPassword)
                    {
                        var db = new DatabaseDataContext();
                        var user=db.Users.FirstOrDefault(u=>u.email==userModel.email);
                        if (user == null)
                        {
                            user = new User();
                            user.name = userModel.name;
                            user.email = userModel.email;
                            user.password = userModel.password;

                            db.Users.InsertOnSubmit(user);
                            db.SubmitChanges();
                            return RedirectToAction("LogOn");

                        }else ModelState.AddModelError("", "User with this email already exist");
                    }else ModelState.AddModelError("","Passwords must be match");
                }
                return View(userModel);
            }
            catch
            {
                return View(userModel);
            }
        }
示例#3
0
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
                var db = new DatabaseDataContext();
                var user = db.Users.Single(u=>u.user_id==id);

                if (Request["Yes"] != null)
                {
                    db.Users.DeleteOnSubmit(user);
                    db.SubmitChanges();
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
示例#4
0
        //
        // GET: /User/Details/5
        public ActionResult Details(int id)
        {
            var db = new DatabaseDataContext();
            var user = db.Users.SingleOrDefault(u =>u.user_id == id);

            ViewData.Model = user;
            return View();
        }
示例#5
0
        public ActionResult ReminderPassword(User userModel)
        {
            ModelState.Remove("name");
            ModelState.Remove("conformPassword");
            ModelState.Remove("password");

            if (ModelState.IsValid)
            {
                var db = new DatabaseDataContext();
                var user = db.Users.FirstOrDefault(u => u.email == userModel.email);

                if (user != null)
                {
                    System.Net.Mail.MailMessage Message = new System.Net.Mail.MailMessage();
                    Message.Subject = "Reminder password";
                    Message.Body = "Hello "+user.name+ "! Your password for ToDo : \n"+user.password;
                    Message.BodyEncoding = System.Text.Encoding.ASCII;
                    Message.From=new MailAddress("*****@*****.**");
                    Message.To.Add(new MailAddress(user.email));
                    System.Net.Mail.SmtpClient Smtp = new SmtpClient("smtp.mail.ru");
                    Smtp.EnableSsl = true;
                    Smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "fktnerg3z7");
                    Smtp.Send(Message);

                    return RedirectToAction("LogOn");
                }
                else
                {
                    ModelState.AddModelError("", "This email does not exist");
                }
            }

            return View(userModel);
        }
示例#6
0
        public ActionResult LogOn(User userModel)
        {
            ModelState.Remove("name");
            ModelState.Remove("conformPassword");
            ModelState.Remove("password");

            if (ModelState.IsValid)
            {
                var db = new DatabaseDataContext();
                var user = db.Users.FirstOrDefault(u=>u.email==userModel.email);

                if (user!=null && user.password==userModel.password)
                {
                    FormsAuthentication.RedirectFromLoginPage(user.name, userModel.remember);
                    return RedirectToAction("Index", "Task", new {id= user.user_id,done=false});
                }
                else
                {
                    ModelState.AddModelError("", "Login and/or password are incorrect");
                }
            }

            return View(userModel);
        }
示例#7
0
        public ActionResult Edit(int id, User userModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    // TODO: Add update logic here
                    var db = new DatabaseDataContext();
                    var user = db.Users.SingleOrDefault(u => u.user_id == id);

                    user.name = userModel.name;
                    user.email = userModel.email;
                    user.password = userModel.password;

                    db.SubmitChanges();
                    return RedirectToAction("Index");
                }

                return View(userModel);
            }
            catch
            {
                return View(userModel);
            }
        }
示例#8
0
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
                var db = new DatabaseDataContext();
                var task = db.Tasks.SingleOrDefault(t => t.task_id == id);

                if (this.Request["Yes"]!=null)
                {
                    db.Tasks.DeleteOnSubmit(task);
                    db.SubmitChanges();
                }

                return RedirectToAction("Index", new { id = task.user,done=task.done });
            }
            catch
            {
                return View();
            }
        }
示例#9
0
 public ActionResult Index(int id,bool done)
 {
     var db = new DatabaseDataContext();
     if (id == 0)
     {
         var taskList = db.Tasks.Where(t => t.user == user).Where(b=>b.done==done).OrderBy(p=>p.date_plan);
         ViewData.Model = taskList;
     }
     else
     {
         var taskList = db.Tasks.Where(t => t.user == user).Where(b => b.done == done).OrderBy(p => p.date_plan);
         user = id;
         ViewData.Model = taskList;
     }
     if (done==true) return View("Archive");
     return View();
 }
示例#10
0
        public ActionResult Edit(int id, Task taskModel)
        {
            try
            {
                // TODO: Add update logic here
                if (ModelState.IsValid)
                {
                    var db = new DatabaseDataContext();
                    var task = db.Tasks.SingleOrDefault(t => t.task_id == id);

                    task.header = taskModel.header;
                    task.text = taskModel.text;
                    task.date_plan = taskModel.date_plan;
                    task.done = taskModel.done;

                    db.SubmitChanges();

                    return RedirectToAction("Index", new { id = task.user,done=task.done});
                }

                return View(taskModel);
            }
            catch
            {
                return View(taskModel);
            }
        }
示例#11
0
        public ActionResult Edit(int id)
        {
            var db = new DatabaseDataContext();
            var task = db.Tasks.SingleOrDefault(t => t.task_id == id);

            ViewData.Model = task;
            return View();
        }