Skip to content
May 10, 2011 / mattdyor

Android not showing up on Eclipse

Home > Menu > Settings > Applications > Development > check “USB debugging”

Of course! Seems like the thirteenth time I scrolled down looking for the device Eclipse could have figured this out:)

Advertisements
December 4, 2010 / mattdyor

Notes on Rails

This works along with Simply Rails: http://my.safaribooksonline.com/9780980455205

To start developing, go to terminal > documents/rails/rallywire then type ruby script/server, then you can visit it at http://0.0.0.0:3000

To play around with your application in the console, terminal to the directory and type ruby script/console

1.    Get to the irb
⁃    go to terminal and type irb
⁃    This lets you play with ruby
2.    Create the rails app
⁃    In terminal, go to the folder in which you want you application to be created (e.g., cd MattDyor/Documents/Rails is where I put all of my rails apps), and type rails APPLICATION_NAME
⁃    rails RallyWire
3.    Create the model
⁃    open terminal
⁃    terminal browse to the directory of the application (create it in finder if you need to)
⁃    terminal rails script/generate model RallyPoint name:string
⁃    fixed by running rails RallyWire – confirm and removei needed to copy the files from the archive over to get this to work
⁃    generating the model automatically adds an id, created_at, and updated_at
⁃    terminal rake db:migrate
4.    Naming conventions:
⁃    Use nouns as your class nouns (eg-use Subscription instead of Subscribe)
⁃    This means you are describing what you are storing, not what you are doing
⁃    Camelcase the class (Subscription, RallyPoint)
⁃    lowercase and pluralize the table (subscriptions, rally_points)
⁃    most references other than the class are lowercase (eg-the resources in the config)
⁃    instance variables can be small, but should be lower
⁃    attributes of the class are lower case
5.    Now add data to the model
⁃    terminal ruby script/console
⁃    rp = RallyPoint.new
⁃    rp.name = ‘Clubhouse Rally’
⁃    rp.save
6.    Now create the controller
⁃    ruby script/generate controller RallyPoints index (note the plural here and not above)
⁃    this will create our index page only
⁃    the controller that is created is rally_point
⁃    update the index method in the controller
⁃    def index
⁃    @rally_point = RallyPoint.find_by_name(‘Clubhouse Rally’)
⁃    end
7.    Now update the view file (index.html.erb)
⁃      <p><%= @rally_point.name%></p>
8.    Firing up the server
⁃    ruby script/server
⁃    you should be able to visit at 0.0.0.0:3000
9.    Add a form to create new entries
⁃    In textmate, go to app>views>XXX(datatype), right click and select new
⁃    Call the file new.html.erb
⁃    <% form_for @rally_point do |f|%>
⁃    <p>
⁃    name: <br />
⁃    <%= f.text_field :name%>
⁃    </p>
⁃    <p>
⁃    <%= submit_tag %>
⁃    </p>
⁃    <% end %>
⁃    update the controller–add a new method
⁃    @rally_point = RallyPoint.new
10.    Now add the helper URLs to map URLs to functions
⁃    go to config/routes.rb
⁃    add map.resources :rally_points
⁃    Now you should be able to visit 0.0.0.0:3000/rally_points/new
11.    A brief review
⁃    The route directory is /rally_points (plural)
⁃    In the config/routes.rb, there is the update above and the following
⁃    map.root :controller => “rally_points”
⁃    the class is RallyPoint, everything else is rally_point
12.    Create your create method in the controller
⁃    def create
⁃    @rally_point  = RallyPoint.new(params[:rally_point])
⁃    @rally_point.save
⁃    redirect_to rally_points_path
⁃    end
13.    Test your controller
⁃    navigate to /rally_point/new
⁃    create a record
⁃    fire up an irb console (terminal > cd to project directory, ruby script/console)
⁃    Story.find(2)
⁃    Story.find(:all)
⁃    Story.find(:all).last
⁃    Story.find(:first, :order =>  ‘id DESC’)
⁃    Story.find_by_name(‘Hello World Today’)
⁃    Story.find(:first, :order => ‘RANDOM()’)
14.    Create your layout
⁃    create, in ap>views>layouts, a layout named application.html.erb
⁃    standard XHTML web page with two extra fields: stylesheet under the title and yield in the body
⁃    <%= stylesheet_link_tag ‘style’ %>
⁃    this will point the style sheet to /public/stylesheets/style.css
⁃    <div id=”content”>
⁃    <%= yield %>
⁃    </div>
15.    Create your style sheet
⁃    body
⁃    {
⁃    background-color: #666;
⁃    margin: 15px 25px;
⁃    font-family: Helvetica, Arial, sans-serif;
⁃    }
⁃    #content
⁃    {
⁃    background-color: #fff;
⁃    border: 10px solid #ccc;
⁃    }
16.    Add some flash
⁃    In the style.css
⁃    #notification {
⁃    border: 5px solid #9c9;
⁃    background-color: #cfc;
⁃    padding: 5px;
⁃    margin:; 10px 0;
⁃    }
⁃    in the controller, add this line after the .save command
⁃    flash[:notice] = ‘Rally Point submission succeeded.’
⁃    add this to your index.html.erb
⁃    <% unless flash[:notice].blank? %>
⁃    <div id=”notification”><%= flash[:notice] %></div>
⁃    <% end %>
17.    Validation
⁃    add this to the model (app/models/rally_point.rb) inside the class
⁃    validates_presence_of :name
⁃    now update the controller>create method so that it does not redirect if there is a (validation) problem
⁃      if @rally_point.save
⁃            flash[:notice] = ‘Rally Point submission succeeded.’
⁃            redirect_to rally_points_path
⁃        else
⁃          render :action => ‘new’
⁃        end
⁃    add this to new.html.erb
⁃    <%= error_messages_for ‘rally_point’ %>
18.    Now create unit tests
⁃    unit tests are defined in test>unit>rally_point_test.rb
⁃    def test_should_not_be_valid_without_name
⁃    rp = RallyPoint.create(:name=>nil)
⁃    assert rp.errors.on(:name)
⁃    end
⁃    def test_should_create_story
⁃        rp=RallyPoint.create(:name=>’Big Juicy Unit Test’)
⁃        assert rp.valid?
⁃      end
⁃    run your unit tests in terminal with rake test:units
19.    Now create functional tests
⁃    functional tests are defined in test>functional?rally_points_controller_test.rb
⁃      def test_should_show_index
⁃        get :index
⁃        assert_response :success
⁃        assert_template ‘index’
⁃        assert_not_nil assigns(:rally_point)
⁃      end
⁃    run your functional tests with rake test:functionals
⁃        assert_select ‘form p’, :count => 3
⁃    Test the create method:
⁃      def test_should_add_rally_point
⁃    post :create, :rally_point => {
⁃          :name => ‘test from test’
⁃        }
⁃        #new_record? tests whether you have a new, unsaved record
⁃        assert ! assigns(:rally_point).new_record?
⁃        #i am not sure whether this actually saves it to the database…it does not appear to have
⁃        assert_redirected_to rally_points_path
⁃        assert_not_nil flash[:notice]
⁃      end
⁃    you can run all the tests with rake test
20.    Create the user security bits
⁃    ruby script/generate model User login:string password:string name:string email:string phone:string
⁃    go to the created model (db/migrate/XXXcreate user.rb) and add this line outside of the create_table and inside self.up:
⁃    add_column :rally_points, :user_id, :integer
⁃    add this to the self.down after drop_table
⁃    remove_column :stories, :user_id
⁃    rake db:migrate
⁃    in the user model, add has_many :rally_points
⁃    in the rally_point model, add belongs_to :user
⁃    Create the sessions controller for managing login (note: this is sessions…with an s, not sure why)
⁃    ruby script/generate controller Sessions new create destroy
⁃    including new create and destroy adds the methods and creates the templates
⁃    update routes.rb with this (note the singular–this is a singleton object, meaning that each user can have only one session)
⁃    map.resource :session
⁃    since this is singular, all of the urls will be singular (eg., session/new)
⁃    update the new.html.erb file
⁃    <% form_tag session_path do %>
⁃      <p>Please log in.</p>
⁃      <p>
⁃        <label>Username: </label>
⁃        <%= text_field_tag ‘ login’ %>
⁃      </p>
⁃      <p>
⁃        <label>Password: </label>
⁃        <%= password_field_tag ‘ password’ %>
⁃      </p>
⁃      <p><%= submit_tag ‘ login’ %></p>
⁃    <% end %>
⁃    update sessions_controller.rb (in app>controllers)
⁃      def create
⁃        @current_user = User.find_by_login_and_password(params[:login], params[:password])
⁃        if @current_user
⁃          session[:user_id] = @current_user.id
⁃          redirect_to rally_points_path
⁃        else
⁃          flash[:notice]=”Incorrect username or password. Please try again.”
⁃          render :action=>’new’
⁃        end
⁃      end
⁃    current_user = User. find session[:user_id]
21.    Apply a login filter
⁃    Add this code to the application_controller (app/controller/)
⁃      before_filter :fetch_logged_in_user
⁃        protected
⁃          def fetch_logged_in_user
⁃            return unless session[:user_id]
⁃            @current_user = User.find_by_id(session[:user_id])
⁃          end
⁃    Add this code to the application layout (app/views/layout)
⁃            <div id=”login_logout”>
⁃          <% if @current_user %>
⁃            Logged in as:
⁃            <%= @current_user.login %>
⁃            <em><%= link_to “(Logout) “, session_path,  :method => :delete %></em>
⁃          <% else %>
⁃            <em>Not logged in.</em>
⁃            <%= link_to ‘Login’, new_session_path %>
⁃          <% end %>
⁃        </div>
⁃    Add the formatting to the style sheet (public/stylesheets)
⁃    #login_logout {
⁃      float: right;
⁃      color: #999;
⁃      font-size: smaller;
⁃    }
⁃    Add this to the session_controller (app/controllers)
⁃      def destroy
⁃        session[:user_id] = @current_user = nil
⁃      end
⁃    Update your logout page
⁃    <h2>Logout successful</h2>
⁃    <%= link_to ‘Back to the home page’ , rally_points_path %>
⁃    Add Navigation to the template (within the body)
⁃      <ul id=”navigation”>
⁃        <li><%= link_to ‘Front page rally points’, rally_points_path %></li>
⁃        <li><%= link_to ‘Submit a new rally point!’, new_rally_point_path %></li>
⁃      </ul>
⁃    Helper methods for requiring login before visiting pages by updating the applicationcontroller (below the protected)
⁃    def logged_in?
⁃        ! @current_user. nil?
⁃      end
⁃      helper_method :logged_in?
⁃    NOTE: the second helper method is so that you can access this method in the views (first method is for access via controller)
⁃    And then add this that actually requires the user to login
⁃    def login_required
⁃        return true if logged_in?
⁃        session[:return_to] = request.request_uri
⁃        redirect_to new_session_path and return false
⁃      end
⁃    Update the rally_points_controller right under the class Intro
⁃     before_filter :login_required, :only => [ :new, :create ]
⁃    Replace the redirection line on sessions_controller with this:
⁃    session[:user_id] = @current_user.id
⁃          if session[:return_to]
⁃            redirect_to session[:return_to]
⁃            session[:return_to] = nil
⁃          else
⁃            redirect_to rally_points_path
⁃          end
⁃    Associate a user with a story by replacing the top line of the create method of the rally_points_controller with the following line
⁃     @rally_point = @current_user.rally_points. build params[:rally_point]
⁃    And show the user along with their story
⁃    <%= @rally_point.user.login %>
⁃    You may need to delete all your rally points or update them so that they have a
23.    Code snippets
⁃    <%= link_to @rally_point.name, @rally_point.link %>
⁃    <%= link_to “New”, new_rally_point_path %>
⁃    url helpers are rally_points_path [/rally_points], rally_point_path(@rally_point) [/rally_points/1], edit_rally_point(@rally_point) [/rally_points/1/edit)

