Example #1
0
        public string Update(Profile profile)
        {
            SsdsContainer c1 = DbContext.OpenContainer("Profile");
            var           p  = c1.Single <Profile>(c => c.Entity.OpenId == profile.OpenId &&
                                                   c.Entity.IdType == profile.IdType
                                                   );

            if (p == null)
            {
                profile.LogOnTime    = DateTime.Now;
                profile.RegisterTime = DateTime.Now;
                profile.Role         = "User";
                profile.Id           = Guid.NewGuid().ToString();
                c1.Insert(new SsdsEntity <Profile>
                {
                    Id     = profile.Id,
                    Kind   = "Profile",
                    Entity = profile,
                });
                return(profile.Id);
            }
            var newp = p.Entity;

            newp.Name = profile.Name;
            //if (profile.Name == "Öصä")
            //    newp.Role = "Admin";
            newp.NickName      = profile.NickName;
            newp.School        = profile.School;
            newp.SchoolDetails = profile.SchoolDetails;
            newp.Sex           = profile.Sex;
            c1.Update(newp, p.Id, ConcurrencyPattern.IfNoneMatch);
            return(p.Id);
        }
Example #2
0
        public static void Insert(this SsdsContainer source, IEnumerable <SsdsBlobEntity> entities, Func <SsdsBlobEntity, Exception, bool> onError)
        {
            object concurrency = new object();

            Parallel.ForEach <SsdsBlobEntity>(entities, delegate(SsdsBlobEntity entity, ParallelState ps)
            {
                try
                {
                    source.Insert(entity);
                }
                catch (Exception ex)
                {
                    lock (concurrency)
                    {
                        if (!ps.IsStopped)
                        {
                            if (onError != null)
                            {
                                if (!onError(entity, ex))
                                {
                                    ps.Stop();
                                }
                            }
                        }
                    }
                }
            });
        }
Example #3
0
        public void Add(Group group)
        {
            SsdsContainer c1 = DbContext.OpenContainer("Group");

            group.BeginTime = DateTime.Now;
            group.EndTime   = DateTime.Now;
            group.Id        = Guid.NewGuid().ToString();
            c1.Insert(group, group.Id);
        }
Example #4
0
        public void Add(Wiki wiki)
        {
            SsdsContainer c1 = DbContext.OpenContainer("Wiki");

            wiki.Id = Guid.NewGuid().ToString();
            c1.Insert <Wiki>(new SsdsEntity <Wiki>
            {
                Id     = wiki.Id,
                Entity = wiki
            });
        }
Example #5
0
        public void Add(Question question)
        {
            SsdsContainer c1 = DbContext.OpenContainer("Question");
            var           id = Guid.NewGuid().ToString();

            question.Id = id;
            c1.Insert <Question>(new SsdsEntity <Question>
            {
                Id     = id,
                Entity = question
            });
        }
Example #6
0
        public void SaveAnswer(Answer answer)
        {
            //answer
            SsdsContainer c1 = DbContext.OpenContainer("Answer");

            c1.Insert(answer, answer.Id);

            var count = c1.Query <Answer>(
                c => c.Entity.QuestionId == answer.QuestionId &&
                c.Entity.Status == (int)AnswerType.Accepted &&
                c.Entity.UserId == answer.UserId &&
                c.Id != answer.Id
                ).Count();
            //question
            var answerType = (AnswerType)answer.Status;
            var c2         = DbContext.OpenContainer("Question");
            var q          = c2.Single <Question>(
                c => c.Id == answer.QuestionId
                );

            if (q != null)
            {
                q.Entity.SubmitCount++;
                if (answerType == AnswerType.Accepted && count == 0)
                {
                    q.Entity.AcceptedCount++;
                }
                c2.Update(q);
            }
            //user
            var c3 = DbContext.OpenContainer("Profile");

            var p = c3.Single <Profile>(c => c.Id == answer.UserId);

            if (p != null)
            {
                p.Entity.Submit++;
                if (answerType == AnswerType.Accepted && count == 0)
                {
                    p.Entity.Accepted++;
                }
                c3.Update(p);
            }
        }