public IActionResult Update(string id, SupermarketBrand supermarketBrand) { if (id != supermarketBrand.id) // Validate ids { return(BadRequest(new { message = "IDs don't match." })); } return(Ok(_supermarketBrandService.Update(supermarketBrand))); // Call the service }
public SupermarketBrand Create(SupermarketBrand supermarketBrand) { if (Read(supermarketBrand.id) != null) // Make sure this doesn't exist on the database yet { throw new AppException("A supermarket brand with id \"" + supermarketBrand.id + "\" is already registered."); } _supermarketBrands.InsertOne(supermarketBrand); // Call the service return(supermarketBrand); }
public IActionResult Create(SupermarketBrand supermarketBrand) { try { var superBrand = _supermarketBrandService.Create(supermarketBrand); return(Ok(superBrand)); } catch (AppException ex) { return(BadRequest(new { message = ex.Message })); } }
public SupermarketLocation Create(SupermarketLocation supermarketLocation) { if (checkDuplicate(supermarketLocation) != null) // Make sure this object doesn't exist yet { SupermarketBrand sm = _supermarketBrandService.Read(supermarketLocation.idSupermarketBrand); throw new AppException("A " + sm.name + " in \"" + supermarketLocation.location + "\" (or with the same coordinates) already exists."); } _supermarketLocations.InsertOne(supermarketLocation); // Insert object in the database return(supermarketLocation); }
// Update object in database public SupermarketBrand Update(SupermarketBrand supermarketBrand) { // Validate object in database var superBrand = Read(supermarketBrand.id); if (superBrand == null) { throw new AppException("Supermarket brand not found"); } // Update supermarket brand fields on the object that comes from the database, because it may contain more fields which we want to keep as is. superBrand.name = supermarketBrand.name; superBrand.logo = supermarketBrand.logo; _supermarketBrands.ReplaceOne(s => s.id == superBrand.id, superBrand); // Update supermarket brand on the database return(superBrand); }