April 1, 2010 / mattdyor

Everything you wanted to know about Ruby

Ruby

Classes always start with a capital letter
each class has attributes, specified by attr_accessor :name, :age, :gender

class Person
attr_accessor :name, :age, :gender
end

inheritance

class User < Person
attr_accessor :password
def hollar
puts “hollar”
end
end

iterate using do and end or { and }

“string”.scan(/./) {|x| puts x}

RAILS:

Overview:
Ruby and Ruby on Rails come pre-installed in the Mac
You will need to update Rails
..this requires XCode developer tools from Apple
..open Terminal, type “sudo gem update –system” enter “sudo gem install rails” enter “sudo gem update rake” enter “sudo gem install sqlite3-ruby” enter (i had to type “go”, but this might have been a rain dance)

To get to an interactive ruby session, type Terminal in spotlight (search in the top right corner) and type “irb” and hit enter.
Now you can type puts “hello world” and it should say hello world
You can also do some of the other ruby commands shown above

Terminal (like the command window)

cd = cd
ls = dir

Ruby Commands

This is a paint by numbers reference to help people remember steps needed to get a new machine or a new site. If you want to learn rails, go to http://www.ruby-doc.org/docs/

In Finder, create a new folder called RubyApps
Go to terminal and cd to RubyApps
type “rails XXX” where xxx is the app name you are going to build
BOOM…a lot of data starts flying by as Rails chunks out the skeleton of your app.

