public async Task <EventDetailsServiceModel> GetByIdAsync(int id) { CoreValidator.ThrowIfInvalidIntegerProvided(id, nameof(id)); return(await this.dbContext.Events .Where(e => e.Id == id && e.IsDeleted == false) .ProjectTo <EventDetailsServiceModel>() .AsNoTracking() .FirstOrDefaultAsync()); }
public async Task <IReadOnlyCollection <EventListsServiceModel> > GetAllAsync(int page = 1, int pageSize = 8) { CoreValidator.ThrowIfInvalidIntegerProvided(page, nameof(page)); CoreValidator.ThrowIfInvalidIntegerProvided(pageSize, nameof(pageSize)); return(await this.dbContext.Events .Where(e => e.IsDeleted == false) .OrderByDescending(e => e.StartDate) .Skip((page - 1) * pageSize) .Take(pageSize) .ProjectTo <EventListsServiceModel>() .AsNoTracking() .ToListAsync()); }
public async Task DeleteAsync(int id) { CoreValidator.ThrowIfInvalidIntegerProvided(id, nameof(id)); var existingEvent = await this.dbContext.Events.FindAsync(id); if (existingEvent == null) { throw new InvalidOperationException(string.Format(ServiceConstants.UnexistingEvent, id)); } existingEvent.IsDeleted = true; this.dbContext.Events.Update(existingEvent); await this.dbContext.SaveChangesAsync(); }
public async Task <IActionResult> Delete(int id, string eventTitle) { CoreValidator.ThrowIfInvalidIntegerProvided(id, nameof(id)); try { await this.eventService.DeleteAsync(id); } catch (InvalidOperationException ex) { this.TempData.AddErrorMessage(ex.Message); return(this.RedirectToAction(nameof(Index))); } catch (Exception ex) { this.TempData.AddErrorMessage(ex.Message); return(this.RedirectToAction(nameof(Index))); } this.TempData.AddSuccessMessage(string.Format(WebConstants.SuccessfullyDeletedEvent, eventTitle)); return(this.RedirectToAction(nameof(Index))); }