public ActionResult Create(Organization model)
 {
     try
     {
         var context = new DataContextContainer();
         context.AddToOrganizations(model);
         context.SaveChanges();
         return RedirectToAction("Index");
     }
     catch
     {
         return View();
     }
 }
        public ActionResult Delete(Organization model)
        {
            try
            {
                var context = new DataContextContainer();

                context.DeleteObject(model);
                context.SaveChanges();
                return RedirectToAction("Index");

            }
            catch
            {

            }

            return RedirectToAction("Index");
        }
Esempio n. 3
0
 /// <summary>
 /// Create a new Organization object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="contactEmail">Initial value of the ContactEmail property.</param>
 public static Organization CreateOrganization(global::System.Int32 id, global::System.String name, global::System.String contactEmail)
 {
     Organization organization = new Organization();
     organization.Id = id;
     organization.Name = name;
     organization.ContactEmail = contactEmail;
     return organization;
 }
Esempio n. 4
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Organizations EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToOrganizations(Organization organization)
 {
     base.AddObject("Organizations", organization);
 }
        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();
            }
        }
        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();
            }
        }
 public ActionResult Edit(Organization model)
 {
     try
     {
         // TODO: Add update logic here
         var context = new DataContextContainer();
         Organization organization = context.Organizations.Where(X => X.Id == model.Id).FirstOrDefault();
         organization.Name  = model.Name;
         organization.ContactEmail = model.ContactEmail;
         context.SaveChanges();
         return RedirectToAction("Index");
     }
     catch
     {
         return RedirectToAction("Index");
     }
 }