Random notes: if you want to get a copy of the documentation for rails, you can navigate to your newly created app directory (XXX) in Terminal and type in “rake rails:freeze:gems” enter “rake doc:rails” enter – after a few minutes of building the docs, you can navigate to /doc/api/index.html and check out the docs (feel free to move it to a location you can more readily find…these docs are not specific to the application but are for Rails generally)

Terminal: navigate to XXX and type “ruby script/server -d” (if you have Mongrel, OS will use that, otherwise, it will use WEBrick which is installed by default) To get Mongrel, type “gem install mongrel”

Now, in a browser you can check out http://localhost:3000 (localhost is the a reference to the name of the machine you are on…it a web server’s way of saying “me”).

In Terminal, To create a controller, navigate to XXX and type “ruby script/generate controller Home”

In finder,  navigate to XXX/app/controllers/home_controller.rb

Open this file up (if it is not opening in the editor of your choice, click on the more info > open with option). Add a action of your choice, such as “def hello” enter “end”

In finder, go to XXX/public/ and rename or delete index.html

In finder, go to XXX/app/views/hello and create a file called “hello.html.erb” (the name of the view corresponds to the action)

In terminal, type “script/server” to fire up the webserver

In web browser, navigate to localhost:3000/home/hello

February 21, 2010 / mattdyor

