public void TestCreateOrganisationView() { OrganisationViewModel organisation = new OrganisationViewModel() { Name = "Maarten's Songs" }; RedirectToRouteResult viewResult = (RedirectToRouteResult) _organisationsController.Create(organisation, null); Organisation createdOrganisation = _organisationManager.ReadOrganisation("Maarten's Songs"); Assert.AreEqual("Details/" + createdOrganisation.Id, viewResult.RouteValues["action"]); }
public ActionResult Create(OrganisationViewModel organisation, HttpPostedFileBase bannerImage) { try { string bannerPath = null; if (User != null) { user = userManager.ReadUser(User.Identity.Name); } var organisationNameAlreadyInUse = organisationManager.ReadOrganisation(organisation.Name); if (organisationNameAlreadyInUse != null) { ModelState.AddModelError("Name", "The name value is already in use"); return View(organisation); } if (String.IsNullOrWhiteSpace(organisation.Name)) { ModelState.AddModelError("Name", "The name value can not be empty"); return View(organisation); } if (bannerImage != null && bannerImage.ContentLength > 0) { var bannerFileName = Path.GetFileName(bannerImage.FileName); bannerPath = FileHelper.NextAvailableFilename(Path.Combine(Server.MapPath(ConfigurationManager.AppSettings["OrganisationsImgPath"]), bannerFileName)); bannerImage.SaveAs(bannerPath); bannerPath = Path.GetFileName(bannerPath); } Organisation org = organisationManager.CreateOrganisation(organisation.Name, bannerPath, user); return RedirectToAction("Details/" + org.Id); } catch { return RedirectToAction("Create"); } }