예제 #1
0
        protected override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            using (var session = MvcApplication.Store.OpenSession())
            {
                var contextAccount = ContextAccountProvider.GetContextAccount(session);

                ViewBag.CurrentAccount = contextAccount;

                ViewBag.Accounts = session.Query <Account>().ToList();

                ViewBag.AbilityToCreateTask = RolesThatHaveTheAbilityToCreateTasks.GetForRole(contextAccount.Role);
            }
            base.OnActionExecuted(filterContext);
        }
        public ActionResult Create(TaskModel model)
        {
            try
            {
                using (var session = MvcApplication.Store.OpenSession())
                {
                    var contextAccount = ContextAccountProvider.GetContextAccount(session);

                    var task = new Task(model.Title, model.Content, model.Source, DateTime.Parse(model.Deadline, null, DateTimeStyles.RoundtripKind), RolesThatHaveTheAbilityToCreateTasks.GetStateForCreateTask(contextAccount.Role));

                    task.AddСomment(new Log("Задача создана", contextAccount));

                    if (!string.IsNullOrWhiteSpace(model.AdditionalСomment))
                    {
                        task.AddСomment(new Comment(model.AdditionalСomment, contextAccount));
                    }

                    session.Store(task);
                    session.SaveChanges();
                    return(RedirectToAction("List", new { notification = string.Format("Задача \"{0}\" создана!", model.Title) }));
                }
            }
            catch (Exception ex)
            {
                return(View("Error", ex));
            }
        }