internal static int RemoveVocabularyWord(string wordStr, int id, string owner) { if (string.IsNullOrEmpty(owner)) { throw new Exception("Owner needed"); } bool isList = VocabularyList.Exists("WHERE ID = @0 AND OwnerID = @1", id, owner); if (!isList) { throw new Exception("Unknown list"); } Word word = Word.FirstOrDefault("WHERE Word=@0", wordStr); if (word == null) { throw new Exception(String.Format("Unknown word {0}", wordStr)); } Sql delSql = new Sql(@"DELETE FROM [dbo].[VocabularyList_Word] WHERE WordID=@0 AND VocabularyListID=@1", word.ID, id); return(db.Execute(delSql)); }
internal static void AddVocabularyWord(string wordStr, int id, string owner) { if (string.IsNullOrEmpty(owner)) { throw new Exception("Owner needed"); } bool isList = VocabularyList.Exists("WHERE ID = @0 AND OwnerID = @1", id, owner); if (!isList) { throw new Exception("Unknown list"); } Word word = Word.FirstOrDefault("WHERE Word=@0", wordStr); if (word == null) { throw new Exception(String.Format("Unknown word {0}", wordStr)); } VocabularyList_Word vlw = new VocabularyList_Word(); vlw.VocabularyListID = id; vlw.WordID = word.ID; vlw.Insert(); }
public VocabularyListVM(VocabularyList list) { this.Description = list.Description; this.ID = list.ID; this.OwnerID = list.OwnerID; this.Status = list.Status; this.Title = list.Title; this.RandomURL = list.RandomURL; this.UserURL = list.UserURL; }
//[System.Web.Http.HttpPost] public HttpResponseMessage Post([FromBody] VocabularyWord model) { if (UserID == null) { return(ResponseError(HttpStatusCode.Forbidden, "Log in required.")); } Sql sql = new Sql("WHERE OwnerID=@0", UserID); int listID = 0; if (model.list != null && int.TryParse(model.list, out listID)) { sql.Append("AND ID=@0", listID); } sql.Append("ORDER BY ID DESC"); VocabularyList vc = VocabularyList.FirstOrDefault(sql); if (vc == null) { return(ResponseError(HttpStatusCode.PreconditionFailed, "No vocabulary list found.")); } try { SuomenkieliRepository.AddVocabularyWord(model.word, vc.ID, UserID); } catch (Exception ex) { return(ResponseError(HttpStatusCode.InternalServerError, ex.Message)); } int wordID = SuomenkieliRepository.GetWordID(model.word).GetValueOrDefault(); // This should not be null. FullWord fWord = SuomenkieliRepository.GetFullWord(wordID); string firstDef = (fWord.Definitions.Count > 0) ? fWord.Definitions.First()._Definition : ""; ResponseWord rWord = new ResponseWord() { id = fWord.ID, word = fWord._Word, definition = firstDef }; var resp = Request.CreateResponse <ResponseWord>(HttpStatusCode.OK, rWord); return(resp); //return ResponseOK(rWord); }
private void deleteObject() { if (mainMenu.SelectItemNumber == 1) { if (kanjiMenu.SelectItemNumber == 1) { Components.Remove(this.kanjiGame); kanjiGame.Dispose(); kanjiGame = null; } else if (kanjiMenu.SelectItemNumber == 2) { Components.Remove(this.compositionGame); compositionGame.Dispose(); compositionGame = null; } else if (kanjiMenu.SelectItemNumber == 3) { Components.Remove(this.kanjiList); kanjiList.Dispose(); kanjiList = null; } else { } } else if (mainMenu.SelectItemNumber == 2) { if (vocabularyMenu.SelectItemNumber == 1) { Components.Remove(this.vocabularyGame); vocabularyGame.Dispose(); vocabularyGame = null; } else if (vocabularyMenu.SelectItemNumber == 2) { Components.Remove(this.vocabularyGame2); vocabularyGame2.Dispose(); vocabularyGame2 = null; } else if (vocabularyMenu.SelectItemNumber == 3) { Components.Remove(this.vocabularyList); vocabularyList.Dispose(); vocabularyList = null; } else { } } else { } }
public ActionResult Create(VocabularyList list) { try { list.OwnerID = UserID; int listID = (int)list.Insert(); return(RedirectToAction("Edit", new { id = listID })); } catch (Exception ex) { return(HttpNotFound(ex.Message)); } }
private IEnumerable <VocabularyListVM> GetListOfVocabularyListVM(int[] ids) { IEnumerable <VocabularyList> vLists = VocabularyList.Fetch("WHERE OwnerID=@0 AND ID IN @1", UserID, ids); List <VocabularyListVM> vmLists = new List <VocabularyListVM>(); foreach (VocabularyList vList in vLists) { VocabularyListVM vmList = new VocabularyListVM(vList); vmList.WordList = SuomenkieliRepository.GetFullWordListByListID(vmList.ID); vmLists.Add(vmList); } return(vmLists); }
private VocabularyListVM GetVocabularyListVW(int id) { VocabularyList vl = VocabularyList.First("WHERE id=@0 AND OwnerID=@1", id, UserID); if (vl == null) { return(null); } VocabularyListVM vlm = new VocabularyListVM(vl); //List<VocabularyList_Word> vlWords = VocabularyList_Word.Fetch("WHERE VocabularyListID = @0 ORDER BY Rank", id); //int[] wordIDs = vlWords.Select(t => t.WordID).ToArray(); List <FullWord> vlFW = SuomenkieliRepository.GetFullWordListByListID(vlm.ID); vlm.WordList = vlFW; return(vlm); }
public HttpResponseMessage Delete([FromBody] VocabularyWord model) { if (UserID == null) { return(ResponseError(HttpStatusCode.Forbidden, "Log in required.")); } Sql sql = new Sql("WHERE OwnerID=@0", UserID); int listID = 0; if (model.list != null && int.TryParse(model.list, out listID)) { sql.Append("AND ID=@0", listID); } sql.Append("ORDER BY ID DESC"); VocabularyList vc = VocabularyList.FirstOrDefault(sql); if (vc == null) { return(ResponseError(HttpStatusCode.PreconditionFailed, "No vocabulary list found.")); } try { SuomenkieliRepository.RemoveVocabularyWord(model.word, vc.ID, UserID); } catch (Exception ex) { return(ResponseError(HttpStatusCode.InternalServerError, ex.Message)); } return(ResponseOK(model.word)); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); Vector2 position = new Vector2(d.X, d.Y); if (mainMenu.SelectItemNumber == 0) { mainMenu.Draw(gameTime, d, position); } else if (mainMenu.SelectItemNumber == 1) { if (kanjiMenu.SelectItemNumber == 0) { kanjiMenu.Draw(gameTime, d, position); } else if (kanjiMenu.SelectItemNumber == 1) { if (kanjiGame == null) { this.kanjiGame = new KanjiGame(this); Components.Add(this.kanjiGame); } kanjiGame.Draw(gameTime, d, position); kanjiGame.Update(gameTime); } else if (kanjiMenu.SelectItemNumber == 2) { if (compositionGame == null) { this.compositionGame = new CompositionGame(this); Components.Add(this.compositionGame); } compositionGame.Draw(gameTime, d, position); compositionGame.Update(gameTime); } else if (kanjiMenu.SelectItemNumber == 3) { if (kanjiList == null) { this.kanjiList = new KanjiList(this); Components.Add(this.kanjiList); } kanjiList.Draw(gameTime, d, position); kanjiList.Update(gameTime); } else { } back(position); } else if (mainMenu.SelectItemNumber == 2) { if (vocabularyMenu.SelectItemNumber == 0) { vocabularyMenu.Draw(gameTime, d, position); } else if (vocabularyMenu.SelectItemNumber == 1) { if (vocabularyGame == null) { this.vocabularyGame = new VocabularyGame(this); Components.Add(this.vocabularyGame); } vocabularyGame.Draw(gameTime, d, position); } else if (vocabularyMenu.SelectItemNumber == 2) { if (vocabularyGame2 == null) { this.vocabularyGame2 = new VocabularyGame2(this); Components.Add(this.vocabularyGame2); } vocabularyGame2.Draw(gameTime, d, position); } else if (vocabularyMenu.SelectItemNumber == 3) { if (vocabularyList == null) { this.vocabularyList = new VocabularyList(this); Components.Add(this.vocabularyList); } vocabularyList.Draw(gameTime, d, position); vocabularyList.Update(gameTime); } else { } back(position); } else { back(position); } spriteBatch.Begin(); if (d.X > 0 && d.X < GraphicsDevice.Viewport.Width && d.Y > 0 && d.Y < GraphicsDevice.Viewport.Height) { spriteBatch.Draw(cursor, position, null, Color.White, 0.0f, textureCenter, 1.0f, SpriteEffects.None, 0.0f); } spriteBatch.End(); base.Draw(gameTime); }