Here is my controller code. I try to create application with MVC N-layer pattern. I asked my buddy for a shot review, and he said, "You should separate logic from controller". But my controller only work as a ViewModel creator. I'm sure I must not create ViewModel from BusinessLayer. I need to pass data in DTO like I did here. But what about logic that takes data from DTO and puts it in ViewModel with some rules? I completely misunderstand and need assistance.
public class HomeController : Controller
{
public ActionResult Index()
{
var uploadedImages = UploadedImageHandler.GetAllUploadedImages();
var model = new IndexViewModel(uploadedImages);
return View(model);
}
[HttpPost]
public void SetDescription(string description, int id)
{
UploadedImageHandler.SetDescription(description, id);
}
[HttpPost]
[ValidateAntiForgeryToken]
public JsonResult UploadImage(HttpPostedFileBase file)
{
var result = UploadedImageHandler.UploadFile(file);
JsonResult json;
if (result != null)
{
var uploadImageViewModel = new UploadedImagesViewModel
{
Compression = result.Compression,
DateTime = result.DateTime.HasValue ? result.DateTime.Value.ToString("f") : null,
Description = result.Description ?? "",
ExifVersion = result.ExifVersion,
ExposureTime = result.ExposureTime,
GpsLatitude = result.GpsLatitude,
GpsLongitude = result.GpsLongitude,
ImagePath = result.ImagePath,
Manufacturer = result.Manufacturer,
Model = result.Model,
UploadedImageId = result.UploadedImageId
};
var uploadResult = new UploadResultViewModel
{
Preview = new PreviewViewModel {Id = result.UploadedImageId, PreviewPath = result.PreviewPath},
UploadedImage = uploadImageViewModel
};
json = new JsonResult
{
Data = uploadResult,
ContentType = "text/html"
};
}
else
{
json = new JsonResult
{
ContentType = "text/html"
};
}
return json;
}
}