Creating an MVC + ASP.net + Azure Storage Table Site in 10 minutes

Get Started

  • Get the proper software (Visual Studio 2010, possibly need cloud computing tools…not sure what is in the box)
  • File > New Project > Cloud Service
    • Call the solution “XXX” (where XXX is the name of your site, like RallyWire for http://www.RallyWire.com)
    • The solution name (eg-XXX) will be the namespace for your solution. (not correct)
    • A “New Cloud Service Project” window will appear — at least add an ASP.net MVC 2 Web Role and hit OK
  • Accept defaults on the “Create Unit Test Project” window and hit OK

Build your model 

  • Right click on References > Add Reference > .NET > System.Data.Services.Client
  • Right click the Models folder, add > class
  • Name the class YYY (where YYY is the singular form of the class, such as RallyPoint for www.RallyWire.com)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.WindowsAzure.StorageClient;
using Microsoft.WindowsAzure;
using System.ComponentModel.DataAnnotations;
using System.Web.Security;

namespace MvcWebRole1.Models
{
    public class YYY : TableServiceEntity
    {
        public YYY(string partitionKey, string rowKey)
            : base(partitionKey, rowKey)
        {
        }

        public YYY()
            : base()
        {
            PartitionKey = string.Empty;
            RowKey = Guid.NewGuid().ToString();
        }

        public string Name
        {
            get;
            set;
        }

        //when you add a new property, you must include this property in the edit method below or the value will not be updateable.
        //search for ITEMTOEDIT_UPDATE
    }

    //this is the context - akin to a data connection between the model and azure table storage
    /// <summary>
    /// DO NOT USE THIS FROM THE CONTROLLER. Use the YYYDataSource instead
    /// </summary>
    public class YYYData : TableServiceContext
    {

        public YYYData(string baseAddress, StorageCredentials credentials)
            : base(baseAddress, credentials)
        {
        }

        public const string YYYTableName = "YYYTable";

        public IQueryable<YYY> YYYTable
        {
            get
            {
                return this.CreateQuery<YYY>(YYYTableName);
            }
        }
    }
    /// <summary>
    /// This is the bridge between the controller and the model; you drop the following code on your controller to implement
    /// var svc = new Models.YYYDataSource();
    /// </summary>
    public class YYYDataSource
    {
        private YYYData _ServiceContext = null;

        public YYYDataSource()
        {
            var storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
            storageAccount.CreateCloudTableClient().CreateTableIfNotExist(YYYData.YYYTableName);
            _ServiceContext = new YYYData(storageAccount.TableEndpoint.ToString(), storageAccount.Credentials);
        }

        private IQueryable<YYY> YYYTable
        {
            get
            {
                return _ServiceContext.YYYTable;
            }
        }

        public IEnumerable<YYY> Select()
        {
            var results = from c in _ServiceContext.YYYTable
                          select c;

            var query = results.AsTableServiceQuery<YYY>();
            var queryResults = query.Execute();

            return queryResults;
        }

        public void Edit(string id, YYY itemToEdit)
        {
            //var svc = new Models.YYYDataSource();
            var q = (from rp in YYYTable
                     where rp.RowKey == id
                     select rp).Single();

            //ITEMTOEDIT_UPDATE
            q.Name = itemToEdit.Name;

            _ServiceContext.UpdateObject(q);
            _ServiceContext.SaveChanges();

        }

        public void Delete(string id, YYY itemToEdit)
        {
            //var svc = new Models.YYYDataSource();
            var q = (from rp in YYYTable
                     where rp.RowKey == id
                     select rp).Single();
            _ServiceContext.DeleteObject(q);
            _ServiceContext.SaveChanges();
        }

        public void Insert(YYY newItem)
        {
            if (newItem.PartitionKey == null)
                newItem.PartitionKey = "primaryPartition";
            _ServiceContext.AddObject(YYYData.YYYTableName, newItem);
            _ServiceContext.SaveChanges();
        }
    }
}

Update WebRole.cs

  • In WebRole.cs in your MVCWebRole1 project, add a using Microsoft.Azure directive and replace your current OnStart() method with the following
        public override bool OnStart()
        {
            DiagnosticMonitor.Start("DiagnosticsConnectionString");
            RoleEnvironment.Changing += RoleEnvironmentChanging;
            CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
            {
                configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));
                RoleEnvironment.Changed += (sender, arg) =>
                {
                    if (arg.Changes.OfType<RoleEnvironmentConfigurationSettingChange>()
                        .Any((change) => (change.ConfigurationSettingName == configName)))
                    {
                        if (!configSetter(RoleEnvironment.GetConfigurationSettingValue(configName)))
                        {
                            RoleEnvironment.RequestRecycle();
                        }
                    }
                };
            });
            return base.OnStart();
        }

