public async Task <IActionResult> UpdateModel(int id, [FromBody] KeyValuePairResource modelResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var model = await modelRepository.GetModel(id); if (model == null) { return(NotFound()); } mapper.Map <KeyValuePairResource, Model>(modelResource, model); modelRepository.Update(model); await unitOfWork.CompleteAsync(); model = await modelRepository.GetModel(model.Id); var result = mapper.Map <Model, KeyValuePairResource>(model); return(Ok(result)); }
public async Task <IActionResult> UpdateFeatureAsync(int id, [FromBody] FeatureResource feature) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { Feature domainFeature = await _repository.GetAsync(id); if (domainFeature == null) { return(BadRequest($"Feature with id = {id} does not exist!")); } _mapper.Map(feature, domainFeature); domainFeature.Id = id; await _unitOfWork.CompeleteAsync(); Feature found = await _repository.GetAsync(id); KeyValuePairResource result = _mapper.Map <Feature, KeyValuePairResource>(found); return(Ok(result)); } catch (Exception e) { return(StatusCode(500, e.InnerException?.Message ?? e.Message)); } }
public async Task <IActionResult> CreateStorage([FromBody] KeyValuePairResource KeyValuePairResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var storage = mapper.Map <KeyValuePairResource, Storage>(KeyValuePairResource); context.Storages.Add(storage); await context.SaveChangesAsync(); var result = mapper.Map <Storage, KeyValuePairResource>(storage); return(Ok(result)); }
public async Task <IActionResult> CreateCoolingFan([FromBody] KeyValuePairResource KeyValuePairResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var coolingFan = mapper.Map <KeyValuePairResource, Coolingfan>(KeyValuePairResource); context.CoolingFans.Add(coolingFan); await context.SaveChangesAsync(); var result = mapper.Map <Coolingfan, KeyValuePairResource>(coolingFan); return(Ok(result)); }
public async Task <IActionResult> CreateGpu([FromBody] KeyValuePairResource KeyValuePairResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var gpu = mapper.Map <KeyValuePairResource, GPU>(KeyValuePairResource); context.GPUs.Add(gpu); await context.SaveChangesAsync(); var result = mapper.Map <GPU, KeyValuePairResource>(gpu); return(Ok(result)); }
public async Task <IActionResult> CreateMotherboard([FromBody] KeyValuePairResource KeyValuePairResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var motherboard = mapper.Map <KeyValuePairResource, Motherboard>(KeyValuePairResource); context.Motherboards.Add(motherboard); await context.SaveChangesAsync(); var result = mapper.Map <Motherboard, KeyValuePairResource>(motherboard); return(Ok(result)); }
public async Task <IActionResult> CreateCase([FromBody] KeyValuePairResource KeyValuePairResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var caseObject = mapper.Map <KeyValuePairResource, Case>(KeyValuePairResource); context.Cases.Add(caseObject); await context.SaveChangesAsync(); var result = mapper.Map <Case, KeyValuePairResource>(caseObject); return(Ok(result)); }
public async Task <IActionResult> CreateRam([FromBody] KeyValuePairResource KeyValuePairResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var ram = mapper.Map <KeyValuePairResource, RAM> (KeyValuePairResource); context.RAMs.Add(ram); await context.SaveChangesAsync(); var result = mapper.Map <RAM, KeyValuePairResource>(ram); return(Ok(result)); }
public async Task <IActionResult> CreatePowersupply([FromBody] KeyValuePairResource KeyValuePairResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var powerSupply = mapper.Map <KeyValuePairResource, Powersupply>(KeyValuePairResource); context.PowerSupplys.Add(powerSupply); await context.SaveChangesAsync(); var result = mapper.Map <Powersupply, KeyValuePairResource>(powerSupply); return(Ok(result)); }
public async Task <IActionResult> PostMaterial([FromBody] KeyValuePairResource materialResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var material = mapper.Map <KeyValuePairResource, Material>(materialResource); if (material == null) { return(BadRequest("Bad Material")); } materialRepository.AddMaterial(material); await unitOfWork.CompleteAsync(); return(Ok(mapper.Map <Material, KeyValuePairResource>(material))); }
public async Task <IActionResult> Post([FromBody] KeyValuePairResource genreResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var genre = mapper.Map <KeyValuePairResource, Genre>(genreResource); await genreRepository.Add(genre); await unitOfWork.CompleteAsync(); genre = await genreRepository.Get(genre.Id, includeRelated : false); var result = mapper.Map <Genre, KeyValuePairResource>(genre); return(Ok(result)); }
public async Task <IActionResult> Post([FromBody] KeyValuePairResource platformResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var platform = mapper.Map <KeyValuePairResource, Platform>(platformResource); await platformRepository.Add(platform); await unitOfWork.CompleteAsync(); platform = await platformRepository.Get(platform.Id, includeRelated : false); var result = mapper.Map <Platform, KeyValuePairResource>(platform); return(Ok(result)); }
public async Task <IActionResult> update(int id, [FromBody] KeyValuePairResource makeResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var make = await context.Makes.FindAsync(id); if (make == null) { return(NotFound()); } make.Name = makeResource.Name; context.Entry(make).State = EntityState.Modified; await context.SaveChangesAsync(); return(Ok(make)); }
public async Task <IActionResult> CreateFeatures([FromBody] KeyValuePairResource featureResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var feature = mapper.Map <KeyValuePairResource, Feature>(featureResource); featureRepository.Add(feature); await unitOfWork.CompleteAsync(); feature = await featureRepository.GetFeature(feature.Id); var result = mapper.Map <Feature, KeyValuePairResource>(feature); return(Ok(result)); }
public async Task <IActionResult> UpdateCase(int id, [FromBody] KeyValuePairResource KeyValuePairResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var caseObject = await context.Cases.FindAsync(id); if (caseObject == null) { return(NotFound()); } mapper.Map <KeyValuePairResource, Case>(KeyValuePairResource, caseObject); await context.SaveChangesAsync(); var result = mapper.Map <Case, KeyValuePairResource>(caseObject); return(Ok(result)); }
public async Task <IActionResult> UpdateRam(int id, [FromBody] KeyValuePairResource KeyValuePairResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var ram = await context.RAMs.FindAsync(id); if (ram == null) { return(NotFound()); } mapper.Map <KeyValuePairResource, RAM> (KeyValuePairResource, ram); await context.SaveChangesAsync(); var result = mapper.Map <RAM, KeyValuePairResource>(ram); return(Ok(result)); }
public async Task <IActionResult> UpdateMotherboard(int id, [FromBody] KeyValuePairResource KeyValuePairResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var motherboard = await context.Motherboards.FindAsync(id); if (motherboard == null) { return(NotFound()); } mapper.Map <KeyValuePairResource, Motherboard>(KeyValuePairResource, motherboard); await context.SaveChangesAsync(); var result = mapper.Map <Motherboard, KeyValuePairResource>(motherboard); return(Ok(result)); }
public async Task <IActionResult> UpdateCoolingFan(int id, [FromBody] KeyValuePairResource KeyValuePairResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var coolingFan = await context.CoolingFans.FindAsync(id); if (coolingFan == null) { return(NotFound()); } mapper.Map <KeyValuePairResource, Coolingfan>(KeyValuePairResource, coolingFan); await context.SaveChangesAsync(); var result = mapper.Map <Coolingfan, KeyValuePairResource>(coolingFan); return(Ok(result)); }
public async Task <IActionResult> UpdateGpu(int id, [FromBody] KeyValuePairResource KeyValuePairResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var gpu = await context.GPUs.FindAsync(id); if (gpu == null) { return(NotFound()); } mapper.Map <KeyValuePairResource, GPU>(KeyValuePairResource, gpu); await context.SaveChangesAsync(); var result = mapper.Map <GPU, KeyValuePairResource>(gpu); return(Ok(result)); }
public async Task <IActionResult> UpdateStorage(int id, [FromBody] KeyValuePairResource KeyValuePairResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var storage = await context.Storages.FindAsync(id); if (storage == null) { return(NotFound()); } mapper.Map <KeyValuePairResource, Storage>(KeyValuePairResource, storage); await context.SaveChangesAsync(); var result = mapper.Map <Storage, KeyValuePairResource>(storage); return(Ok(result)); }
public async Task <IActionResult> UpdatePowerSupply(int id, [FromBody] KeyValuePairResource KeyValuePairResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var powerSupply = await context.PowerSupplys.FindAsync(id); if (powerSupply == null) { return(NotFound()); } mapper.Map <KeyValuePairResource, Powersupply>(KeyValuePairResource, powerSupply); await context.SaveChangesAsync(); var result = mapper.Map <Powersupply, KeyValuePairResource>(powerSupply); return(Ok(result)); }
public async Task <IActionResult> CreateFeatureAsync([FromBody] FeatureResource feature) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { Feature domainFeature = _mapper.Map <FeatureResource, Feature>(feature); await _repository.CreateAsync(domainFeature); await _unitOfWork.CompeleteAsync(); int id = domainFeature.Id; Feature found = await _repository.GetAsync(id); KeyValuePairResource result = _mapper.Map <Feature, KeyValuePairResource>(found); return(Ok(result)); } catch (Exception e) { return(StatusCode(500, e.InnerException?.Message ?? e.Message)); } }
public async Task <IActionResult> Put(int id, [FromBody] KeyValuePairResource genreResource) { var genreInDb = await genreRepository.Get(id, includeRelated : false); if (genreInDb == null) { return(NotFound()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } mapper.Map(genreResource, genreInDb); await unitOfWork.CompleteAsync(); await genreRepository.Get(genreInDb.Id, includeRelated : false); var result = mapper.Map <Genre, KeyValuePairResource>(genreInDb); return(Ok(result)); }