public async Task <ActionResult <HomebannerDto> > PutHomebanner([FromRoute] int id, [FromBody] HomebannerDto homebannerDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != homebannerDto.ID) { return(BadRequest()); } Homebanner homebanner = DtoToEntityIMapper.Map <HomebannerDto, Homebanner>(homebannerDto); repository.ModifyEntryState(homebanner, EntityState.Modified); try { await uoW.SaveAsync(); } catch (DbUpdateConcurrencyException) { if (!HomebannerExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IHttpActionResult> GetHomebanner(int id) { Homebanner item = await UoW.GetRepository <Homebanner>().GetItemAsycn(e => e.ID == id); if (item == null) { return(NotFound()); } var DTO = EntityToDtoIMapper.Map <Homebanner, HomebannerDto>(item); return(Ok(DTO)); }
public async Task <IHttpActionResult> DeleteHomebanner(int id) { Homebanner homebanner = await UoW.GetRepository <Homebanner>().GetItemAsycn(e => e.ID == id); if (homebanner == null) { return(NotFound()); } UoW.GetRepository <Homebanner>().Delete(homebanner); await UoW.SaveAsync(); return(Ok(homebanner)); }
public async Task <ActionResult <HomebannerDto> > PostHomebanner([FromBody] HomebannerDto homebannerDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Homebanner homebanner = DtoToEntityIMapper.Map <HomebannerDto, Homebanner>(homebannerDto); repository.Add(homebanner); await uoW.SaveAsync(); return(CreatedAtAction("GetHomebanner", new { id = homebanner.ID }, homebannerDto)); }
public async Task <ActionResult <HomebannerDto> > DeleteHomebanner([FromRoute] int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Homebanner homebanner = await repository.GetAsync(a => a.ID == id); if (homebanner == null) { return(NotFound()); } repository.Delete(homebanner); await uoW.SaveAsync(); HomebannerDto homebannerDto = EntityToDtoIMapper.Map <Homebanner, HomebannerDto>(homebanner); return(Ok(homebannerDto)); }