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)); }
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); }
public async Task <ActionResult <VehicleBrandForReturnDto> > Update(VehicleBrandForCreationDto updateDto) { return(await vehicleBrandService.Update(updateDto)); }