コード例 #1
0
        public async Task <VehicleBrandForReturnDto> Update(VehicleBrandForCreationDto updateDto)
        {
            var checkById = await vehicleBrandDal.GetAsync(x => x.Id == updateDto.Id);

            if (checkById == null)
            {
                throw new RestException(HttpStatusCode.BadRequest, new { NotFound = Messages.NotFound });
            }

            var mapForUpdate = mapper.Map(updateDto, checkById);
            await vehicleBrandDal.Update(mapForUpdate);

            return(mapper.Map <VehicleBrand, VehicleBrandForReturnDto>(mapForUpdate));
        }
コード例 #2
0
        public async Task <VehicleBrandForReturnDto> Create(VehicleBrandForCreationDto createDto)
        {
            var checkByName = await vehicleBrandDal.GetAsync(x => x.BrandName.ToLower() == createDto.BrandName.ToLower());

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

            var mapForCreate = mapper.Map <VehicleBrand>(createDto);
            var saveToDb     = await vehicleBrandDal.Add(mapForCreate);

            var mapForReturn = mapper.Map <VehicleBrand, VehicleBrandForReturnDto>(saveToDb);

            return(mapForReturn);
        }
コード例 #3
0
 public async Task <ActionResult <VehicleBrandForReturnDto> > Update(VehicleBrandForCreationDto updateDto)
 {
     return(await vehicleBrandService.Update(updateDto));
 }