Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [HttpPost]
- public ActionResult Create(UploadViewItem viewItem, HttpPostedFile postedFile)
- {
- if (!ModelState.IsValid)
- {
- return View();
- }
- var result = AddInstanties(postedFile.InputStream, viewItem.StartDatum, viewItem.EindDatum);
- return View(viewItem);
- }
- public class UploadViewItem : IValidatableObject
- {
- public UploadViewItem()
- {
- EindDatum = DateTime.Now;
- StartDatum = DateTime.Now;
- Result = new UploadResultItem();
- }
- [Required(ErrorMessage = "Bestand kan niet worden gevonden")]
- public string File { get; set; }
- [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")]
- [Required(ErrorMessage = "Startdatum is verplicht")]
- [DisplayName("Startdatum")]
- public DateTime StartDatum { get; set; }
- [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")]
- [Required(ErrorMessage = "Einddatum is verplicht")]
- [DisplayName("Einddatum")]
- public DateTime EindDatum { get; set; }
- public UploadResultItem Result { get; set; }
- public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
- {
- if (StartDatum.CompareTo(EindDatum) > 0)
- {
- yield return new ValidationResult("Startdatum moet voor Einddatum zijn", new string[] { "StartDatum", "EindDatum" });
- }
- }
- }
- public class UploadResultItem
- {
- public UploadResultItem()
- {
- FormatErrorLine = 0;
- AmountOfAddedItems = 0;
- WrongCursusInstanties = null;
- }
- public int FormatErrorLine { get; set; }
- public int AmountOfAddedItems { get; set; }
- public WrongCursusDTO[] WrongCursusInstanties { get; set; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement