public ActionResult Create(Resource resource)
        {
            foreach (var modelStateValue in ViewData.ModelState.Values)
            {
                foreach (var error in modelStateValue.Errors)
                {
                    // Do something useful with these properties
                    var errorMessage = error.ErrorMessage;
                    var exception = error.Exception;
                }
            }

            if (ModelState.IsValid)
            {
                int orgID = int.Parse(Request.Form["OrgCombo"].ToString());
                var orginization = db.Organizations.Where(X => X.Id == orgID).FirstOrDefault();

                resource.Organization = orginization;

                int projectID = int.Parse(Request.Form["ProjectCombo"].ToString());
                var project = db.Projects.Where(X => X.Id == projectID).FirstOrDefault();

                resource.Project = project;

                db.Resources.AddObject(resource);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            else {

                ViewBag.Organizations = db.Organizations;
                ViewBag.Projects = db.Projects;
                return View(resource);
            }
        }
Beispiel #2
0
 private static Marker CreateMarker(Resource resource)
 {
     return new Marker() {
         Title = resource.Title,
         Content = String.Format("<h3>{0}</h3>{1}", resource.Title, resource.Description),
         Latitude = resource.Location.Latitude,
         Longitude = resource.Location.Longitude,
         Address = resource.Location.Address
     };
 }
Beispiel #3
0
 private static Marker CreateMarker(Resource resource)
 {
     return new Marker() {
         Title = resource.Title,
         Content = String.Format(
             "<h3>{0}</h3><p>{1}</p><p><img src='{2}'/></p>",
             resource.Title,
             resource.Description,
             resource.ImageUrl),
         Latitude = resource.Location.Latitude,
         Longitude = resource.Location.Longitude,
         Address = resource.Location.Address,
     };
 }
 /// <summary>
 /// Create a new Resource object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="title">Initial value of the Title property.</param>
 /// <param name="description">Initial value of the Description property.</param>
 /// <param name="quantity">Initial value of the Quantity property.</param>
 /// <param name="quantityUnits">Initial value of the QuantityUnits property.</param>
 /// <param name="location">Initial value of the Location property.</param>
 public static Resource CreateResource(global::System.Int64 id, global::System.String title, global::System.String description, global::System.Double quantity, global::System.String quantityUnits, Location location)
 {
     Resource resource = new Resource();
     resource.Id = id;
     resource.Title = title;
     resource.Description = description;
     resource.Quantity = quantity;
     resource.QuantityUnits = quantityUnits;
     resource.Location = StructuralObject.VerifyComplexObjectIsNotNull(location, "Location");
     return resource;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Resources EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToResources(Resource resource)
 {
     base.AddObject("Resources", resource);
 }
 public ActionResult Edit(Resource resource)
 {
     if (ModelState.IsValid)
     {
         db.Resources.Attach(resource);
         db.ObjectStateManager.ChangeObjectState(resource, EntityState.Modified);
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(resource);
 }
        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();
            }
        }
Beispiel #8
0
 public static Marker CreateRequiredResourceMarker(Resource resource, UrlHelper url)
 {
     Marker marker = CreateMarker(resource);
     marker.IconUrl = url.Content("~/Content/images/required-resource.png");
     return marker;
 }
        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();
            }
        }