public async Task <Space> Create(Space spaceIn)
        {
            var ressourceTypeIn = await _ressourceTypeRepository.GetById(spaceIn.SpaceTypeId);

            if (ressourceTypeIn == null)
            {
                throw new RessourceTypeRepositoryException(string.Format(_errorHandler.GetMessage(ErrorMessagesEnum.NotFound),
                                                                         nameof(RessourceType), spaceIn.SpaceTypeId), nameof(spaceIn.SpaceTypeId));
            }
            try
            {
                ressourceTypeIn.Count++; // Increamenting count when adding an asset
                await _ressourceTypeRepository.Update(ressourceTypeIn);

                spaceIn.SpaceTypeName = ressourceTypeIn.Name;
                await _spaceRepository.Add(spaceIn);
            }
            catch (MongoWriteException mwx)
            {
                if (mwx.WriteError.Category == ServerErrorCategory.DuplicateKey)
                {
                    var     pattern         = @"\{(?:[^{*}])*\}";
                    Match   result          = Regex.Match(mwx.Message, pattern);                     // get the dublicated feild from the string error msg
                    JObject duplicatedField = JsonConvert.DeserializeObject <JObject>(result.Value); // parse it  to get the field
                    throw new SpaceRepositoryException(string.Format(_errorHandler.GetMessage(ErrorMessagesEnum.DuplicateKey),
                                                                     nameof(Space), duplicatedField.First.Path), duplicatedField.First.Path);
                }
            }
            return(spaceIn);
        }
 public async Task <RessourceType> Update(RessourceType ressourceTypeIn)
 {
     try
     {
         await _ressourceTypeRepository.Update(ressourceTypeIn);
     }
     catch (MongoWriteException mwx)
     {
         if (mwx.WriteError.Category == ServerErrorCategory.DuplicateKey)
         {
             var     pattern         = @"\{(?:[^{*}])*\}";
             Match   result          = Regex.Match(mwx.Message, pattern);                     // get the dublicated feild from the string error msg
             JObject duplicatedField = JsonConvert.DeserializeObject <JObject>(result.Value); // parse it  to get the field
             throw new RessourceTypeRepositoryException(string.Format(_errorHandler.GetMessage(ErrorMessagesEnum.DuplicateKey),
                                                                      nameof(RessourceType), duplicatedField.First.Path), duplicatedField.First.Path);
         }
     }
     return(ressourceTypeIn);
 }