public void Insert(string[] data)//inserting words into the database { using (MarineDataEntities db = new MarineDataEntities()) { //data array contains a vocabulary title value at index[0] //appended to that is the list of words to be inserted into database data table //index[0] is skipped so that it is not added as a keyword //for each value starting at index[1] the vocabulary title (index[0]) and the //i'th value in the array are added into the vocab and keyword columns in the //Data table foreach (string w in data.Skip(1)) { Data d = new Data(); d.Vocab = data[0]; d.Keyword = w; db.Data.Add(d); } db.SaveChanges();//better for performance } //NOTE originally i was passing a JSON object array with key value pairs //but as they were two different data types, a string in first index and an array //in second, it was very difficult to receive in the controller }
[HttpPost]// public void Insert(string[] words) { //if list array is hard coded in here then the following code will write to db using (MarineDataEntities db = new MarineDataEntities()) { foreach (string w in words) { try { StopWordList sw = new StopWordList(); //create new instance sw.Stopword = w; //set the stop word to value of w db.StopWordLists.Add(sw); //add the new stopword to the add method db.SaveChanges(); } //http://stackoverflow.com/questions/5400530/validation-failed-for-one-or-more-entities-while-saving-changes-to-sql-server-da catch (DbEntityValidationException dbEx) { foreach (var errors in dbEx.EntityValidationErrors) { foreach (var validationError in errors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } //end catch //db.SaveChanges();//save changes together - faster } //end foreach } //end using }
//GET: api/Stopword/ public IHttpActionResult Get() { using (MarineDataEntities db = new MarineDataEntities()) { var result = from w in db.StopWordLists select w.Stopword; return(Ok(result.ToList())); } }
public IHttpActionResult GetTag() { using (MarineDataEntities db = new MarineDataEntities()) { var result = from t in db.SchemaTags select t.TagName; return(Ok(result.ToList())); } }
public IHttpActionResult GetCatalogueTitle() { using (MarineDataEntities db = new MarineDataEntities()) { var result = from cat in db.Catalogues select cat.Title; return(Ok(result.ToList())); } }
public IHttpActionResult GetVocabTitle() { using (MarineDataEntities db = new MarineDataEntities()) { var result = from voc in db.Vocabularies select voc.Title; return(Ok(result.ToList())); } }
public IHttpActionResult GetKeyword()//returns the keyword list from Data table { using (MarineDataEntities db = new MarineDataEntities()) { var result = from k in db.Data select new { k.Vocab, k.Keyword }; return(Ok(result.ToArray()));//returns to an array (JSON) } }
public ActionResult UserDetails(int ID) { MarineDataEntities dc = new MarineDataEntities(); if (ID == null) { } var userDetailsResponse = dc.Data.Where(x => x.Laskuri == ID); return(PartialView("_UserDetails", userDetailsResponse)); }
public IHttpActionResult OceanEnergy() { using (MarineDataEntities db = new MarineDataEntities()) { var query = from t in db.Vocabularies where t.Catalogues.Any(c => c.CatID == 2003) select t.Title; return(Ok(query.ToList()));//pulled from site } }
public IHttpActionResult GetSchemaTag()//returns the tags already stored in the Data table { using (MarineDataEntities db = new MarineDataEntities()) { var result = from k in db.Data where k.Tag != null select new { k.Vocab, k.Tag }; return(Ok(result.ToArray()));//returns as array (JSON) } }
//this calls the current stopWords stored in the databse and adds them to the stopWords dictionary //this is done each time the program is run against an xmlFile //i chose to do this to keep the data up to date and avoid manual insertion public void Get() { MarineDataEntities db = new MarineDataEntities(); var result = from w in db.StopWordLists select w.Stopword; var words = result.ToList(); foreach (string w in words) { Add(w); } }
public ActionResult ViewRevisionData() { //Get parameters try { log.Info("Before Paramater called"); var draw = Request.Form.GetValues("draw").FirstOrDefault(); var start = Request.Form.GetValues("start").FirstOrDefault(); var length = Request.Form.GetValues("length").FirstOrDefault(); //Get Sort columns value var sortColumn = Request.Form.GetValues("columns[" + Request.Form.GetValues("order[0][column]").FirstOrDefault() + "][name]").FirstOrDefault(); var sortColumnDir = Request.Form.GetValues("order[0][dir]").FirstOrDefault(); var searchValue = Request.Form.GetValues("search[value]").FirstOrDefault(); int pageSize = length != null?Convert.ToInt32(length) : 0; int skip = start != null?Convert.ToInt32(start) : 0; int totalRecords = 0; log.Info("ActionMethod was Called Before Database"); using (MarineDataEntities dc = new MarineDataEntities()) { var dv = (from a in dc.Data where (a.Datasheet_status == "Ei käytössä") select a); //Sorting if (!(string.IsNullOrEmpty(sortColumn) && string.IsNullOrEmpty(sortColumnDir))) { dv = dv.OrderBy(sortColumn + " " + sortColumnDir); } if (!string.IsNullOrEmpty(searchValue)) { dv = dv.Where(m => m.Datasivun_numero == searchValue || m.Code == searchValue || m.Model_No == searchValue); } totalRecords = dv.Count(); var data = dv.Skip(skip).Take(pageSize).ToList(); return(Json(new { draw = draw, recordsFiltered = totalRecords, recordsTotal = totalRecords, data = data }, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { log.Error(ex.Message.ToString()); throw ex; } // get Start (paging start index) and length (page size for paging) }
public void InsertTag(string[] data) { using (MarineDataEntities db = new MarineDataEntities()) { string word = data[0]; string tag = data[1]; List <Data> results = (from r in db.Data where r.Keyword == word select r).ToList(); foreach (Data d in results) { d.Tag = tag; } db.SaveChanges(); } }