public async Task <int> AddEvent(EventAddingBindingModel model) { DanceType dance = DbContext .DanceTypes .FirstOrDefault(dt => dt.Name == model.Dance); if (model.Address == null) { model.Address = model.Place; } Event @event = new Event() { Name = model.Name, Dance = dance, Place = model.Place, Address = model.Address, PosterUrl = model.PosterUrl, StartDate = model.StartDate, EndDate = model.EndDate }; await this.DbContext.Events.AddAsync(@event); await this.DbContext.SaveChangesAsync(); return(@event.Id); }
public async Task AddEvent_WithCorrectFewEvent_ShouldAddProperly() { var firstEventModel = new EventAddingBindingModel() { Name = "First Event Testing Name", Place = "First Event Testing Place", Address = "First Event Testing Address", Dance = "Folklor", PosterUrl = "https://dveri.bg/cache/new5/6/1687d8c0fb11c8f4e2a1d603e65e6e1a.png", StartDate = DateTime.Now, EndDate = DateTime.Now.AddDays(2) }; var secondEventModel = new EventAddingBindingModel() { Name = "Second Event Testing Name", Place = "Second Event Testing Place", Address = "Second Event Testing Address", Dance = "Folklor", PosterUrl = "https://dveri.bg/cache/new5/6/1687d8c0fb11c8f4e2a1d603e65e6e1a.png", StartDate = DateTime.Now, EndDate = DateTime.Now.AddDays(2) }; await this.service.AddEvent(firstEventModel); await this.service.AddEvent(secondEventModel); Assert.AreEqual(2, this.context.Events.Count()); }
public async Task AddEvent_WithNullEvent_ShouldThrowException() { EventAddingBindingModel eventModel = null; await Assert.ThrowsExceptionAsync <InvalidOperationException>( () => this.service.AddEvent(eventModel)); }
public async Task AddEvent_WithCorrectEvent_ShouldWorkProperly() { const string name = "Event Testing Name"; const string place = "Event Testing Place"; const string address = "Event Testing Address"; var eventModel = new EventAddingBindingModel() { Name = "Event Testing Name", Place = "Event Testing Place", Address = "Event Testing Address", Dance = "Folklor", PosterUrl = "https://dveri.bg/cache/new5/6/1687d8c0fb11c8f4e2a1d603e65e6e1a.png", StartDate = DateTime.Now, EndDate = DateTime.Now.AddDays(2) }; await this.service.AddEvent(eventModel); var @event = this.context.Events.First(); Assert.AreEqual(name, @event.Name); Assert.AreEqual(place, @event.Place); Assert.AreEqual(address, @event.Address); }
public async Task <IActionResult> Add(EventAddingBindingModel model) { if (!ModelState.IsValid) { return(this.View()); } int id = await this.eventsService.AddEvent(model); return(RedirectToAction("Details", new { id })); }