Ejemplo n.º 1
0
        public void Dequeue(int letter_id)
        {
            db_mssql db_mssql = new db_mssql();

            Queued deque = (from m in db_mssql.Queueds where m.LetterID == letter_id && m.State == 0 select m).FirstOrDefault();
            if (deque != null)
            {

                db_mssql.Queueds.Attach(deque);
                var entry = db_mssql.Entry(deque);
                entry.Property(e => e.State).IsModified = true;
                deque.State = 1;

                db_mssql.SaveChanges();
            }
        }
Ejemplo n.º 2
0
        public Letter PublishQueue()
        {
            db_mssql db_mssql = new db_mssql();
            db_mysql db_mysql = new db_mysql();

            List<Queued> qry = (from m in db_mssql.Queueds where m.State == 0 orderby m.LetterID ascending select m).ToList();
            if (qry.Count() == 0)
            {
                return null;
            }

            Queued latest_unpublished_queued = qry.First();

            letter latest_front_page = (from l in db_mysql.letters where l.letterLevel == 1 orderby l.letterPostDate descending select l).First();
            letter lucky_letter = (from l in db_mysql.letters where l.Id == latest_unpublished_queued.LetterID select l).FirstOrDefault();

            if (lucky_letter == null)
            {
                return null;
            }

            db_mysql.letters.Attach(lucky_letter);
            var letter = db_mysql.Entry(lucky_letter);
            letter.Property(e => e.letterLevel).IsModified = true;
            lucky_letter.letterLevel = 1;

            db_mssql.Queueds.Attach(latest_unpublished_queued);
            var queued = db_mssql.Entry(latest_unpublished_queued);
            queued.Property(e => e.State).IsModified = true;
            latest_unpublished_queued.State = 1;

            db_mysql.SaveChanges();
            db_mssql.SaveChanges();

            edit new_edit = new edit();
            new_edit.editComment = "Published from queue.";
            new_edit.previousLetter = lucky_letter.letterMessage;
            new_edit.newLetter = lucky_letter.letterMessage;
            new_edit.editDate = DateTime.Now;
            new_edit.letterID = lucky_letter.Id;
            new_edit.status = "accepted";
            new_edit.editor = "auto post";
            db_mssql.edits.Add(new_edit);
            db_mssql.SaveChanges();

            return Mapper.Map<letter, Letter>(lucky_letter);
        }