Esempio n. 1
0
        public ActionResult Create(TaskModel model, int Subject)
        {
            try
            {

                using (ISession session = NHibernateHelper.OpenSession())
                {
                    SubjectModel subjectModel = session.Get<SubjectModel>(Subject);

                    model.Subject = subjectModel;

                    using (ITransaction transaction = session.BeginTransaction())
                    {
                        session.Save(model);
                        transaction.Commit();
                    }
                    return RedirectToAction("Index").WithMessage(Languages.Success, "alert-success", "glyphicon glyphicon-ok-sign");
                }

            }
            catch (ADOException)
            {
                ModelState.AddModelError("", Languages.InvalidModelState);
                return View();
            }
            catch (System.Exception)
            {
                return RedirectToAction("Index");
            }
        }
Esempio n. 2
0
        public ActionResult Edit(TaskModel Task, int Subject)
        {
            try
            {

                using (ISession session = NHibernateHelper.OpenSession())
                {
                    SubjectModel subject = session.Get<SubjectModel>(Subject);
                    TaskModel persistentModel = session.Get<TaskModel>(Task.Id);

                    persistentModel.Name = Task.Name;
                    persistentModel.Subject = subject;
                    persistentModel.Status = Task.Status;
                    persistentModel.Stage = Task.Stage;
                    persistentModel.DeadLine = Task.DeadLine;
                    persistentModel.Description = Task.Description;

                    using (ITransaction transaction = session.BeginTransaction())
                    {
                        session.Save(persistentModel);
                        transaction.Commit();
                    }
                    return RedirectToAction("Index").WithMessage(Languages.Success, "alert-success", "glyphicon glyphicon-ok-sign");
                }
            }
            catch (ADOException)
            {
                return RedirectToAction("Index").WithMessage(Languages.Error, "alert-danger", "glyphicon glyphicon-remove-sign");
            }
            catch (System.Exception)
            {
                return RedirectToAction("Index").WithMessage(Languages.Error, "alert-danger", "glyphicon glyphicon-remove-sign");
            }
        }