Esempio n. 1
0
        public ActionResult Add(Task task)
        {
            if (String.IsNullOrEmpty(task.name))
                ModelState.AddModelError("Name", "Введите свое name");

            if (String.IsNullOrEmpty(task.text))
                ModelState.AddModelError("Text", "Введите свое text");

            if (ModelState.IsValid)
            {
                MyDBDataContext db = new MyDBDataContext();
                MyTable125 item = new MyTable125
                {
                    name = task.name,
                    text = task.text,
                    TaskAdded = DateTime.Now,
                    TaskBegin = task.TaskBegin,
                    TaskEnd = task.TaskEnd,
                    delete = false
                };

                //item.done = !flagDone;

                db.MyTable125.InsertOnSubmit(item);
                db.SubmitChanges();
                return RedirectPermanent("/Home/Index");
            }
            else
                // Обнаружена ошибка проверки достоверности
                return RedirectPermanent("/Home/Index");

            return RedirectPermanent("/Home/Index");
            //return View();
        }
        public ActionResult OnInput([Bind(Include = "name, text, TaskBegin, taskEnd")] Task task)
        {
            task.TaskAdded = DateTime.Now;
            //Валидация вводных данных
            if (ModelState.IsValid)
            {
                //Корректные

                MyDBDataContext db = new MyDBDataContext();
                MyTable125 item = new MyTable125
                {
                    name = task.name,
                    text = task.text,
                    TaskAdded = DateTime.Now,
                    TaskBegin = task.TaskBegin,
                    TaskEnd = task.TaskEnd,
                    delete = false
                };

                { }
                //item.done = !flagDone;

                db.MyTable125.InsertOnSubmit(item);
                db.SubmitChanges();

                ViewBag.Sussed = "Успешно добвлен!";

                //return RedirectToAction("Index", "Home");
                //return RedirectPermanent("~/Home/Index");
                //return RedirectPermanent("~/Add/Add");
                return View();
            }
            else
            {
                //Некорректные
                //return RedirectPermanent("~/Home/Index");
                return View("Input");
            }

            //return View();
        }