示例#1
0
        public async Task <CityForReturnDto> Create(CityForCreationDto createDto)
        {
            var checkByName = await cityDal.GetAsync(x => x.Name.ToLower() == createDto.Name.ToLower());

            if (checkByName != null)
            {
                throw new RestException(HttpStatusCode.BadRequest, new { AlreadyExist = Messages.AlreadyExist });
            }

            var mapForCreate = mapper.Map <City>(createDto);
            var saveToDb     = await cityDal.Add(mapForCreate);

            var mapForReturn = mapper.Map <City, CityForReturnDto>(saveToDb);

            return(mapForReturn);
        }
 public async Task <City> GetById(int id)
 {
     return(await _cityDal.GetAsync(x => x.Id == id));
 }