Пример #1
0
        public IHttpActionResult DeleteRaceClassification(int?id)
        {
            if (!id.HasValue)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            var raceClassificationDB = raceClassificationRepository.GetRaceClassification(id ?? (int)InvalidPropertyValues.undefinedValue);

            if (raceClassificationDB == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            var races = raceRepository.GetRacesForClassifications(raceClassificationDB.RaceClassificationID);

            if (races.Any())
            {
                return(BadRequest("The Race Classification is used by a Race!\nTo delete it contact your Database Manager."));
            }

            raceClassificationRepository.Remove(raceClassificationDB);
            unitOfWork.Complete();

            return(Ok());
        }