Ejemplo n.º 1
0
        public static CBB.ExceptionHelper.OperationResult DeleteRelation(RelationMember obj)
        {
            try
            {
                MongoDatabase md = MongoDBHelper.MongoDB;
                MongoCollection<RelationMember> mc = md.GetCollection<RelationMember>(obj.GetCollectionName());
                IMongoQuery qc = Query.And(Query.EQ("FromMember", obj.FromMember), Query.EQ("ToMember", obj.ToMember));
                mc.Remove(qc);

                return new CBB.ExceptionHelper.OperationResult(true);
            }
            catch (System.Exception err)
            {
                throw new CBB.ExceptionHelper.OperationException(
                    CBB.ExceptionHelper.ErrType.SystemErr,
                    CBB.ExceptionHelper.ErrNo.DBOperationError,
                    err);
            }
        }
Ejemplo n.º 2
0
        public static CBB.ExceptionHelper.OperationResult UpdateFavorerVisitCount(RelationMember obj)
        {
            try
            {
                MongoDatabase md = MongoDBHelper.MongoDB;
                MongoCollection<RelationMember> mc = md.GetCollection<RelationMember>(obj.GetCollectionName());
                IMongoQuery qc = Query.And(Query.EQ("FromMember", obj.FromMember), Query.EQ("ToMember", obj.ToMember));
                IMongoUpdate ud = Update.Combine(
                    Update.Inc("VisitCount", 1)
                    );
                mc.Update(qc, ud, UpdateFlags.Upsert);

                return new CBB.ExceptionHelper.OperationResult(true);
            }
            catch (System.Exception err)
            {
                throw new CBB.ExceptionHelper.OperationException(
                    CBB.ExceptionHelper.ErrType.SystemErr,
                    CBB.ExceptionHelper.ErrNo.DBOperationError,
                    err);
            }
        }
Ejemplo n.º 3
0
        public static CBB.ExceptionHelper.OperationResult AddRelation(RelationMember obj,RelationOperationType t)
        {
            try
            {
                MongoDatabase md = MongoDBHelper.MongoDB;
                MongoCollection<RelationMember> mc = md.GetCollection<RelationMember>(obj.GetCollectionName());
                if (t == RelationOperationType.OnlyOneTimes && mc.Count(Query.And(Query.EQ("FromMember", obj.FromMember), Query.EQ("ToMember", obj.ToMember))) > 0)
                {
                    return new CBB.ExceptionHelper.OperationResult(false, "OverrideOneTimes");
                }
                if (t == RelationOperationType.OneOperationEachHour && mc.Count(Query.And(Query.EQ("FromMember", obj.FromMember), Query.EQ("ToMember", obj.ToMember), Query.GT("CreatedTime", DateTime.Now.AddHours(-1)))) > 0)
                {
                    return new CBB.ExceptionHelper.OperationResult(false, "OverrideOneTimesThisHour");
                }
                if (t == RelationOperationType.OneOperationEachDay && mc.Count(Query.And(Query.EQ("FromMember", obj.FromMember), Query.EQ("ToMember", obj.ToMember), Query.GT("CreatedTime", DateTime.Now.AddDays(-1)))) > 0)
                {
                    return new CBB.ExceptionHelper.OperationResult(false, "OverrideOneTimesThisDay");
                }
                mc.Save(obj);
                return new CBB.ExceptionHelper.OperationResult(true);

            }
            catch (System.Exception err)
            {
                throw new CBB.ExceptionHelper.OperationException(
                    CBB.ExceptionHelper.ErrType.SystemErr,
                    CBB.ExceptionHelper.ErrNo.DBOperationError,
                    err);
            }
        }