public async Task<IActionResult> CreateAsync(RaidCreateBindingModel inputModel) { if (ModelState.IsValid == false) { return RedirectToAction(nameof(Create)); } await this.raidService.CreateAsync(inputModel); return RedirectToAction("Upcoming", "Events"); }
public async Task CreateAsync_Should_Throw_If_Not_Valid_InputData(string destination, string leaderId) { var context = await this.GetDatabase(); var mapper = this.GetMapper(); var characterService = new CharacterService(context, mapper); var raidService = new RaidService(context, characterService, mapper); var raidCreateBindingModel = new RaidCreateBindingModel { DateTime = DateTime.Now, Destination = destination, LeaderId = leaderId }; await Assert.ThrowsAsync <ArgumentException>(async() => await raidService.CreateAsync(raidCreateBindingModel)); }
public async Task CreateAsync_Should_Create_And_Push_Raid_In_Database() { var context = await this.GetDatabase(); var mapper = this.GetMapper(); var characterService = new CharacterService(context, mapper); var raidService = new RaidService(context, characterService, mapper); var raidCreateBindingModel = new RaidCreateBindingModel { DateTime = DateTime.Now, Description = "TestDescr", Destination = "TestRaid1", LeaderId = "1" }; await raidService.CreateAsync(raidCreateBindingModel); var expected = 2; var actual = context.Raids.Count(); Assert.Equal(expected, actual); }
public async Task <Raid> CreateAsync(RaidCreateBindingModel createModel) { var destinationId = this.GetDestinationId(createModel.Destination); var raid = new Raid { EventDateTime = createModel.DateTime, Description = createModel.Description, DestinationId = destinationId, LeaderId = createModel.LeaderId, }; raid.RegisteredCharacters.Add(new RaidCharacter { CharacterId = createModel.LeaderId, RaidId = raid.Id }); await this.context.Raids.AddAsync(raid); await this.context.SaveChangesAsync(); return(raid); }