Example #1
0
        public ActionResult CreateManager(string fullname)
        {
            var model = new HomeBackofficeViewModel();
            if (string.IsNullOrWhiteSpace(fullname))
            {
                model.Result = HomeBackofficeViewModel.OperationResult.Ko;
                model.OperationMessage = "Full name cannot be null";
                return View("Backoffice", model);
            }

            if (!this.IsValidManagerName(fullname))
            {
                model.Result = HomeBackofficeViewModel.OperationResult.Ko;
                model.OperationMessage = string.Format("Manager '{0}' already exists", fullname);
                return View("Backoffice", model);
            }

            try
            {
                var nameparts = fullname.Split(' ');
                var firstname = nameparts.Count() > 1 ? nameparts.First() : string.Empty;
                var surname = nameparts.Count() > 1 ? nameparts.Skip(1).First() : nameparts.First();

                this.Bus.Publish(new CreateManager(Guid.NewGuid(), firstname.Trim(), surname.Trim()));

                model.Result = HomeBackofficeViewModel.OperationResult.Ok;
                model.OperationMessage = string.Format("Manager '{0}' creation submitted.", fullname);
            }
            catch
            {
                model.Result = HomeBackofficeViewModel.OperationResult.Ko;
                model.OperationMessage = "Create manager cannot be submitted. Please, retry later.";
            }

            return View("Backoffice", model);
        }
Example #2
0
 public ActionResult Backoffice()
 {
     var model = new HomeBackofficeViewModel();
     this.ReadModel.GetManagers().ForEach(model.Managers.Add);
     return View(model);
 }