public void UpdateAnimalDetailsValidInput() { var details = context.GetAllAnimalsDetailById(1); Assert.AreEqual(2, details.Count()); var an = new AnimalDetail { animalId = 1, language = (long)Languages.he, name = "בבון הזית", category = "קופים", series = "קוף", distribution = "", family = "", food = "", reproduction = "", interesting = "גילאור בבון הזית מאוד חמוד" }; an.name = "אביב מאג"; context.UpdateAnimalDetails(an); details = context.GetAllAnimalsDetailById(1); Assert.AreEqual(2, details.Count()); Assert.IsTrue(details.Any(d => d.name == "אביב מאג")); Assert.IsFalse(details.Any(d => d.name == "בבון הזית")); }
public void UpdateAnimalDetailsValidButMissingInput() { var details = context.GetAllAnimalsDetailById(1); Assert.AreEqual(2, details.Count()); var an = new AnimalDetail { animalId = 1, language = (long)Languages.he, name = "בבון הזית", category = "קופים", series = "קוף", distribution = "", family = "", food = "", reproduction = "", interesting = "גילאור בבון הזית מאוד חמוד" }; an.category = ""; an.series = ""; context.UpdateAnimalDetails(an); details = context.GetAllAnimalsDetailById(1); Assert.AreEqual(2, details.Count()); an = details.SingleOrDefault(d => d.language == (int)Languages.he); Assert.IsNotNull(an); Assert.AreEqual("", an.category); Assert.AreEqual("", an.series); }
public IHttpActionResult PutAnimalDetail(int id, AnimalDetail animalDetail) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != animalDetail.FactId) { return(BadRequest()); } db.Entry(animalDetail).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!AnimalDetailExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Question(AnimalDetail animalDetail) { AnimalDetail temp = null; if (!string.IsNullOrEmpty(animalDetail.SelectedAnswer) && animalDetail.SelectedAnswer.Equals("Yes")) { temp = new BusinessLayer.BLAnimalDetail().GetNextFactForAnimal(animalDetail); ViewData["AnimalFound"] = true; } else if (!string.IsNullOrEmpty(animalDetail.SelectedAnswer) && animalDetail.SelectedAnswer.Equals("No")) { temp = new BusinessLayer.BLAnimalDetail().GetFactForNextAnimal((List <AnimalDetail>)@ViewBag.animalDetails, animalDetail); ViewData["AnimalFound"] = false; } ModelState.Clear(); if (temp == null) { ViewData["EndGuess"] = true; var animal = db.Animals.Find(animalDetail.AnimalId); if (animal != null) { ViewData["AnimalName"] = animal.Name; } } return(View(temp)); }
public ActionResult DeleteConfirmed(int id) { AnimalDetail animalDetail = db.AnimalDetails.Find(id); db.AnimalDetails.Remove(animalDetail); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <ActionResult> DeleteConfirmed(int id) { AnimalDetail animalDetail = await db.AnimalDetails.FindAsync(id); db.AnimalDetails.Remove(animalDetail); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public IHttpActionResult GetAnimalDetail(int id) { AnimalDetail animalDetail = db.AnimalDetails.Find(id); if (animalDetail == null) { return(NotFound()); } return(Ok(animalDetail)); }
public ActionResult Edit([Bind(Include = "FactId,Facts,AnimalId")] AnimalDetail animalDetail) { if (ModelState.IsValid) { db.Entry(animalDetail).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.AnimalId = new SelectList(db.Animals, "Id", "Name", animalDetail.AnimalId); return(View(animalDetail)); }
public ActionResult Create([Bind(Include = "FactId,Facts,AnimalId")] AnimalDetail animalDetail) { if (ModelState.IsValid) { db.AnimalDetails.Add(animalDetail); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.AnimalId = new SelectList(db.Animals, "Id", "Name", animalDetail.AnimalId); return(View(animalDetail)); }
public IHttpActionResult PostAnimalDetail(AnimalDetail animalDetail) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.AnimalDetails.Add(animalDetail); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = animalDetail.FactId }, animalDetail)); }
// GET: AnimalDetails/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AnimalDetail animalDetail = db.AnimalDetails.Find(id); if (animalDetail == null) { return(HttpNotFound()); } return(View(animalDetail)); }
public IHttpActionResult DeleteAnimalDetail(int id) { AnimalDetail animalDetail = db.AnimalDetails.Find(id); if (animalDetail == null) { return(NotFound()); } db.AnimalDetails.Remove(animalDetail); db.SaveChanges(); return(Ok(animalDetail)); }
// GET: AnimalDetails/Delete/5 public async Task <ActionResult> Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AnimalDetail animalDetail = await db.AnimalDetails.FindAsync(id); if (animalDetail == null) { return(HttpNotFound()); } return(View(animalDetail)); }
// GET: AnimalDetails/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AnimalDetail animalDetail = db.AnimalDetails.Find(id); if (animalDetail == null) { return(HttpNotFound()); } ViewBag.AnimalId = new SelectList(db.Animals, "Id", "Name", animalDetail.AnimalId); return(View(animalDetail)); }
public void UpdateAnimaDetailsWrongName() { var details = context.GetAllAnimalsDetailById(1); Assert.AreEqual(2, details.Count()); var an = new AnimalDetail { animalId = 1, category = "חרבון", interesting = "זה סיפור על קקי יפה", language = (long)Languages.ar }; context.UpdateAnimalDetails(an); }
/// <summary> /// Retrieve one fact(Animal Detail) for each animal. /// </summary> /// <param name="items"></param> /// <param name="currentFact"></param> /// <returns></returns> public AnimalDetail GetFactForNextAnimal(List <AnimalDetail> items, AnimalDetail currentFact) { if (currentFact != null) { int nextAnimalId = currentFact.AnimalId + 1; var animalDetails = from element in db.AnimalDetails.Include(a => a.Animal) group element by element.AnimalId into groups select groups.OrderBy(p => p.FactId).FirstOrDefault(); return(animalDetails.Include(a => a.Animal).ToList().Where(ad => ad.AnimalId == nextAnimalId).OrderBy(a => a.FactId).FirstOrDefault()); //from element in db.AnimalDetails.Include(a => a.Animal) // select groups.OrderBy(p => p.FactId).FirstOrDefault(); } return(null); }
public void UpdateAnimalDetailsAddAnimalDoesntExists() { var details = context.GetAllAnimalsDetailById(1); Assert.AreEqual(2, details.Count()); var an = new AnimalDetail { animalId = -1, name = "בבון הזית", category = "חרבון", interesting = "זה סיפור על קקי יפה", language = (long)Languages.ar }; context.UpdateAnimalDetails(an); }
// [Route("Get/{animalId}/{factId}/{selectedAnswer}")] public IHttpActionResult Get([FromUri] int animalId, int factId, string selectedAnswer) { bool animalFound = false; if (animalId == 0 && factId == 0) { var animalDetails = from element in db.AnimalDetails.Include(a => a.Animal) group element by element.AnimalId into groups select groups.OrderBy(p => p.FactId).FirstOrDefault(); return(Ok(animalDetails.ToList().FirstOrDefault())); } AnimalDetail temp = null; if (!string.IsNullOrEmpty(selectedAnswer) && selectedAnswer.ToLower().Equals("yes")) { temp = new BusinessLayer.BLAnimalDetail().GetNextFactForAnimal(animalId, factId); animalFound = true; //ViewData["AnimalFound"] = true; } else if (!string.IsNullOrEmpty(selectedAnswer) && selectedAnswer.ToLower().Equals("no")) { temp = new BusinessLayer.BLAnimalDetail().GetFactForNextAnimal(animalId); //ViewData["AnimalFound"] = false; } // ModelState.Clear(); if (temp == null && animalFound.Equals(true)) { // ViewData["EndGuess"] = true; var animal = db.Animals.Find(animalId); if (animal != null) { temp = new AnimalDetail(); temp.AnimalName = animal.Name; } } return(Ok(temp)); }
/// <summary> /// if one fact is matched then retrieve the next fact for the same Animal. /// </summary> /// <param name="currentFact"></param> /// <returns></returns> public AnimalDetail GetNextFactForAnimal(AnimalDetail currentFact) { if (currentFact != null) { int nextAnimalId = currentFact.AnimalId + 1; var items = db.AnimalDetails.Include(a => a.Animal).Where(ad => ad.AnimalId == currentFact.AnimalId).OrderBy(a => a.FactId).ToList(); int index = items.FindIndex(it => it.FactId == currentFact.FactId); if (items.Count > index + 1) { return(items.ElementAt(index + 1)); } else { } } return(null); }
public ActionResult <AnimalDetail> Get(string id) { var animal = _animalService.Get(id); var taxonomyId = animal.TaxonomyId; var Taxonomy = _taxonomyService.Get(taxonomyId); var animalDetail = new AnimalDetail { Id = animal.Id, ThaiName = animal.ThaiName, CommonName = animal.CommonName, ScientificName = animal.ScientificName, Description = animal.Description, TaxonomyId = Taxonomy, BoneImgPath = animal.BoneImgPath, ImgPath = animal.ImgPath, }; return(animalDetail); }
public void UpdateAnimalDetailsAddAnValidTest() { var details = context.GetAllAnimalsDetailById(1); Assert.AreEqual(2, details.Count()); var det = new AnimalDetail { animalId = 1, name = "הקקי שלי", category = "חרבון", interesting = "זה סיפור על קקי יפה", language = (long)Languages.ar }; context.UpdateAnimalDetails(det); details = context.GetAllAnimalsDetailById(1); Assert.AreEqual(3, details.Count()); }
public void UpdateAnimalDetails(AnimalDetail animalsDetails) { try { using (var db = this.GetContext()) { if (ValidateSessionId(db)) { db.UpdateAnimalDetails(animalsDetails); } else { throw new AuthenticationException("Couldn't validate the session"); } } } catch (Exception Exp) { string AnimalDetailInput = "id: " + animalsDetails.animalId + ", name: " + animalsDetails.name + ", category: " + animalsDetails.category + ", distribution: " + animalsDetails.distribution + ", family: " + animalsDetails.family + ", food: " + animalsDetails.food + animalsDetails.reproduction + ", series: " + animalsDetails.series + ", language: " + animalsDetails.language; Logger.GetInstance(isTesting).WriteLine(Exp.Message, Exp.StackTrace, "AnimalDetails: " + AnimalDetailInput); throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } }
public void UpdateAnimalDetailsWrongLangauge() { var details = context.GetAllAnimalsDetailById(1); Assert.AreEqual(2, details.Count()); var an = new AnimalDetail { animalId = 1, language = -4, name = "בבון הזית", category = "קופים", series = "קוף", distribution = "", family = "", food = "", reproduction = "", interesting = "גילאור בבון הזית מאוד חמוד" }; an.name = "גורילה"; context.UpdateAnimalDetails(an); }