Exemplo n.º 1
0
        public IUserSnap GetUserSnap(string ticket, LoginType type)
        {
            var passport = MongoEntity.Get <Passport>(p => p.SecurityKey == ticket);

            if (passport == null)
            {
                return(null);
            }
            var profile = MongoEntity.Get <Profile>(p => p.SecurityKey == ticket);

            if (profile == null)
            {
                return(null);
            }
            IUserSnap snap = new UserSnap()
            {
                Id             = profile.Id,
                SecurityKey    = profile.SecurityKey,
                Name           = profile.Name,
                Account        = profile.Account,
                LoginCode      = passport.GetLoginCode(type),
                LoginType      = type,
                Email          = profile.Email,
                RegisteredTime = profile.BsonObjectId.CreationTime
            };

            Log(snap.Name + " do GetUserSnap");
            return(snap);
            //return new UserInfo(profile.Id, profile.Account, profile.Name, profile.Email, (profile.Native == null ? "" : string.Format("{0}{1}{2}", profile.Region.Name, profile.Nationality.Name, profile.Native.Name)), DateTime.Now, profile.SecurityKey);
        }
Exemplo n.º 2
0
        public void TestEntityList()
        {
            School school = new School()
            {
                Name = "WinStudio"
            };

            List <Department> depts = new List <Department>()
            {
                new Department()
                {
                    Name = "Master"
                },
                new Department()
                {
                    Name = "Admin"
                }
            };

            foreach (Department dept in depts)
            {
                school.Departments.Add(dept);
            }

            foreach (Student student in students)
            {
                school.Students.Add(student);
            }
            school.Save();

            School sch = MongoEntity.Get <School>(school.Id);

            Console.WriteLine(sch.Name);
        }
Exemplo n.º 3
0
        public ComRet Login(string account, string password, ClientType client, string client_sn)
        {
            var passport = MongoEntity.Get <Passport>(p => p.Account == account && p.Password == password);

            if (passport == null)
            {
                return(Result(false, "账户名不正确"));
            }

            Profile profile = MongoEntity.Get <Profile>(p => p.Account == account);

            if (profile == null)
            {
                return(Result(false, "账户不合法"));
            }

            profile.Client   = client;
            profile.ClientSN = client_sn;
            profile.Save();

            passport.Ticket = BusinessAuthentication.GenTicket(profile);
            passport.Save();

            return(Result(true, passport.Ticket));
        }
Exemplo n.º 4
0
 public void InitModel(string id)
 {
     if (IsModelReady)
     {
         return;
     }
     _dto_T = MongoEntity.Get <T>(id);
 }
Exemplo n.º 5
0
        public ComRet GetProfile(string id)
        {
            var profile = MongoEntity.Get <Profile>(id);

            if (profile == null)
            {
                return(Result("不存在的用户"));
            }
            Log("GetProfile");
            return(Result(profile));
        }
        public void TestUpdate()
        {
            Student student2 = grade.Pick <Student>(students[2].Id);

            student2.Age = 100;
            grade.Update();

            var g = MongoEntity.Get <Grade>(grade.Id);

            Assert.AreEqual(student2.Age, g.Pick <Student>(student2.Id).Age);
        }
Exemplo n.º 7
0
        public ComRet UpdateInfo(string ticket, string telphone)
        {
            var passport = MongoEntity.Get <Passport>(p => p.Ticket == ticket);

            if (passport == null)
            {
                return(Result(false, "账户不存在"));
            }
            var profile = MongoEntity.Get <Profile>(p => p.Account == passport.Account);

            profile.Telphone = telphone;
            profile.Save();
            return(Result(true));
        }
Exemplo n.º 8
0
        public void TestSave()
        {
            Student student = new Student();

            student.Name = "hyf";
            student.Age  = 30;
            student.Save();
            MongoEntity.Save <Student>(students);
            var stud = MongoEntity.Get <Student>(student.Id);

            MongoEntity.Get <Student>(s => s.Name == "hyf" && s.Age > 33);
            Assert.AreEqual(student.Name, stud.Name);
            Assert.AreEqual(student.Age, stud.Age);
        }
Exemplo n.º 9
0
        public ComRet UpdateInfo(string ticket, string name, Gender gender)
        {
            var passport = MongoEntity.Get <Passport>(p => p.Ticket == ticket);

            if (passport == null)
            {
                return(Result(false, "账户不存在"));
            }
            var profile = MongoEntity.Get <Profile>(p => p.Account == passport.Account);

            profile.Name   = name;
            profile.Gender = gender;
            profile.Save();
            return(Result(true));
        }
Exemplo n.º 10
0
        public void TestAdd()
        {
            grade.Update();

            students[0].Name = "NameChanged";
            students[0].Save();

            var g = MongoEntity.Get <Grade>(grade.Id);

            Assert.AreSame(students[0].Name, grade.Pick <Student>(students[0].Id).Name);
            Assert.AreNotSame(grade.Pick <Student>(students[0].Id).Name, g.Pick <Student>(students[0].Id).Name);
            Assert.AreEqual(grade.Count <Student>(), g.Count <Student>());
            Assert.AreEqual(grade.Count <Teacher>(), g.Count <Teacher>());

            Assert.AreEqual(g.Count <Student>(), MongoEntity.Select <Student>(s => s.Age > 0).Count());
        }
Exemplo n.º 11
0
        public void TestTypeTest()
        {
            TypeTest tt = new TypeTest();

            tt.Name  = "TypeTester";
            tt.Bytes = Encoding.UTF8.GetBytes(tt.Name);
            tt.Save();

            var dbtt = MongoEntity.Get <TypeTest>(tt.Id);

            string b64 = Convert.ToBase64String(tt.Bytes);

            Assert.AreEqual(tt.Name, dbtt.Name);
            Assert.AreEqual(tt.Bytes.Length, dbtt.Bytes.Length);
            Assert.AreEqual(tt.Bytes, dbtt.Bytes);
        }
Exemplo n.º 12
0
        public ComRet CheckIn(string account, string password, LoginType type, string code)
        {
            var pp = MongoEntity.Get <Passport>(p => p.Account == account);

            if (pp == null)
            {
                return(Result("用户名不正确"));
            }
            if (pp.Password != password)
            {
                return(Result("密码不正确"));
            }
            if (type == LoginType.Web && pp.WebCode != code)
            {
                pp.WebCode = code;
                pp.Save();
            }
            else if (type != LoginType.Web && pp.ClientCode != code)
            {
                pp.ClientCode = code;
                pp.Save();
            }
            return(Result(true, pp.SecurityKey));
        }
Exemplo n.º 13
0
 public void InitDto(string id)
 {
     Tdto = MongoEntity.Get <T>(id);
 }
Exemplo n.º 14
0
 public DboModel(string id)
 {
     _dto_T = MongoEntity.Get <T>(id);
 }
Exemplo n.º 15
0
 public virtual T Get(Expression <Func <T, bool> > where)
 {
     return(MongoEntity.Get <T>(where));
 }
Exemplo n.º 16
0
 public virtual T Get(string id)
 {
     return(MongoEntity.Get <T>(id));
 }