MVC Newbie.
After an edit I want to save the changes and then update an image to be stored in a different class.
I have now debugged the inline code and realize I will need it in another controller. So how do I turn it into a method? Where do I put it (create a folder[mymethods]? There is probably some preferred place to keep these custom methods. In my VB days I would write this as a function or subroutine, now I see this as some type of action result. I've seen a list of several, would this be a fileresult()?
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(Task task)
{
if (ModelState.IsValid)
{
db.Entry(task).State = EntityState.Modified;
db.SaveChanges();
var Mytopleft = 0;
var Mytext = "";
Bitmap mybmp = new Bitmap(10, 400);
Graphics g = Graphics.FromImage(mybmp);
string[] chunks = Mytext.Split(',');
var brush = new SolidBrush(Color.Black);
SolidBrush[] brushes = new SolidBrush[]
{ new SolidBrush(Color.OldLace),
new SolidBrush(Color.LightSlateGray),
new SolidBrush(Color.LightBlue),
new SolidBrush(Color.LightGreen)
};
int c = 0;
foreach (var titem in ViewBag.Task)
{
if (titem.SStart == null)
{ c = 0; }
else if (titem.SStart != null && titem.SEnd == null)
{ c = 1; }
else if (titem.SEnd != null && titem.SCert == null)
{ c = 2; }
else if (titem.SCert != null)
{ c = 3; }
g.FillRectangle(brushes[c], Mytopleft, 0, 10, 10);
Mytopleft += 10;
}
mybmp.Save("C:\\temp\\lot1.bmp", System.Drawing.Imaging.ImageFormat.Gif);
return RedirectToAction("Index");
}
ViewBag.BuilderID = new SelectList(db.Builders, "BuilderID", "BName", task.BuilderID);
ViewBag.LotID = new SelectList(db.Lots, "LotID", "LotName", task.LotID);
return View(task);
}
Later I will write the bitmap into a db field.
So I create a method, something like Makegraph(Viewbag). Would I call it with a public FileResult makegraph(ViewBag)? Will I need to add a reference in the controller? Does it return(image)?
And most important where can I learn about this? MSDN doesn't seem to have meaningful examples.
Thank goodness for CODEPROJECT. and STACKOVERFLOW