public void Execute(TransmissionDto request) { var trans = new Transmission(); if (Context.Transmissions.Any(t => t.Type.ToLower() == t.Type.ToLower())) { throw new EntityAlreadyExistsException("Transmission"); } trans.Type = request.Type; Context.Transmissions.Add(trans); Context.SaveChanges(); }
public MappingProfile() { ApplyMappingsFromAssembly(Assembly.GetExecutingAssembly()); CarDto.Mapping(this); CarDetailVm.Mapping(this); AccountDetailVm.Mapping(this); PhotoDto.Mapping(this); TransmissionDto.Mapping(this); CarTypeDto.Mapping(this); ColorDto.Mapping(this); CityDto.Mapping(this); LocationDto.Mapping(this); RentDto.Mapping(this); }
public void Execute(TransmissionDto request) { var trans = Context.Transmissions.Find(request.Id); if (trans == null) { throw new EntityNotFoundException("Transmission"); } if (Context.Transmissions.Any(t => t.Type.ToLower() == request.Type.ToLower())) { throw new EntityAlreadyExistsException("Transmission"); } trans.Type = request.Type; Context.SaveChanges(); }
public ActionResult Post([FromBody] TransmissionDto dto) { try { _add.Execute(dto); return(StatusCode(201)); } catch (EntityAlreadyExistsException e) { return(Conflict(e)); } catch (Exception e) { Console.WriteLine(e.Message); return(StatusCode(500)); } }
public ActionResult Put([FromBody] TransmissionDto dto) { try { _edit.Execute(dto); return(StatusCode(204)); } catch (EntityNotFoundException e) { return(NotFound(e.Message)); } catch (EntityAlreadyExistsException e) { return(Conflict(e)); } catch (Exception e) { Console.WriteLine(e.Message); return(Conflict(e.Message)); } }