This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Oct 11th, 2012  |  syntax: C#  |  size: 2.14 KB  |  views: 54  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.         [HttpPost]
  2.         public ActionResult Create(UploadViewItem viewItem, HttpPostedFile postedFile)
  3.         {
  4.             if (!ModelState.IsValid)
  5.             {
  6.                 return View();
  7.             }
  8.  
  9.             var result = AddInstanties(postedFile.InputStream, viewItem.StartDatum, viewItem.EindDatum);
  10.             return View(viewItem);
  11.         }
  12.  
  13.  
  14.  
  15.  
  16.  
  17.     public class UploadViewItem : IValidatableObject
  18.     {
  19.         public UploadViewItem()
  20.         {
  21.             EindDatum = DateTime.Now;
  22.             StartDatum = DateTime.Now;
  23.             Result = new UploadResultItem();
  24.         }
  25.  
  26.         [Required(ErrorMessage = "Bestand kan niet worden gevonden")]
  27.         public string File { get; set; }
  28.  
  29.         [RegularExpression(@"^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d$", ErrorMessage = "Datum moet voldoen aan het volgende format: dd-mm-yyyy")]
  30.         [Required(ErrorMessage = "Startdatum is verplicht")]
  31.         [DisplayName("Startdatum")]
  32.         public DateTime StartDatum { get; set; }
  33.  
  34.         [RegularExpression(@"^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d$", ErrorMessage = "Datum moet voldoen aan het volgende format: dd-mm-yyyy")]
  35.         [Required(ErrorMessage = "Einddatum is verplicht")]
  36.         [DisplayName("Einddatum")]
  37.         public DateTime EindDatum { get; set; }
  38.  
  39.         public UploadResultItem Result { get; set; }
  40.  
  41.         public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
  42.         {
  43.             if (StartDatum.CompareTo(EindDatum) > 0)
  44.             {
  45.                 yield return new ValidationResult("Startdatum moet voor Einddatum zijn", new string[] { "StartDatum", "EindDatum" });
  46.             }
  47.         }
  48.     }
  49.  
  50.     public class UploadResultItem
  51.     {
  52.         public UploadResultItem()
  53.         {
  54.             FormatErrorLine = 0;
  55.             AmountOfAddedItems = 0;
  56.             WrongCursusInstanties = null;
  57.         }
  58.  
  59.         public int FormatErrorLine { get; set; }
  60.         public int AmountOfAddedItems { get; set; }
  61.         public WrongCursusDTO[] WrongCursusInstanties { get; set; }
  62.     }
clone this paste RAW Paste Data