public ApartmentTenantDto Update(ApartmentTenantDto tenant) { ApartmentTenant tenantToUpdate = Get(tenant.Id); _dbContext.Entry(tenantToUpdate).CurrentValues.SetValues(_mapper.Map <ApartmentTenant>(tenant)); _dbContext.SaveChanges(); return(_mapper.Map <ApartmentTenantDto>(tenantToUpdate)); }
public ApartmentTenantDto Add(ApartmentTenantDto item) { ApartmentTenant tenant = _mapper.Map <ApartmentTenant>(item); _dbContext.ApartmentTenant.Add(tenant); _dbContext.SaveChanges(); return(GetDto(tenant.Id)); }
public IActionResult Single(int id) { ApartmentTenantDto apartment = _apartmentTenantRepository.GetDto(id); if (apartment == null) { return(NotFound()); } return(Ok(apartment)); }
public IActionResult Remove(int id) { ApartmentTenantDto apartment = _apartmentTenantRepository.GetDto(id); if (apartment == null) { return(NotFound()); } _apartmentTenantRepository.Delete(id); return(NoContent()); }
public IActionResult Add([FromBody] ApartmentTenantDto apartment) { if (apartment == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } ApartmentTenantDto apartmentAdded = _apartmentTenantRepository.Add(apartment); return(Ok(apartmentAdded)); }
public IActionResult Update(int id, [FromBody] ApartmentTenantDto apartment) { var apartmentToCheck = _apartmentTenantRepository.Get(id); if (apartmentToCheck == null) { return(NotFound()); } if (id != apartment.Id) { return(BadRequest("Ids do not match")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } ApartmentTenantDto updatedapartment = _apartmentTenantRepository.Update(apartment); return(Ok(updatedapartment)); }