Update Configuration

  • Finally, you are ready to point your Model at the right data store. Start by using local storage, which involves right clicking on the MVCWebRole1 role in the XXX project, selecting Properties > Settings > Add Setting, Name = DataConnectionString, Type = ConnectionString, value = UseDevelopmentStorage=true (you can specify this last parameter by clicking the elipses, but you do have to remember what you named your connection string in your YYY.cs file)
  • All of these steps are described in great detail at http://blogs.msdn.com/jnak/archive/2010/01/06/walkthrough-windows-azure-table-storage-nov-2009-and-later.aspx (steps 1-21), but then that article goes off to implement a grid view so it will not help you beyond this point.
  • Save and Build.

Update your controller 

  • In the controllers folder in the MVCWebRole1 folder, overwrite the original code with the following code: 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using MvcWebRole1.Models;
using System.Collections;
using System.Linq;
namespace MvcWebRole1.Controllers
{
    public class HomeController : Controller
    {
        //private MvcWebRole1.Models.YYYDataSource _entities = new YYYDataSource();
        YYYDataSource svc = new Models.YYYDataSource();
        //
        // GET: /Home/
        public ActionResult Index()
        {
            return View(svc.Select());
        }
        //
        // GET: /Home/Details/5
        //On the details page, add a link to get you to the delete (just copy the edit page)
        public ActionResult Details(string id)
        {
            var originalItem = svc.Select().First(i => i.RowKey == id);
            return View(originalItem);
        }
        //
        // GET: /Home/Create
        public ActionResult Create()
        {
            return View();
        }
        //
        // POST: /Home/Create
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create([Bind(Exclude = "RowKey")]YYY itemToCreate)
        {
            svc.Insert(itemToCreate);
            return RedirectToAction("Index");
        }
        //
        // GET: /Home/Edit/5
        public ActionResult Edit(string id)
        {
            var originalItem = svc.Select().First(i => i.RowKey == id);
            return View(originalItem);
        }
        //
        // POST: /Home/Edit/5
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Edit(string id, YYY itemToEdit)
        {
            var originalItem = svc.Select().First(i => i.RowKey == id);
            svc.Edit(id, itemToEdit);
            return RedirectToAction("Index");
        }
        //
        // GET: /Home/Delete/5
        //To generate this page, right click, Add View, add it as an update page and remove all of the fields and just have a button that says confirm and cancel
        public ActionResult Delete(string id)
        {
            var originalItem = svc.Select().First(i => i.RowKey == id);
            return View(originalItem);
        }
        //
        // POST: /Home/Delete/5
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Delete(string id, YYY itemToDelete)
        {
            svc.Delete(id, itemToDelete);
            return RedirectToAction("Index");
        }
    }
}

