Ejemplo n.º 1
0
 public void Update(string id, SupermarketLocation supermarketLocation) // É necessário um utilizador estar logado para poder actualizar um producto
 {
     if (id == supermarketLocation.id)                                  // Validar ids
     {
         _supermarketLocationService.Update(supermarketLocation);       // Actualizar producto na base de dados
     }
 }
Ejemplo n.º 2
0
 public IActionResult Create(SupermarketLocation supermarketLocation)
 {
     try {
         return(Ok(_supermarketLocationService.Create(supermarketLocation)));
     } catch (AppException ex) {
         return(BadRequest(new { message = ex.Message }));
     }
 }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
0
        public void Update(SupermarketLocation supermarketLocation)
        {
            var super = Read(supermarketLocation.id);

            if (super == null)
            {
                throw new AppException("Supermarket not found");
            }

            // Update updatable supermarket brand fields on the object that comes from the database, because it may contain more (non-updatable) fields which we want to keep.
            super.idSupermarketBrand = supermarketLocation.idSupermarketBrand;
            super.location           = supermarketLocation.location;
            super.latitude           = supermarketLocation.latitude;
            super.longitude          = supermarketLocation.longitude;

            _supermarketLocations.ReplaceOne(s => s.id == s.id, super); // Update supermarket brand on the database
        }
Ejemplo n.º 5
0
 public SupermarketLocation checkDuplicate(SupermarketLocation supermarketLocation) =>
 _supermarketLocations.Find <SupermarketLocation>(superLoc => superLoc.idSupermarketBrand == supermarketLocation.idSupermarketBrand && (superLoc.location == supermarketLocation.location || (superLoc.latitude == supermarketLocation.latitude && superLoc.longitude == supermarketLocation.longitude))).FirstOrDefault();