Пример #1
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);
            }
        }
Пример #2
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);
            }
        }
Пример #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
        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);
            }
        }
Пример #5
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();
            }
        }
Пример #6
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);
            }
        }