Exemple #1
0
        public ActionResult DefinePlanYear(DefineYearForPlan command, FormCollection formCollection)
        {
            command.PlanYearId = Guid.NewGuid().ToString();

            try
            {
                var response = _commandSender.Send(command);
                if (response.CommandStatus == CommandStatusEnum.Failed)
                {
                    //set the error message in the ViewData and return to the view
                    ModelState.AddModelError("ResponseError", response.Message);
                    return(View(command));
                }

                return(RedirectToAction("Index"));
            }
            catch (TimeoutException toe)
            {
                ModelState.AddModelError("TimeOutError", toe.Message);
                return(View(command));
            }
            catch
            {
                return(View());
            }
        }
Exemple #2
0
        //
        //GET: /Plans/DefinePlanYear

        public ActionResult DefinePlanYear(string planId, string companyId)
        {
            //this command is going to be our model for the view
            //therefore, we can set some properties here and they will be available to the view
            //the planId and companyId came from the selected row in the list of plans view.
            var defineYearCommand = new DefineYearForPlan
            {
                PlanId    = planId,
                CompanyId = companyId,
            };

            return(View(defineYearCommand));
        }
Exemple #3
0
        public void DefineYearForPlan(DefineYearForPlan command)
        {
            //check that there is not already a plan year with the same dates as the incoming command
            if (_planState.PlanYears.Any(year => year.Year == command.Year))
            {
                throw new DomainException(string.Format("There is already a plan year defined for the year '{0}'", command.Year));
            }

            ApplyEvent(new NewPlanYearAssignedEvent
            {
                CompanyId  = command.CompanyId,
                Ends       = command.Ends,
                Name       = command.Name,
                PlanId     = command.PlanId,
                PlanYearId = command.PlanYearId,
                Starts     = command.Starts,
                Version    = 0,
                Year       = command.Year,
            }
                       , @event => _planState.Apply(@event));
        }