예제 #1
0
        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
        }
예제 #2
0
 [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
 }
예제 #3
0
        //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()));
            }
        }
예제 #4
0
        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()));
            }
        }
예제 #7
0
        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)
            }
        }
예제 #8
0
        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
            }
        }
예제 #10
0
        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);
            }
        }
예제 #12
0
        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)
        }
예제 #13
0
        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();
            }
        }