private static List <Pest> Pests(string symptom) { List <Pest> final = new List <Pest>(); Pest Pest = new Pest(); char[] delimiter = { '.' }; List <string> split_symptoms = Constants.Data(symptom, delimiter); foreach (var split_symptom in split_symptoms) { string id = string.Empty; try { var query = db.Symptoms.Where(c => c.Description == split_symptom).Single(); id = query.S_ID; } catch { } if (id.Equals(string.Empty)) { } else { final = PestFromSymptom(id); } } return(final); }
public ActionResult Create([Bind(Include = "P_ID,Name,About,Spread")] Pest pest) { var query = db.Pests.Count() + 1; string temp = "P-" + query; bool exist = false; try { var search = db.Pests.Where(c => c.P_ID == temp).Single(); exist = true; } catch { exist = false; } if (exist) { var all = db.Pests.ToList(); var dis = all.Last(); pest.P_ID = "P-" + DataModel.Constants.NextNumber(dis.P_ID); } else { pest.P_ID = temp; } if (ModelState.IsValid) { db.Pests.Add(pest); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(pest)); }
private static List <Pest> ResponsePests(string symptom) { List <Pest> final = new List <Pest>(); Pest disease = new Pest(); char[] delimiter = { '.' }; List <string> split_symptoms = Constants.Data(symptom, delimiter); foreach (var split_symptom in split_symptoms) { List <Pest> symptom_pest = new List <Pest>(); var query = db.Symptoms.FirstOrDefault(c => c.S_ID == split_symptom); if (query != null) { symptom_pest = PestsFromSelection(query.S_ID); if (symptom_pest != null) { foreach (var _pest in symptom_pest) { final.Add(_pest); } } } } return(final); }
public ActionResult DeleteConfirmed(string id) { Pest pest = db.Pests.Find(id); db.Pests.Remove(pest); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "P_ID,Name,About,Spread")] Pest pest) { if (ModelState.IsValid) { db.Entry(pest).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(pest)); }
public ActionResult Edit(Pest pest) { if (ModelState.IsValid) { db.Entry(pest).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(pest)); }
public ActionResult Create(Pest pest) { if (ModelState.IsValid) { db.Pests.Add(pest); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(pest)); }
public static Pest PestDetails(JObject PestObject) { Pest pest = new Pest() { Name = PestObject.Value <string>("Name"), About = PestObject.Value <string>("About"), Spread = PestObject.Value <string>("Spread"), Controls = Controls(PestObject.Value <JArray>("Controls")), Symptoms = Symptoms(PestObject.Value <JArray>("Symptoms")) }; return(pest); }
// GET: Pests/Edit/5 public ActionResult Edit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Pest pest = db.Pests.Find(id); if (pest == null) { return(HttpNotFound()); } return(View(pest)); }
public static List <Pest> PestList(JArray Array) { List <Pest> pests = new List <Pest>(); foreach (var item in Array) { var obj = item as JObject; Pest pest = new Pest() { ID = obj.Value <string>("ID"), Name = obj.Value <string>("Name") }; pests.Add(pest); } return(pests); }
public async Task <Guid> CreatePest(CreatePestViewModel model) { var pest = new Pest() { Name = model.Name, CreatedOn = DateTime.UtcNow, PestImgUrl = model.PestImgUrl, ShortDescription = model.ShortDescription, SuperFamily = model.SuperFamily, }; await this._pestRepository.AddAsync(pest); await this._pestRepository.SaveChangesAsync(); return(pest.Id); }
private static List <Pest> PestFromSymptom(string symptom_id) { List <Pest> final = new List <Pest>(); try { var query = db.Pest_Symptoms.Where(c => c.S_ID == symptom_id).ToList(); foreach (var _result in query) { string id = _result.P_ID; Pest Pest = db.Pests.Where(c => c.P_ID == id).Single(); final.Add(Pest); } } catch { } return(final); }
/// <summary>Creates the pest.</summary> /// <param name="pest">The pest.</param> /// <returns>A JSON encoded success indicator</returns> public JsonResult Create(Pest pest) { try { var farmContext = new PicolEntities(); farmContext.Pests.Add(pest); farmContext.SaveChanges(); return(new JsonNetResult { Data = new { Error = false, Pest = pest }, MaxJsonLength = int.MaxValue, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } catch (Exception e) { // Signal the error to be logged by elmah ErrorSignal.FromCurrentContext().Raise(e); return(new JsonNetResult { Data = new { Error = true, ErrorMessage = "Failed save pest." }, MaxJsonLength = int.MaxValue, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } }
private static List <Pest> PestsFromSelection(string symptom_id) { List <Pest> final = new List <Pest>(); try { var query = db.Pest_Symptoms.Where(c => c.S_ID == symptom_id).ToList(); if (query.Count == 1) { foreach (var _result in query) { Pest pest = db.Pests.Where(c => c.P_ID == _result.P_ID).Single(); final.Add(pest); } } } catch { } return(final); }
public static List <Pest> ClearPests(List <Pest> pests) { List <Pest> manipulate = new List <Pest>(); if (pests != null) { foreach (var pest in pests) { Pest Search = manipulate.Find(x => x.P_ID.Contains(pest.P_ID)); if (Search == null) { manipulate.Add(pest); } } return(manipulate); } else { return(null); } }
/// <summary>Updates the pest.</summary> /// <param name="pest">The pest.</param> /// <returns>A JSON encoded success indicator</returns> public JsonResult Update(Pest pest) { try { var farmContext = new PicolEntities(); farmContext.Pests.Attach(pest); farmContext.Entry(pest).State = System.Data.Entity.EntityState.Modified; farmContext.SaveChanges(); return(new JsonNetResult { Data = new { Error = false }, MaxJsonLength = int.MaxValue, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } catch (Exception e) { // Signal the error to be logged by elmah ErrorSignal.FromCurrentContext().Raise(e); return(new JsonNetResult { Data = new { Error = true, ErrorMessage = "Failed to update pest." }, MaxJsonLength = int.MaxValue, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } }
public async Task UpdateAsync(Pest pest) { await _repository.UpdateAsync(pest); }
public async Task CreateAsync(Pest pest) { await _repository.AddAsync(pest); }
public void processPest(Pest pest) { }
public void InsertPest(Pest pest) { context.Pests.Add(pest); context.SaveChangesAsync(); }
public void AddPest(Pest p) { currentPests.Add(p); }
protected override void Seed(FinalProject.Web.Models.ApplicationDbContext context) { // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. E.g. // // context.People.AddOrUpdate( // p => p.FullName, // new Person { FullName = "Andrew Peters" }, // new Person { FullName = "Brice Lambson" }, // new Person { FullName = "Rowan Miller" } // ); // var norwayRat = new Pest { PestName = "Norway Rat" }; var roofRat = new Pest { PestName = "Roof Rat" }; var mouse = new Pest { PestName = "Mouse" }; context.Pests.AddOrUpdate( p => p.PestName, new Pest { PestName = "Grass Spider" }, new Pest { PestName = "Black and Yellow Garden Spider" }, new Pest { PestName = "Black Widow Spider" }, new Pest { PestName = "Brown Recluse Spider" }, new Pest { PestName = "Wolf Spider" }, new Pest { PestName = "House Spider" }, new Pest { PestName = "American Cockroach" }, new Pest { PestName = "German Cockroach" }, new Pest { PestName = "Smokey Brown Cockroach" }, new Pest { PestName = "Carpenter Ant" }, new Pest { PestName = "Fire Ants" }, new Pest { PestName = "Little Black Ants" }, new Pest { PestName = "Crazy Ants" }, new Pest { PestName = "Velvet Ants" }, new Pest { PestName = "Indian Meal Moth" }, new Pest { PestName = "Weeval" }, new Pest { PestName = "Saw Tooth Grain Beetle" }, new Pest { PestName = "Larger Cabinet Beetle" }, norwayRat, roofRat, mouse ); var firstQuestion = new Question { Text = "How many legs?" }; var rats = new Collection <Pest>() { norwayRat, roofRat, mouse }; firstQuestion.Answers = new Collection <Answer>() { new Answer() { Text = "4", AssociatedPest = rats } }; var secondQuestion = new Question { Text = "Is it Big or Small?", Answers = new Collection <Answer> { new Answer() { Text = "Big", AssociatedPest = new Collection <Pest>() { norwayRat } }, new Answer() { Text = "Small", AssociatedPest = new Collection <Pest>() { roofRat, mouse } } } }; var thirdQuestion = new Question { Text = "Where was it located?", Answers = new Collection <Answer> { new Answer() { Text = "Roof or Tree", AssociatedPest = new Collection <Pest>() { roofRat } }, new Answer() { Text = "In or Around House", AssociatedPest = new Collection <Pest>() { mouse } } } }; context.Questions.AddOrUpdate(p => p.Text, firstQuestion, secondQuestion, thirdQuestion ); context.SaveChanges(); }