示例#1
0
        // GET: Administration/Offices/Create
        public ActionResult Create()
        {
            NewOfficeViewModel           model    = new NewOfficeViewModel();
            IEnumerable <SelectListItem> managers = this.GetManagers();

            model.Managers = managers;
            return(View(model));
        }
示例#2
0
        public ActionResult Create(NewOfficeViewModel model)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser manager = this.data.Users.Find(model.ManagerId);
                if (manager == null)
                {
                    this.TempData["ErrorMessage"] = "Invalid manager";
                    this.RedirectToAction("Index");
                }

                Office office = new Office();
                Mapper.Map(model, office);
                this.data.Offices.Add(office);
                this.data.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }