Showing posts with label MVC. Show all posts
Showing posts with label MVC. Show all posts

Thursday, August 5, 2010

LINQ to SQL

Well, I'm cracking on nicely now - though not getting as much time to spend on the development as I would have liked, so I'll make this brief.

If you're looking for an introduction to .NET's LINQ technology, you could do far worse that browse here:

From an MVC point of view it's a little out-of-date in its use of code-behind files, which I don't believe are supported any more, but the demonstration is excellent. It even gave me one of those 'wow' moments.

There are still a few unknowns for me to work through, but once I have a mature, working example of the code I'm using in the Resource Manager application, I'll post it here.

Monday, July 26, 2010

ASP.net MVC file upload

Today's task was simply: upload a file from the local machine and save it out to the 'webserver'.

To do this I created a new controller HomeController.cs and a new View, Home\Index.aspx

The important bit of Home\Index.aspx looked like this:
  <form action="/Home/AddProjectPlan" method="post" enctype="multipart/form-data">
         <label for="file">Filename:</label>
         <input type="file" name="file" id="file" />
       <input type="submit" name="submit" value="Submit" />
     </form>


To HomeController.cs I added the System.IO namespace, and the following method:

[HttpPost, ActionName("AddProjectPlan")] //don't really understand this?
public void Add()
{
foreach (string file in Request.Files) //only posting one element from the form, but this would work for many
{
HttpPostedFileBase postedFile = Request.Files[file] as HttpPostedFileBase;

if (postedFile.ContentLength > 0) //if file not empty
{
string savedFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "temp\\", Path.GetFileName(postedFile.FileName));
postedFile.SaveAs(savedFileName);

// Let user know that it all worked and where the file was saved
Response.Write("File submitted to " + savedFileName);
}
else
{
// Let user know there was a problem
Response.Write("No file submitted or file zero length");
}
}
}

There are a few things in there I don't 100% understand, particularly what the [HttpPost,...] notation at the top means. I tried adding this all into a separate method AddProjectPlan, but for some reason the form post couldn't find this. If anyone has any ideas or decent tutorials, please let me know.

Useful links
While doing this work I found the following very useful:

(and less so)

A Start

Hello,

Day one on the new software development project, ABLE. The plan is to create a suite of quality, low cost, enterprise level project management software - and have a lot of fun while doing it. As a contract Project Manager I'm pretty confident I know the market, as an ex-coder I'm pretty rusty and very out of date.

This blog is initially about the development of the software and the useful online resources I've used to to help me get back up to speed. Some community involvement through this blog would be excellent if you feel like chipping in.

Right, an overview:

Product Summary
In the first instance I plan to develop a thin vertical slice of end to end functionality that allows multiple Microsoft Project Plans to be loaded in to a web interface, and then display the resource utilisation over different time-frames (e.g. days, weeks, months) in a graph format. For v1 support will only be MS Project files saved as XML.
This solves the problem that most mid sized organisations do not want to purchase MS Project Server and this resource view functionality is very useful at a strategic level.
From an ABLE point of view, this implements a lot of code that can be built on for future 'vertical slices' that will extend functionality.

Technology choice
My background is MS, so I've gone for a C# ASP.NET MVC implementation. As I'm using the free Microsoft Visual Web Developer 2010 Express, I've currently opted for xUnit.net for my unit testing. However, I think it will be a while before that gets implemented as I have a few more basic functionality issues to solve first...


If anyone has any comments or suggestions then I'd love to hear about them. I'm doing this as much for fun of coding as any serious attempt (yet) to make a career, so the geekier the better. I'm not keen to hear the 'there's x product that already does this' - I know there's a lot of stuff out there, but see above comment about doing this for fun ;-)

Thanks,

Jonathan