Example #1
0
 public IActionResult Creative(Poem poem, string id)
 {
     try
     {
         string res  = null;
         int    code = 200;
         //string id = Request.Query["id"];
         if (!string.IsNullOrEmpty(id))
         {
             poem.PoemID = Guid.Parse(id);
             code        = 201;
         }
         if (ModelState.IsValid)
         {
             poem.Auther   = HttpContext.Session.GetString("UserName");
             poem.AutherID = Guid.Parse(HttpContext.Session.GetString("UserID"));
             res           = IPoemService.SavePoem(poem);
         }
         if (res == "success")
         {
             return(Json(new { code, msg = "发布成功" }));
         }
     }
     catch (Exception ex)
     {
         Tools.InsertPLog("保存诗歌失败", ex.ToString(), "", Request);
     }
     return(Json(new { code = 400, msg = "发布失败" }));
 }
Example #2
0
        public Poem TrackPoem(int numberToAdd)
        {
            Poem poem  = new Poem();
            int  count = Data.Poems.Count() + 1;

            string newID = count.ToString();

            for (int x = 0; x < newID.Length; x++)
            {
                numberToAdd *= 10;
            }
            count      += numberToAdd;
            poem.PoemId = count;
            while (Data.Poems.Find(poem.PoemId) != null)
            {
                poem.PoemId = poem.PoemId * 10;
            }
            Data.Database.OpenConnection();
            try
            {
                Data.Add(poem);
                Data.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Poems ON");

                Data.SaveChanges();
                Data.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Poems OFF");
            }
            finally
            {
                Data.Database.CloseConnection();
            }
            return(poem);
        }
        public IActionResult PutVote(int id, string author, int vote)
        {
            Poem poem = _poemRepository.GetById(id);

            if (vote == 0)
            {
                if (!poem.DownVoters.Contains(author))
                {
                    poem.AddDownvote();
                    poem.DownVoters.Add(author);
                    if (poem.UpVoters.Contains(author))
                    {
                        poem.RemoveUpvote();
                        poem.UpVoters.Remove(author);
                    }
                }
            }
            else
            {
                if (!poem.UpVoters.Contains(author))
                {
                    poem.AddUpvote();
                    poem.UpVoters.Add(author);
                    if (poem.DownVoters.Contains(author))
                    {
                        poem.RemoveDownvote();
                        poem.DownVoters.Remove(author);
                    }
                }
            }
            _poemRepository.Update(poem);
            _poemRepository.SaveChanges();
            return(NoContent());
        }
