public async Task <ActionResult> FormTeacher()
        {
            var    myForm    = new FormDataViewModel();
            string username  = User.Identity.GetUserName();
            var    className = Db.AssignFormTeacherToClasses.Where(x => x.Username.Equals(username))
                               .Select(s => s.ClassName)
                               .FirstOrDefault();

            myForm.AssignedClasses = await Db.AssignedClasses.Where(x => x.ClassName.Equals(className) && x.TermName.Equals("First") &&
                                                                    x.SessionName.Equals("2016-2017")).ToListAsync();

            ViewBag.SubjectCode = new SelectList(Db.Subjects, "CourseName", "CourseName");
            ViewBag.StudentId   = new SelectList(Db.Students, "StudentID", "FullName");
            ViewBag.SessionName = new SelectList(Db.Sessions, "SessionName", "SessionName");
            ViewBag.ClassName   = new SelectList(Db.Classes, "FullClassName", "FullClassName");
            // return View(await Db.Classes.ToListAsync());
            return(View(myForm));
        }
        public async Task <IActionResult> Form(FormDataViewModel dta)
        {
            var frmId       = dta.FormId;
            var obj         = JObject.Parse(dta.FormValues);
            var namesString = dta.FilesName.Remove(dta.FilesName.LastIndexOf('='));
            var namesList   = namesString.Split('=');
            Dictionary <string, string> namesDic = new Dictionary <string, string>();

            foreach (var row in namesList)
            {
                var item = row.Split('|');
                namesDic.Add(item[0], item[1]);
            }
            if (dta.Files != null)
            {
                foreach (var file in dta.Files)
                {
                    var currentfileName = file.FileName;
                    var names           = namesDic.Where(x => x.Value == currentfileName);
                    if (names.Any())
                    {
                        var name        = names.FirstOrDefault();
                        var gotName     = name.Key;        //Title of field
                        var gotFileName = currentfileName; //Save This File and return address
                        //Upload Image

                        var fileLink = String.Format("<a href='{0}' target='_blank'>دانلود فایل</a>", "Url of Uploaded Image");
                        obj.Add(gotName, fileLink);
                    }
                }
            }
            _db.FormDatas.Add(new FormData()
            {
                FormValues = JsonConvert.SerializeObject(obj),
                FormId     = frmId
            });
            await _db.SaveChangesAsync();

            var forms = await _db.Forms.Include("Fields").FirstOrDefaultAsync(x => x.Id == frmId);

            return(View(forms));
        }
        public async Task <IActionResult> UploadZip(FormDataViewModel formData)
        {
            if (ModelState.IsValid)
            {
                IFormFile file = formData.File;
                //copy file to server
                if (file.Length > 0)
                {
                    try
                    {
                        //get a temp location path to copy the file
                        var filePath = Path.GetTempFileName();
                        using (var stream = new FileStream(filePath, FileMode.Create))
                        {
                            await formData.File.CopyToAsync(stream);
                        }
                        //unzip it
                        string unzipedPath = Path.GetTempPath();
                        ZipFile.ExtractToDirectory(filePath, unzipedPath, true);
                        //get JSON
                        string   targetPath = string.Concat(unzipedPath, Path.GetFileNameWithoutExtension(file.FileName));
                        TreeNode root       = new TreeNode(new DirectoryInfo(targetPath));
                        var      json       = JsonConvert.SerializeObject(root);
                        //post the file
                        StatusDTO response = await _dmsService.PostFile(json, formData.Username, formData.Password);

                        ViewData[(response.IsSuccess) ? "Success" : "Error"] = response.Message;
                    }
                    catch (Exception)
                    {
                        ViewData["Error"] = "Error occurred while submitting zip file.";
                    }
                }
            }

            return(View("Index", formData));
        }
Exemple #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FormDataContent"/> class.
 /// </summary>
 /// <param name="formDataContentViewModel">The model view.</param>
 public FormDataContent(FormDataViewModel formDataContentViewModel)
 {
     DataContext = formDataContentViewModel;
 }
Exemple #5
0
 public FormGeneratorActionResponse GenericAction <TA>(TA viewModel, FormDataViewModel dataViewModel)
 {
     throw new NotImplementedException();
 }
Exemple #6
0
 public FormGeneratorActionResponse Cancel <TC>(TC viewModel, FormDataViewModel dataViewModel)
 {
     throw new NotImplementedException();
 }
Exemple #7
0
 public FormGeneratorActionResponse Submit <SubmitFormDataViewModel>(SubmitFormDataViewModel viewModel, FormDataViewModel dataViewModel)
 {
     throw new NotImplementedException();
 }