Exemplo n.º 1
0
        public ActionResult Add(string format)
        {
            PointDataSummary newSummary = null;

            using (TransactionScope ts = new TransactionScope())
            using (SharedDbConnectionScope sharedConnectionScope = new SharedDbConnectionScope())
            {
                try
                {
                    newSummary = new PointDataSummary();

                    // Get POST data
                    TryUpdateModel<PointDataSummary>(newSummary, new[] { "Description", "LayerId", "Latitude", "Longitude", "Guid", "Name", "Tag" });

                    if (newSummary.Latitude == 0)
                    {
                        string lat = HttpContext.Request["Latitude"];
                        newSummary.Latitude = decimal.Parse(lat, CultureInfo.InvariantCulture);
                    }

                    if (newSummary.Longitude == 0)
                    {
                        string longi = HttpContext.Request["Longitude"];
                        newSummary.Longitude = decimal.Parse(longi, CultureInfo.InvariantCulture);
                    }

                    PointDataSummary testSummary = GetSummary(newSummary.Guid, newSummary.LayerId);
                    if (testSummary != null) {
                        throw new Exception("PointDataSummary already exists in database guid, layerId");
                    }

                    newSummary.Description = newSummary.Description ?? string.Empty;
                    newSummary.Tag = newSummary.Tag ?? string.Empty;

                    newSummary.CreatedOn = DateTime.UtcNow;
                    newSummary.ModifiedOn = newSummary.CreatedOn;
                    newSummary.CreatedById = CurrentUserId;
                    newSummary.Save();
                    if (RoleEnvironment.IsAvailable)
                        SearchEngine.Instance.Index(newSummary.Id);
                    ts.Complete();

                    // Set 201 status code, and Location header
                    HttpContext.Response.StatusCode = 201;
                    string location = this.BuildUrlFromExpression<SummariesController>(c => c.ShowById(newSummary.Id, format));
                    HttpContext.Response.AddHeader("Location", location);
                }
                catch (Exception ex)
                {
                    HttpContext.Response.StatusCode = 400;
                    return Json( CreateErrorObject(ex) );
                }
            }

            return Json(newSummary);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds the PointDataSummary to the lucene index specified by the IndexWriter
        /// </summary>
        /// <param name="indexWriter"></param>
        /// <param name="summary"></param>
        public void Index(IndexWriter indexWriter, PointDataSummary summary)
        {
            // Delete the current document if it exists already
            indexWriter.DeleteDocuments(new Lucene.Net.Index.Term("point_id", summary.Id.ToString()));

            // Create Lucene document and add the indexed fields.
            Document doc = new Document();
            doc.Add(new Field("point_id", summary.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED, Field.TermVector.NO));
            doc.Add(new Field("Name", summary.Name, Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.NO));
            doc.Add(new Field("Tags", summary.Tag, Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.NO));
            doc.Add(new Field("Description", summary.Description, Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.NO));
            doc.Add(new Field("LayerId", summary.LayerId, Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.NO));
            indexWriter.AddDocument(doc);
        }
Exemplo n.º 3
0
        public ActionResult AddTag(long id, string tag, string format)
        {
            IQueryable<PointDataSummary> iq = PointDataSummary.All().Where(
                    c => c.Id == id);
            PointDataSummary summary = iq.SingleOrDefault();

            if (summary == null)
            {
                summary = new PointDataSummary()
                {
                    Id = id,
                    Tag = ""
                };
                //HttpContext.Response.StatusCode = 404;
                //return Json(null);
            }

            using (TransactionScope ts = new TransactionScope())
            using (SharedDbConnectionScope sharedConnectionScope = new SharedDbConnectionScope())
            {
                try
                {
                    string filteredTag = filterForDuplicates(summary.Tag, tag);

                    if (!String.IsNullOrEmpty(filteredTag))
                    {
                        string fmt = String.IsNullOrEmpty(summary.Tag)? "{0}" : ",{0}";
                        summary.Tag += String.Format(fmt, filteredTag);
                        summary.ModifiedOn = DateTime.UtcNow;
                        summary.Save();
                        if (RoleEnvironment.IsAvailable)
                            SearchEngine.Instance.Index(summary.Id);
                        ts.Complete();
                    }
                }
                catch (Exception ex)
                {
                    HttpContext.Response.StatusCode = 400;
                    return Json( CreateErrorObject(ex) );
                }
            }

            return Json(summary);
        }
Exemplo n.º 4
0
 public ActionResult CreateLandmark(string name, string description, string layerid, string latitude, string longitude, string createdby)
 {
     try
     {
         PointDataSummary newSummary = new PointDataSummary()
         {
             Name = name,
             Description = description,
             LayerId = layerid,
             Latitude = decimal.Parse(latitude, CultureInfo.InvariantCulture),
             Longitude = decimal.Parse(longitude, CultureInfo.InvariantCulture),
             Guid = Guid.NewGuid().ToString(),
             CreatedById = long.Parse(createdby, CultureInfo.InvariantCulture),
             CreatedOn = DateTime.UtcNow,
             ModifiedOn = DateTime.UtcNow
         };
         newSummary.Save();
     }
     catch (Exception)
     {
         return Json("error", JsonRequestBehavior.AllowGet);
     }
     return Json("success", JsonRequestBehavior.AllowGet);
 }
Exemplo n.º 5
0
        public ActionResult GetSummaryByGuid(string guid, string name, string latitude, string longitude, string createdby, int Region_Index = 0, int Feed_Index = 0)
        {
            PointDataSummary summary = PointDataSummary.All().FirstOrDefault(s => s.Guid == guid);

            if (summary == null)
            {
                summary = new PointDataSummary()

                {
                    Name = name,
                    Description = name,
                    LayerId = GetFeedUniqueId(Region_Index, Feed_Index),
                    Latitude = decimal.Parse(latitude, CultureInfo.InvariantCulture),
                    Longitude = decimal.Parse(longitude, CultureInfo.InvariantCulture),
                    Guid = Guid.NewGuid().ToString(),
                    CreatedById = long.Parse(createdby.Length > 0 ? createdby : "0"),
                    CreatedOn = DateTime.UtcNow,
                    ModifiedOn = DateTime.UtcNow
                };
                if (createdby.Length > 0)
                    summary.Save();
            }

            var comments = from c in PointDataCommentView.All().Where(c => c.SummaryId == summary.Id)
                           join a in OAuthAccount.All() on c.CreatedById equals a.Id
                           select new { Text = c.Text, User = a.screen_name, Date = c.CreatedOn.ToString("dd MMM yyy hh:mm") };

            return Json(new { summary, comments }, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 6
0
 public static void Setup(int testItems)
 {
     SetTestRepo();
     for(int i=0;i<testItems;i++){
         PointDataSummary item=new PointDataSummary();
         _testRepo._items.Add(item);
     }
 }
Exemplo n.º 7
0
 public static void Setup(PointDataSummary item)
 {
     SetTestRepo();
     _testRepo._items.Add(item);
 }