public static void Execute() { var client = new WebClient(); var result = client.DownloadString("http://www.skillbook.co.uk/ca/data/project.json.html"); var j = new JavaScriptSerializer(); var result2 = j.Deserialize<ProjectPoco[]>(result); Project project = null; foreach (var item in result2) { project = _context.Projects.FirstOrDefault(proj => proj.ExternalId == item.ProjectId); if (project == null) { project = new Project(); project.AdminOrganization = GetOrganisation; project.Location = new Location(); _context.AddToProjects(project); } project.Location.Longitude = RandomNumber(40, 55); project.Location.Latitude = RandomNumber(40, 55); project.Location.Address = "Playgound Central"; project.Name = item.Name; project.ExternalId = item.ProjectId; project.Description = item.Description; } _context.SaveChanges(); }
public static Marker CreateProjectMarker(Project project, UrlHelper url) { return new Marker() { Title = project.Name, Content = String.Format("<h3>{0}</h3>{1}", project.Name, project.Description), IconUrl = url.Content("~/Content/images/project.png"), Latitude = project.Location.Latitude, Longitude = project.Location.Longitude, Address = project.Location.Address }; }
public ActionResult Create(Project project) { if (ModelState.IsValid) { int orgID = int.Parse(Request.Form["AdminOrg"].ToString()); var orginization = db.Organizations.Where(X => X.Id == orgID).FirstOrDefault(); project.AdminOrganization = orginization; db.Projects.AddObject(project); db.SaveChanges(); return RedirectToAction("Index"); } return View(project); }
/// <summary> /// Create a new Project object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="name">Initial value of the Name property.</param> /// <param name="description">Initial value of the Description property.</param> /// <param name="isActive">Initial value of the IsActive property.</param> /// <param name="location">Initial value of the Location property.</param> public static Project CreateProject(global::System.Int32 id, global::System.String name, global::System.String description, global::System.Boolean isActive, Location location) { Project project = new Project(); project.Id = id; project.Name = name; project.Description = description; project.IsActive = isActive; project.Location = StructuralObject.VerifyComplexObjectIsNotNull(location, "Location"); return project; }
/// <summary> /// Deprecated Method for adding a new object to the Projects EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToProjects(Project project) { base.AddObject("Projects", project); }
private void SaveResourceFromTweet(Tweet tweet) { Resource resource = null; Regex tweetSplitter = new Regex(@"^(" + _MagicHashTag + @")\W+(#(p|o)\W*(\w+))\W+(.*?(x(\d+)\W*(\w*)){0,1})$"); MatchCollection matches = tweetSplitter.Matches(tweet.Title); if(matches.Count==1) { //Looks like a good tweet resource= new Resource(); var match = matches[0]; string ownerType = match.Groups[3].Value; //P or O string ownerName = match.Groups[4].Value; //numeric int quantity; string units; if (match.Groups.Count > 7) { quantity = int.Parse(match.Groups[7].Value); units = match.Groups[8].Value; } else { quantity = 1; units = "unit"; } Organization organization = null; Project project = null; if(ownerType=="o") { organization = _context.Organizations.FirstOrDefault(o => o.Name == ownerName); if (organization == null) { organization = new Organization(); organization.Name = ownerName; organization.ContactEmail = "@"+tweet.Author; _context.Organizations.AddObject(organization); } resource.Organization = organization; } else if(ownerType=="p") { project = _context.Projects.FirstOrDefault(o => o.Name == ownerName); if (project == null) { project = new Project(); project.Name = ownerName; project.IsActive = true; project.Description = "Created by " + tweet.Author + " via twitter at " + DateTime.UtcNow.ToString("s"); _context.Projects.AddObject(project); //Need to connect to an organisation too organization = _context.Organizations.FirstOrDefault(o => o.ContactEmail == "@" + tweet.Author); if (organization == null) { organization = new Organization(); organization.ContactEmail = "@" + tweet.Author; organization.Name = tweet.Author; //default for now? _context.Organizations.AddObject(organization); } project.AdminOrganization = organization; //TODO: Make this correct project.Location.Address = string.Empty; project.Location.Latitude = 51.5; project.Location.Longitude = -1.75; } resource.Project = project; } string description = match.Groups[5].Value; //description resource.Description = description; resource.Title = description; resource.Quantity = quantity; resource.QuantityUnits = units; //TODO: Make this correct resource.Location.Address = string.Empty; resource.Location.Latitude = 51.5; resource.Location.Longitude = -1.75; //resource.Tags.Add(new Tag() {Name = ""}); _context.AddToResources(resource); _context.SaveChanges(); } }
public ActionResult Edit(Project project) { if (ModelState.IsValid) { db.Projects.Attach(project); db.ObjectStateManager.ChangeObjectState(project, EntityState.Modified); db.SaveChanges(); return RedirectToAction("Index"); } return View(project); }
private void SaveResourceFromTweet(Tweet tweet) { Resource resource = null; Regex tweetSplitter = new Regex(@"^("+_MagicHashTag+@")\s+(#(?<ownerType>p|o)\s*(?<owner>\S+))\s+((?<title>.*?)(x(?<count>\d+)\s*(?<units>\S*)){0,1})$"); Regex imageUrlsRegex = new Regex(@"(http://yfrog.com/\S+)\s+"); MatchCollection matches = tweetSplitter.Matches(tweet.Title); if(matches.Count==1) { //Looks like a good tweet resource= new Resource(); var match = matches[0]; string ownerType = match.Groups["ownerType"].Value; //P or O string ownerName = match.Groups["owner"].Value; //name int quantity; string units; if (match.Groups.Count > 7) { quantity = int.Parse(match.Groups["count"].Value); units = match.Groups["units"].Value; } else { quantity = 1; units = "unit"; } Organization organization = null; Project project = null; if(ownerType=="o") { organization = _context.Organizations.FirstOrDefault(o => o.Name == ownerName); if (organization == null) { organization = new Organization(); organization.Name = ownerName; organization.ContactEmail = "@"+tweet.Author; _context.Organizations.AddObject(organization); } resource.Organization = organization; } else if(ownerType=="p") { project = _context.Projects.FirstOrDefault(o => o.Name == ownerName); if (project == null) { project = new Project(); project.Name = ownerName; project.IsActive = true; project.Description = "Created by " + tweet.Author + " via twitter at " + DateTime.UtcNow.ToString("s"); _context.Projects.AddObject(project); //Need to connect to an organisation too organization = _context.Organizations.FirstOrDefault(o => o.ContactEmail == "@" + tweet.Author); if (organization == null) { organization = new Organization(); organization.ContactEmail = "@" + tweet.Author; organization.Name = tweet.Author; //default for now? _context.Organizations.AddObject(organization); } project.AdminOrganization = organization; //TODO: Make this correct project.Location.Address = string.Empty; project.Location.Latitude = 51.5 + (_Random.NextDouble() - 0.5); project.Location.Longitude = -1.75 + (_Random.NextDouble() - 0.5); } resource.Project = project; } string description = match.Groups["title"].Value; //description resource.Quantity = quantity; resource.QuantityUnits = units; //TODO: Make this correct resource.Location.Address = string.Empty; resource.Location.Latitude = 51.5 + (_Random.NextDouble()-0.5); resource.Location.Longitude = -1.75 + (_Random.NextDouble() - 0.5); var imageMatches = imageUrlsRegex.Matches(tweet.Title); if (imageMatches.Count > 0) { resource.ImageUrl = imageMatches[0].Groups[1].Value; description = description.Replace(resource.ImageUrl,string.Empty); resource.ImageUrl += ":small"; } resource.Description = description; resource.Title = description; //resource.Tags.Add(new Tag() {Name = ""}); _context.AddToResources(resource); _context.SaveChanges(); } }