public ISportshallDto GetMostVisitedSportshall() { Sportshall sportshall = this.dbContext.Sportshalls?.Where(s => !s.IsDeleted) .OrderByDescending(c => c.Visits.Where(v => !v.IsDeleted).Count()) .FirstOrDefault(); Guard.WhenArgument(sportshall, "Most visited sportshall can not be null.").IsNull().Throw(); Guard.WhenArgument(sportshall.Visits.Where(v => !v.IsDeleted).Count(), "There no sportshall with visits.").IsLessThan(1).Throw(); ISportshallDto sportshallDto = this.mapper.Map <SportshallDto>(sportshall); Guard.WhenArgument(sportshallDto, "SportshallDto can not be null.").IsNull().Throw(); return(sportshallDto); }
public void AddSportshall(ISportshallDto sportshallDto) { Guard.WhenArgument(sportshallDto, "SportshallDto can not be null").IsNull().Throw(); var sportshallToAdd = this.mapper.Map <Sportshall>(sportshallDto); if (!this.dbContext.Sportshalls.Any(s => s.Name == sportshallDto.Name && !s.IsDeleted)) { this.dbContext.Sportshalls.Add(sportshallToAdd); this.dbContext.SaveChanges(); } else { throw new ArgumentException("A sporthall with the same name already exists!"); } }