Example #4
0
        /// <summary> The start of the normal poem-view process
        /// Shows the first line and some help text below it</summary>
        /// <param name="poem"></param>
        public void StartLoadPoem(Poem poem)
        {
            LoadTitleLine(poem);

            if (poem.IsEmpty)
            {
                // Remove clickability from Title line
                ((StackLayout.Children[0]) as ExtendedLabel).tapAction = null;
                // Set status
                Status = PoemViewerStatus.CompletePoem;
            }
            else
            {
                // Load help lines
                // Note that we don't increment DisplayedChunkIndex, because this isn't poem we're displaying, it's help text
                ExtendedLabel nextLineTap_HelpLabel = GetFormattedLabel(ChunkType.HelpText);
                nextLineTap_HelpLabel.Text = PoemViewerHelpText.NextLineTap_Help;
                StackLayout.Children.Add(nextLineTap_HelpLabel);
                nextLineTap_HelpLabel.tapAction = () => ShowNextChunk(poem, DisplayedChunkIndex, Status);

                ExtendedLabel TitleTap_HelpLabel = GetFormattedLabel(ChunkType.HelpText);
                TitleTap_HelpLabel.Text = PoemViewerHelpText.TitleTap_Help;
                StackLayout.Children.Add(TitleTap_HelpLabel);
                TitleTap_HelpLabel.tapAction = () => LoadWholePoem(poem);

                ExtendedLabel PreviousLineTap_HelpLabel = GetFormattedLabel(ChunkType.HelpText);
                PreviousLineTap_HelpLabel.Text = PoemViewerHelpText.PreviousLineTap_Help;
                StackLayout.Children.Add(PreviousLineTap_HelpLabel);

                // and define what we're doing
                Status = PoemViewerStatus.LineOnePlushelp;
            }
        }
        public ActionResult Create(Poem poem)
        {
            if (ModelState.IsValid)
            {
                poem.PoemTypeId = poem.PoemType.Id;
                poem.PoemType   = db.PoemType.Find(poem.PoemType.Id);
                poem.AuthorId   = User.Identity.GetUserId();
                var attachment = db.File.Where(f => f.URL.Contains(poem.VoiceURL)).FirstOrDefault();
                if (attachment != null)
                {
                    poem.VoiceURL = attachment.URL;
                }
                else
                {
                    poem.VoiceURL = null;
                }
                db.Poem.Add(poem);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.AuthorId  = new SelectList(db.Users, "Id", "UserName", poem.AuthorId);
            ViewBag.PoemTypes = new SelectList(db.PoemType, "Id", "Type");
            return(View(poem));
        }
Example #6
0
        public IActionResult Become([FromRoute] Guid guid, [FromForm] PoemModel poem)
        {
            Contract.Assert(poem != null);
            if (ModelState.IsValid)
            {
                var participant = new Participant()
                {
                    CompetitionGuid = guid,
                    UserGuid        = HttpContext.Session.Get <User>("user").Guid
                };
                database.Participants.Add(participant);

                var poemRecord = new Poem()
                {
                    ParticipantGuid = participant.Guid,
                    Text            = poem.Text,
                    Title           = poem.Title
                };
                database.Poems.Add(poemRecord);
                database.SaveChangesAsync();
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                ModelState.AddModelError("", "Неверные данные");
                return(View());
            }
        }
        public ActionResult Edit(Poem poem)
        {
            var roles  = db.Users.Find(User.Identity.GetUserId()).Roles.ToList();
            var dbPoem = db.Poem.Find(poem.Id);

            if (roles.Select(r => r.Role.Name).Contains("Administrator") || dbPoem.AuthorId == User.Identity.GetUserId())
            {
                //if (ModelState.IsValid)
                try
                {
                    dbPoem.Body            = poem.Body;
                    dbPoem.Name            = poem.Name;
                    dbPoem.Tags            = poem.Tags;
                    dbPoem.Poet            = poem.Poet;
                    db.Entry(dbPoem).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    return(View(db.Poem.Find(poem.Id)));
                }
            }
            ViewBag.AuthorId  = new SelectList(db.Users, "Id", "UserName", poem.AuthorId);
            ViewBag.PoemTypes = new SelectList(db.PoemType, "Id", "Type");
            return(View());
        }
Example #8
0
        public void RemovePoem(int selectedPoemId)
        {
            Poem selectedPoem = FindPoemById(selectedPoemId);

            Context.Poetry.Remove(selectedPoem);
            Context.SaveChanges();
        }
 /// <summary>
 /// 新增或保存诗歌
 /// </summary>
 /// <param name="poem"></param>
 /// <returns>success or fail</returns>
 public string SavePoem(Poem poem)
 {
     try
     {
         using (PoemDbContext db = new PoemDbContext())
         {
             if (poem.PoemID == Guid.Parse("00000000-0000-0000-0000-000000000000"))//无id传进来,是新增
             {
                 poem.PoemID = Guid.NewGuid();
                 db.Poem.Add(poem);
             }
             else//保存
             {
                 var p = db.Poem.Find(poem.PoemID);
                 p.Title   = poem.Title;
                 p.Content = poem.Content;
             }
             int res = db.SaveChanges();
             return(res > 0 ? "success" : "fail");
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Example #10
0
        //首页
        public IActionResult Index()
        {
            ViewModel vm = new ViewModel();

            try
            {
                vm.Msg    = Request.Query["msg"];
                vm.UserID = HttpContext.Session.GetString("UserID");
                //每日诗歌
                Poem   poem = new Poem();
                string url  = "http://www.zgshige.com";
                string html = IPoemService.NetRequest(url);
                string Sel1 = IPoemService.RegexCat(html, "<a title=\".{4}\" target=\"_blank\" href=\"http://www.zgshige.com/c/.*.shtml\">.{4}</a>");
                //匹配标题
                string title = IPoemService.RegexCat(Sel1, ">.*</a>");
                poem.Title = title.Substring(1, title.Length - 5);
                //内容
                url  = IPoemService.RegexCat(Sel1, "http://www.zgshige.com/c/.*.shtml");
                html = IPoemService.NetRequest(url);
                string con = IPoemService.RegexCat(html, "<div class=\"m-lg font14\"><p>.*</p></div>");
                poem.Content = con.Substring(33, (con.Length - 53)).Replace("<br/>", "###***");
                vm.Poem      = poem;
            }
            catch (Exception ex)
            {
                Tools.InsertPLog("进入首页失败", ex.ToString(), "", Request);
            }
            return(View(vm));
        }
Example #11
0
 public RevisionBuilder(Poem p)
 {
     _poem = p;
     if (_poem != null)
     {
         _poemName = _poem.Name;
     }
 }
        public void Replace()
        {
            Poem = Poem.Replace(",", ",\n");
            Poem = Poem.Replace(".", ".\n");
            Poem = Poem.Replace(":", ":\n");

            Console.WriteLine(Poem);
        }
        public ActionResult <Poem> DeletePoem(int id)
        {
            Poem poem = _poemRepository.GetById(id);

            _poemRepository.Delete(poem);
            _poemRepository.SaveChanges();
            return(poem);
        }
Example #14
0
        private HttpClient CreateClientAndTestData(Poem poem)
        {
            var client = _appFactory.CreateAuthorizedClient();

            _appFactory.DbContext.Add(poem);
            _appFactory.DbContext.SaveChanges();

            return(client);
        }
        public string GenerateContent(Poem poem)
        {
            var html = "<h1>" + poem.Title + "</h1>";

            html += "<pre><p>" + poem.Content + "</p></pre>";
            html += "<h2 class=\'poet-name\'>" + poem.PoetName + "</h3>";

            return(html);
        }
Example #16
0
        public Poem ToEntity()
        {
            var entity = new Poem();

            entity.Name             = Name;
            entity.Notes            = Notes;
            entity.ConceivedDateUTC = ConceivedDateLocal.ToUniversalTime();
            return(entity);
        }
        public Poem GetNextPoem(Poem poem, bool forward)
        {
            {
                PoemCollection coll = null;

                if (poem.ParentBlockPart != null)
                {
                    coll = poem.ParentBlockPart.Poems;
                }
                else
                {
                    coll = poem.ParentBlock.Poems;
                }

                int indexLine = coll.IndexOf(poem);
                if (indexLine != -1)
                {
                    int nextIndex = indexLine + (forward ? 1 : -1);

                    if (0 <= nextIndex && nextIndex < coll.Count)
                    {
                        return(coll[nextIndex]);
                    }
                }
            }

            if (poem.ParentBlockPart != null)
            {
                SABlockPart nextBlockPart = GetNextBlockPart(poem.ParentBlockPart, forward);

                if (nextBlockPart != null)
                {
                    if (forward)
                    {
                        return(nextBlockPart.GetFirstPoem());
                    }
                    else
                    {
                        return(nextBlockPart.GetLastPoem());
                    }
                }
            }

            {
                SABlock nextBlock = GetNextBlock(poem.ParentBlock, forward);

                if (forward)
                {
                    return(nextBlock.GetFirstPoem());
                }
                else
                {
                    return(nextBlock.GetLastPoem());
                }
            }
        }
 public IActionResult PutPoem(int id, Poem poem)
 {
     if (id != poem.Id)
     {
         return(BadRequest());
     }
     _poemRepository.Update(poem);
     _poemRepository.SaveChanges();
     return(NoContent());
 }
Example #19
0
        public void Post(Poem poem)
        {
            var vowelCount = CalculateVovelCount(poem.Text);

            _rabbitBusControl.Publish <СonsonantMessage>(new
            {
                TaskId     = poem.TaskId,
                Text       = poem.Text,
                VowelCount = vowelCount,
            });
        }
Example #20
0
        public async Task <IActionResult> Delete(int id)
        {
            Poem poem = _appDbContext.Poems.FirstOrDefault(p => p.Id == id);

            if (poem != null && CurrentPoet().Id == poem.Poet.Id)
            {
                _appDbContext.Poems.Remove(poem);
                await _appDbContext.SaveChangesAsync();
            }
            return(Ok(poem));
        }
        public void Replace2()
        {
            var split = Poem.Split(',');

            Poem  = string.Join(",\n", split);
            split = Poem.Split('.');
            Poem  = string.Join(".\n", split);
            split = Poem.Split(':');
            Poem  = string.Join(":\n", split);
            Console.WriteLine(Poem);
        }
        public Poem GetPoem(int id)
        {
            Poem poem = Data.Poems.Where(p => p.PoemId == id).FirstOrDefault();

            if (poem == null)
            {
                return(null);
            }
            poem.Themes = Data.PoemThemes.Where(w => w.PoemId == id).ToList();
            return(poem);
        }
Example #23
0
        private void PoemColor(On.Celeste.Poem.orig_ctor orig, Poem self, string text, int heartindex, float heartalpha)
        {
            orig(self, text, heartindex, heartalpha);

            var settings = this.InRandomizerSettings;

            if (heartindex == 3 || settings == null)
            {
                return;
            }

            Color  color     = Color.White;
            string guiSprite = "";

            switch (settings.Difficulty)
            {
            case Difficulty.Easy:
                color     = Calc.HexToColor("20c020");
                guiSprite = "heartgem0";
                break;

            case Difficulty.Normal:
                color     = Calc.HexToColor("8cc7fa");
                guiSprite = "heartgem0";
                break;

            case Difficulty.Hard:
                color     = Calc.HexToColor("ff668a");
                guiSprite = "heartgem1";
                break;

            case Difficulty.Expert:
                color     = Calc.HexToColor("fffc24");
                guiSprite = "heartgem2";
                break;

            case Difficulty.Master:
                color     = Calc.HexToColor("ff5024");
                guiSprite = "Randomizer_HeartMaster";
                break;

            case Difficulty.Perfect:
                color     = Calc.HexToColor("9B3FB5");
                guiSprite = "Randomizer_HeartPerfect";
                break;
            }

            typeof(Poem).GetProperty("Color").SetValue(self, color);

            self.Heart = GFX.GuiSpriteBank.Create(guiSprite);
            self.Heart.Play("spin");
            self.Heart.Position = new Vector2(1920f, 1080f) * 0.5f;
            self.Heart.Color    = Color.White * heartalpha;
        }
Example #24
0
        public void MakeSureICanGetPoemByTitle()
        {
            //Arrange
            PoemRepository repo = new PoemRepository(mock_context.Object);

            //Act
            string title      = "Lovely Day";
            Poem   found_poem = repo.FindPoemByTitle(title);

            //Assert
            Assert.AreEqual(found_poem.Title, title);
        }
Example #25
0
        public void MakeSureICanGetPoemByID()
        {
            //Arrange
            PoemRepository repo = new PoemRepository(mock_context.Object);

            //Act
            int  myId         = 102;
            Poem found_poetry = repo.FindPoemById(myId);

            List <Poem> my_poetry = repo.GetPoems();

            Assert.IsTrue(my_poetry.Contains(found_poetry));
        }
Example #26
0
        private void tSMIRandomPoemPart_Click(object sender, EventArgs e)
        {
            if (clickedNode != null && clickedNode.Tag != null && clickedNode.Tag is Poem)
            {
                Poem poem = (Poem)clickedNode.Tag;

                if (poem.Parts.Count > 0)
                {
                    Engine.controller.GetRandomPoemPart(poem);
                    this.Close();
                }
            }
        }
Example #27
0
        /// <summary> Конвертирование JSON в Poem </summary>
        /// <param name="jsonString">JSON</param>
        /// <returns>object || null</returns>
        public Poem MappingPoem(string jsonString)
        {
            Poem         poem  = null;
            IList <Poem> poems = JsonSerializer.Deserialize <List <Poem> >(jsonString);

            // по заданию нужно вставлять одну поэму, а приходит arr[] => выбираем любую
            if (poems != null && poems.Count > 0)
            {
                poem         = poems[rnd.Next(0, poems.Count - 1)];
                poem.Content = poem.Content;
            }
            return(poem);
        }
Example #28
0
        public PoemViewModel(int Id)
        {
            _context = new ApplicationDbContext();

            _poem = _context.Poems.Where(p => p.Id == Id).FirstOrDefault();

            _fileName = string.IsNullOrEmpty(_poem.SpecialName) ? _poem.Name.ToLower().Replace(" ", "_") : _poem.SpecialName;

            _minSeq = (int)_context.Poems.Select(p => p.Sequence).Min();
            _maxSeq = (int)_context.Poems.Select(p => p.Sequence).Max();

            _sequenceNumbers = _context.Poems.Where(p => p.Sequence != null).OrderBy(p => p.Sequence).Select(p => p.Sequence).ToList();
        }
Example #29
0
        // Todo: Getting a log message: requestLayout() improperly called by ... NavigationPageRenderer
        // https://stackoverflow.com/questions/24598977/android-requestlayout-improperly-called
        // Specifically this answer: https://stackoverflow.com/questions/24598977/android-requestlayout-improperly-called/24756631#24756631

        /// <summary> Add a complete poem into the viewer</summary>
        /// <param name="poem"></param>
        public void LoadWholePoem(Poem poem)
        {
            StackLayout.Children.Clear();

            DisplayedChunkIndex = 0;
            foreach (string chunk in poem.Chunks)
            {
                ChunkType     chunkType = (DisplayedChunkIndex == 0) ? ChunkType.Title : ChunkType.NormalPoem;
                ExtendedLabel label     = GetChunkToExtendedLabel(poem, DisplayedChunkIndex, chunkType);
                StackLayout.Children.Add(label);
                DisplayedChunkIndex++;
            }
        }
Example #30
0
        public void createPoetDante_withVilaNouvaandSomeCharacters_shouldCreate()
        {
            Character dante = new Character
            {
                Name = "Dante"
            };
            Character beatrice = new Character
            {
                Name = "Beatrice"
            };
            Poem m = new Poem
            {
                Name = "Vila Nouva"
            };

            dante.Poem    = m;
            beatrice.Poem = m;
            m.Characters.Add(dante);
            m.Characters.Add(beatrice);
            Poet f = new Poet
            {
                Name = "Dante"
            };

            m.Author = f;
            f.Poems.Add(m);

            using (ISession session = sqliteSessionFactory.Session)
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    Assert.That(f.Id == 0);

                    session.SaveOrUpdate(f);

                    transaction.Commit();

                    Assert.That(f.Id > 0);
                }
                using (session.BeginTransaction())
                {
                    var poets = session.CreateCriteria(typeof(Poet)).List <Poet>();
                    var poet  = poets[0];
                    Assert.That(poet.Poems[0].Name == "Vila Nouva");
                    Assert.That(poet.Poems[0].Characters.FirstOrDefault <Character>().Name == "Dante");

                    var people = session.CreateCriteria(typeof(Person)).List <Person>();
                    Assert.That(people.Count == 3);
                }
            }
        }