コード例 #1
0
        public void Put(DictionaryItem dto)
        {
            if (string.IsNullOrWhiteSpace(dto.Id))
            {
                throw new("id cant be null");
            }
            var obj = Coll.Find(x => x.Id == dto.Id).SingleOrDefault();

            if (obj is null)
            {
                throw new("id is not correct");
            }
            if (obj.Type != dto.Type)
            {
                throw new("type cant be modified");
            }
            if (string.IsNullOrWhiteSpace(dto.K) || string.IsNullOrWhiteSpace(dto.V) || string.IsNullOrWhiteSpace(dto.Type))
            {
                throw new("k,v,type cant be null");
            }
            if (Coll.CountDocuments(x => x.Id != dto.Id && x.Type == dto.Type && (x.K == dto.K || x.V == dto.V)) > 0)
            {
                throw new("this item already exist");
            }
            obj.K     = dto.K;
            obj.V     = dto.V;
            obj.Order = dto.Order;
            obj.Desc  = dto.Desc;
            _         = Coll.ReplaceOne(x => x.Id == dto.Id, obj);
        }
コード例 #2
0
 public void Post(DictionaryItem dto)
 {
     if (string.IsNullOrWhiteSpace(dto.K) || string.IsNullOrWhiteSpace(dto.V) || string.IsNullOrWhiteSpace(dto.Type))
     {
         throw new("k,v,type cant be null");
     }
     if (Coll.CountDocuments(x => x.Type == dto.Type && (x.K == dto.K || x.V == dto.V)) > 0)
     {
         throw new("this item already exist");
     }
     Coll.InsertOne(dto);
 }