Пример #1
0
        public ActionResult AddFile(IndexViewModel viewModel)
        {
            ModelState.Clear();
            var validation = TryValidateModel(viewModel);
            var errors     = (from modelstate in ModelState.Values from error in modelstate.Errors select error.ErrorMessage).ToList();

            if (!validation)
            {
                return(Json(errors.ToArray()));
            }

            var pic  = Path.GetFileName(viewModel.File.FileName);
            var name = User.Identity.Name.Split('@')[0];
            var path = Path.Combine(Server.MapPath("/bewijzen/" + name), pic);

            if (System.IO.File.Exists(path))
            {
                errors.Add("FileName does already exist!");
                return(Json(errors.ToArray()));
            }
            viewModel.File.SaveAs(path);

            var dbBewijs = new Evidence
            {
                Path        = pic,
                Description = viewModel.Description
            };

            _studentFacade.InsertEvidence(dbBewijs, User.Identity.Name);
            errors.Add("Finish");
            return(Json(errors.ToArray()));
        }