コード例 #1
0
        public async Task <ActionResult> AddCollege(College model)
        {
            ViewBag.college = "active";
            if (ModelState.IsValid)
            {
                if (!VerifyIfCollegeExist(model))
                {
                    try
                    {
                        model.Title = model.Title.ToUpper();
                        await _collegeService.CreateAsync(model);

                        TempData["success"] = "The college was successfully created";
                        return(RedirectToAction("colleges"));
                    }
                    catch (Exception ex)
                    {
                        ModelState.AddModelError("", ex.Message);
                    }
                }
                else
                {
                    TempData["error"] = string.Format("Either the College: {0} or Title: {1}, has already been added", model.Name, model.Title);
                }
            }
            return(View("AddCollege", model));
        }