public async Task <IActionResult> Create(CreateSchoolInputModel input) { if (!this.ModelState.IsValid) { return(View(input)); } if (!this.schoolService.IsSchoolNameAvailable(input.Name)) { this.ModelState.AddModelError("School name", "School name is already in use"); return(View(input)); } var school = new School() { Name = input.Name, ImageUrl = input.ImageUrl, }; await this.schoolService.CreateAsync(school); var user = await this.userManager.GetUserAsync(this.User); await this.schoolService.AssignUserToSchool(user, school.Id); return(RedirectToAction("Forum")); }
public void Create_ValidInputModel_ReturnsCreatedSchool() { var school = new School() { ManagerId = "aaaa", OfficeAddress = "asdfg", TradeMark = "testy", Phone = "222222" }; this.repository.Setup(r => r.AddAsync(school)).Returns(Task.FromResult(school)); var model = new CreateSchoolInputModel() { ManagerId = "aaaa", OfficeAddress = "asdfg", TradeMark = "testy", Phone = "222222" }; var result = this.schoolService.Create(model); Assert.That(result.Id, Is.EqualTo(0)); Assert.That(result.TradeMark, Is.EqualTo("testy")); Assert.That(result, Is.TypeOf <School>()); }
public School Create(CreateSchoolInputModel model) { var school = Mapper.Map <School>(model); this.schoolRepository.AddAsync(school).GetAwaiter().GetResult(); this.schoolRepository.SaveChangesAsync().GetAwaiter().GetResult(); return(school); }
public IActionResult Create(CreateSchoolInputModel model) { if (!this.ModelState.IsValid) { return(this.View(model)); } var schoolId = this.schoolService.Create(model).Id; //set user role this.accountService.SetRole("School", model.ManagerId); //todo decide where to redirect return(this.RedirectToAction("Details", "ManageSchools", schoolId)); }
public IActionResult Create(CreateSchoolInputModel model) { try { if (!this.ModelState.IsValid) { return(this.View(model)); } var schoolId = this.schoolService.Create(model).Id; this.accountService.SetRole("School", model.ManagerId); //todo decide where to redirect return(this.RedirectToAction("Manage", "Schools", new { Area = "SchoolManage" })); } catch (Exception e) { return(this.View("_Error", e.Message)); } }