Beispiel #1
0
        public static void EnsureBgExists(Discussion discussion)
        {
            if (discussion == null)
            {
                return;
            }

            if (discussion.Background == null)
            {
                discussion.Background = new RichText();
            }
        }
Beispiel #2
0
        public static int GetGeneralSide(Person p, Discussion d)
        {
            if (p == null || d == null)
            {
                return(-1);
            }

            var q = from genSide in PublicBoardCtx.Get().GeneralSide
                    where genSide.Discussion.Id == d.Id && genSide.Person.Id == p.Id
                    select genSide;

            if (q.Count() > 0)
            {
                return(q.First().Side);
            }
            else
            {
                return(-1);
            }
        }
Beispiel #3
0
        public static void SetGeneralSide(Person p, Discussion d, int side)
        {
            if (p == null || d == null)
            {
                return;
            }

            var q = from genSide in PublicBoardCtx.Get().GeneralSide
                    where genSide.Discussion.Id == d.Id && genSide.Person.Id == p.Id
                    select genSide;

            if (q.Count() > 0)
            {
                q.First().Side = side;
            }
            else
            {
                PublicBoardCtx.Get().AddToGeneralSide(Ctors.NewGenSide(p, d, side));
            }
        }
Beispiel #4
0
        public static void DeleteDiscussion(Discussion d)
        {
            if (!Ctors.DiscussionExists(d))
            {
                return;
            }

            var ctx = PublicBoardCtx.Get();

            //delete attachments
            var attachments = new List <Attachment>();

            foreach (var a in d.Attachment)
            {
                attachments.Add(a);
            }
            foreach (var a in attachments)
            {
                ctx.DeleteObject(a);
            }

            //delete background
            if (d.Background != null)
            {
                d.Background = null;
            }

            foreach (var t in d.Topic)
            {
                t.Person.Clear();
                t.ArgPoint.Clear();
            }
            d.Topic.Clear();

            d.GeneralSide.Clear();

            ctx.DeleteObject(d);

            ctx.SaveChanges();
        }
Beispiel #5
0
        private void Run(Discussion A, Discussion B)
        {
            if (A == null || B == null)
            {
                return;
            }

            Tuple <int, int, string> range = GetRange();

            if (range.Item3 != "")
            {
                return;
            }

            var ctx = PublicBoardCtx.Get();

            var moderator = ctx.Person.FirstOrDefault(p => p.Name == "moderator");

            if (moderator == null)
            {
                MessageDlg.Show("Cannot find moderator in DB");
                return;
            }

            for (int i = range.Item1; i <= range.Item2; i++)
            {
                var disc = cloneDiscussion(ctx, A, moderator, i);
                DaoUtils.SetGeneralSide(moderator, disc, (int)SideCode.Neutral);
                ctx.AddToDiscussion(disc);

                var disc2 = cloneDiscussion(ctx, B, moderator, i);
                DaoUtils.SetGeneralSide(moderator, disc2, (int)SideCode.Neutral);
                ctx.AddToDiscussion(disc2);
            }
            ctx.SaveChanges();

            MessageDlg.Show("Done");
        }
 private void lstBxDiscussions_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     SelectedDiscussion = e.AddedItems[0] as Discussion;
     Close();
 }
Beispiel #7
0
        //if given seat was not used in current session, and user takes the seat, new user is created in DB.
        //if user takes seat that was used in this session, then no new user is created. instead, the user
        //is recognized as the same user who took the seat in current session, though during second login user
        //enters name again (effectively changing name)
        private static Person RegisterOrLogin(string name, Discussion discussion, Session session, Seat seat)
        {
            //was the seat taken by some user?
            var sessionId = session.Id;
            var seatId    = seat.Id;

            DbCtx.DropContext();
            var outrunnerPerson =
                DbCtx.Get().Person.FirstOrDefault(p0 => p0.Session != null && p0.Session.Id == sessionId &&
                                                  p0.Seat != null && p0.Seat.Id == seatId);

            //the user already took the place, just change name
            if (outrunnerPerson != null)
            {
                outrunnerPerson.Name = name;

                //do we need general side ?
                var ctx             = DbCtx.Get();
                var previousGenSide = ctx.GeneralSide.FirstOrDefault(gs0 => gs0.Discussion.Id == discussion.Id &&
                                                                     gs0.Person.Id == outrunnerPerson.Id);
                if (previousGenSide == null)
                {
                    //the person takes part in this discussion first time, create general
                    //side of the person in this discussion
                    var disc = ctx.Discussion.FirstOrDefault(d0 => d0.Id == discussion.Id);
                    outrunnerPerson.GeneralSide.Add(
                        CreateGeneralSide(
                            outrunnerPerson,
                            disc,
                            (int)SideCode.Neutral
                            )
                        );

                    //assign person to all topics of selected discussion
                    foreach (var topic in disc.Topic)
                    {
                        outrunnerPerson.Topic.Add(topic);
                    }
                }

                DbCtx.Get().SaveChanges();

                return(outrunnerPerson);
            }
            else
            {
                //seat was not used in this session, create new user
                var ctx = DbCtx.Get();
                var p   = new Person();
                p.Name    = name;
                p.Session = ctx.Session.FirstOrDefault(s0 => s0.Id == session.Id);
                p.Seat    = ctx.Seat.FirstOrDefault(s0 => s0.Id == seat.Id);

                var disc = ctx.Discussion.FirstOrDefault(d0 => d0.Id == discussion.Id);
                p.GeneralSide.Add(CreateGeneralSide(p, disc, (int)SideCode.Neutral));

                //person inherits color of seat
                p.Color = p.Seat.Color;

                p.Email = "no-email";

                //assign person to all topics of selected discussion
                foreach (var topic in disc.Topic)
                {
                    p.Topic.Add(topic);
                }

                ctx.AddToPerson(p);
                DbCtx.Get().SaveChanges();
                return(p);
            }
        }
Beispiel #8
0
 public static IEnumerable <ArgPoint> ArgPointsOf(Person pers, Discussion d, Topic t)
 {
     return(pers.ArgPoint.Where(ap => ap.Topic != null && ap.Topic.Id == t.Id));
 }