예제 #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);
        }
예제 #2
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);
 }
예제 #3
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);
        }