Now Create Views

  • Build your solution. (i threw an error on one of the tests for an about page, so I deleted the failing test)
  • Delete About and Index from the Views > Home folder (we are going to create new ones)
  • Right click on Index, select Add View > Strongly Typed View > Select “MvcWebRole1.Models.YYY” from the top drop down and “List” from the bottom, Click Add.
  • Open the Index view under the home folder. You can modify the view to suit your needs (eg-remove columns that your visitors do not care about). Also, modify the links at the bottom of the page as follows:

<%= Html.ActionLink(“Edit”, “Edit”, new {  id=item.RowKey}) %> |
<%= Html.ActionLink(“Details”, “Details”, new { id = item.RowKey })%> |
<%= Html.ActionLink(“Delete”, “Delete”, new { id = item.RowKey })%>

  • Back on the HomeController, right click the delete method, and select Add View. Select strongly typed view and, in the content drop down, select Details.
  • On the Delete view, add the following code (probably below the fieldset):
    <% using (Html.BeginForm()) {%>
        <fieldset>
            <p>
                <input type="submit" value="Delete" />
            </p>
        </fieldset>
    <% } %>
  • You will need to uncomment and modify the Edit ActionLink to say:
id=Model.RowKey
  • Create views for Edit and Details. These are straight forward. Remember to uncomment and modify the id=Model.RowKey on the Details page.

Go Live

  • You are now ready to MVC out. Go to www.azure.com and get an account.
  • You need to get your keys from Azure and update your Web Config (see Update Configuration above…but use the key from your Azure storage account).
  • Right click on the XXX project and select publish. This will open a folder on your machine and a web page. Use the web page to upload the items in the folder.
  • Note: Azure charges you per hour that your instance exists, so you need to either buy the $60/month version, or delete (not suspend) the active instance (you get 25 hours for free in a month…that is one day).
February 20, 2010 / mattdyor

Adding HTTPS / SSL / Secure endpoint to azure

http://blogs.msdn.com/jnak/archive/2009/12/01/how-to-add-an-https-endpoint-to-a-windows-azure-cloud-service.aspx

After you upload the certificate to azure, you will have to suspend and delete the instance or you will get one of the unintelligible azure errors:

Different number of input endpoints for role Dr. Watson Diagnostic ID: 825d94c9-ca91-4b09-9a76-5a6ba92a2af0

February 13, 2010 / mattdyor

Creating REST APIs for ASP.net + MVC

This is a stub. I will comment on this post when I finish implementing. Looks promising.

February 9, 2010 / mattdyor

Creating an MVC + ASP.net + SQL Site in 10 minutes

  • Get the proper software (___)
  • File > New Project > Web > Asp.net MVC 2 Web App
    • Call the solution “MVCPlayground
    • The solution name (eg-MVCPlayground) will be the namespace for your solution.
  • In solution explorer, right click App Data > Add > New Item > Data > Sql Server database > IdeaDB
  • In server explorer, expand IdeaDB (click on the +), right click Tables, add new table
    • If solution explorer is not visible, View>Server Explorer.
  • Call it IdeaTable
    • You could call it Idea, but the term becomes overloaded…we may change this.
  • In solution explorer, right click Models > Add > New Item
  • Select ADO.net Entity Data Model
  • Name the file DataModel.edmx
    • Generate from DB, select IdeaDB.mdf, the the check checked.
    • Name the thing (bottom box) IdeaDBEntities
    • Select (check box) tables and keep checkboxes checked
    • Model Namespace should be Model
    • Rename the entity from IdeaTable to Idea
  • Delete Controllers > Home Controller
  • Delete Views > Home > Index and About
  • Delete Test > Controllers > Home
  • Right Click controllers > Add > Controllers and name it HomeControllers, keep the checks checked
  • In HomeController.cs under “public class…” add “private IdeaDBEntities _entities = new IdeaDBEntities();”  and hit CTRL+. on IdeaDBEntities to add the using reference.
  • Build Solution (this makes the classes available for follow on steps)
  • For Index
    • Make it “return View(_entities.Ideas);”
    • Right click index, check create strongly typed view
    • Select MVCPlayground.models.idea (this is solutionName.ModelNamespace)
    • For View Content, select List
  • Duplicate the above steps for create, but select “create” from drop down and do not update the “return View();”
  • On the create view…