public BaseResponse Delete(int id) { var category = databaseContext.Categories.FirstOrDefault(c => c.Id == id); if(category == null) { return BaseResponse.CreateNotFoundResponse(id, translationProvider); } databaseContext.Categories.Remove(category); databaseContext.SaveChanges(); return BaseResponse.CreateOkResponse(translationProvider); }
public BaseResponse Delete(long id) { var product = databaseContext.Products.FirstOrDefault(c => c.Id == id); if (product == null) { return(BaseResponse.CreateNotFoundResponse(id, translationProvider)); } databaseContext.Products.Remove(product); databaseContext.SaveChanges(); return(BaseResponse.CreateOkResponse(translationProvider)); }
private BaseResponse SaveChangesInCategoryTree(CategoryNodeDto categoryDto) { Category category = Mapper.Map <Category>(categoryDto); Category categoryEntity = databaseContext.Categories.Where(cat => cat.Id == category.Id).FirstOrDefault(); if (categoryEntity == null) { return(BaseResponse.CreateNotFoundResponse(categoryDto.Id, translationProvider)); } foreach (CategoryNodeDto child in categoryDto.Children) { SaveChangesInCategoryTree(child); } databaseContext.Entry(categoryEntity).State = EntityState.Modified; databaseContext.Entry(categoryEntity).CurrentValues.SetValues(categoryDto); return(BaseResponse.CreateOkResponse(translationProvider)); }
public BaseResponse Put([FromBody] ProductDto productDto) { Product productEntity = databaseContext.Products.Where(prod => prod.Id == productDto.Id).FirstOrDefault(); if (productEntity == null) { return(BaseResponse.CreateNotFoundResponse(productDto.Id, translationProvider)); } var validateResponse = ValidateProductDto(productDto); if (!validateResponse.Success) { return(validateResponse); } databaseContext.Entry(productEntity).State = EntityState.Modified; databaseContext.Entry(productEntity).CurrentValues.SetValues(productDto); databaseContext.SaveChanges(); return(BaseResponse.CreateOkResponse(translationProvider)); }