Example #1
0
        public async Task UpdateVehiculeAsync(string currentUserId, string id, VehiculesUpdateModel toUpdate)
        {
            var vehicule = await GetVehiculeAsync(id);

            if (vehicule == null)
            {
                throw new Exception("The vehicule doesn't exist");
            }

            if (vehicule.SocietyId == id)
            {
                throw new UnauthorizedAccessException("Your are not the manager of this society");
            }

            var update = Builders <Vehicules> .Update
                         .Set(dbVehicule => dbVehicule.VehiculesNumber, toUpdate.VehiculesNumber)
                         .Set(dbVehicule => dbVehicule.HasTarpaulinVehicule, toUpdate.HasTarpaulinVehicule)
                         .Set(dbVehicule => dbVehicule.PTAC_TarpaulinVehicule, toUpdate.PTAC_TarpaulinVehicule)
                         .Set(dbVehicule => dbVehicule.HasHardWallVehicule, toUpdate.HasHardWallVehicule)
                         .Set(dbVehicule => dbVehicule.PTAC_HardWallVehicule, toUpdate.PTAC_HardWallVehicule)
                         .Set(dbVehicule => dbVehicule.CanTransportHorse, toUpdate.CanTransportHorse)
                         .Set(dbVehicule => dbVehicule.CanTransportVehicule, toUpdate.CanTransportVehicule)
                         .Set(dbVehicule => dbVehicule.TotalCapacity, toUpdate.TotalCapacity);

            await _vehicules.UpdateOneAsync(dbVehicule =>
                                            dbVehicule.Id == id,
                                            update
                                            );
        }
Example #2
0
        public async Task <IActionResult> UpdateVehicule(string id, [FromBody] VehiculesUpdateModel vehiculeUpdateModel)
        {
            var currentUserId = User.Identity.Name;

            try
            {
                await _vehiculesService.UpdateVehiculeAsync(currentUserId, id, vehiculeUpdateModel);

                return(Ok());
            }
            catch (UnauthorizedAccessException e)
            {
                return(Forbid($"Can't update the vehicule: {e.Message}"));
            }
            catch (Exception e)
            {
                return(BadRequest($"Can't update the vehicule: {e.Message}"));
            }
        }