Esempio n. 1
0
        public ActionResult CreateXML(Submission submission)
        {
            _context.Submission.Add(submission);
            _context.SaveChanges();

            //Use Namespace called :  System.IO
            string FileName = Path.GetFileNameWithoutExtension(submission.TemplateFile.FileName);

            //To Get File Extension
            string FileExtension = Path.GetExtension(submission.TemplateFile.FileName);

            FileName = DateTime.Now.ToString("yyyyMMdd") + "-" + FileName.Trim() + FileExtension;

            // If file with same name exists delete it
            if (System.IO.File.Exists(FileName))
            {
                System.IO.File.Delete(FileName);
            }

            //Get Upload path from Web.Config file AppSettings.
            string UploadPath = ConfigurationManager.AppSettings["UserImagePath"].ToString();

            System.IO.Directory.CreateDirectory(UploadPath + "Submissions\\" + submission.Id + "\\Definition\\");

            //Its Create complete path to store in server.
            submission.FilePath = UploadPath + "Submissions\\" + submission.Id + "\\Definition\\" + FileName;

            Debug.WriteLine(submission.FilePath);

            //To copy and save file into server.
            submission.TemplateFile.SaveAs(submission.FilePath);

            submission.Authorised = 0;


            List <string> headers = new List <string>();

            if (submission.CollectionFileTypeId == 3)
            {
                CSVRead csv = new CSVRead();

                headers = csv.readCSV(submission.FilePath);

                foreach (var temp in headers)
                {
                    TempData["message"] = TempData["message"] + "||" + temp;
                }
            }
            else if (submission.CollectionFileTypeId == 4)
            {
                XMLRead xml = new XMLRead();

                headers = xml.readXML(submission.FilePath);
            }

            TempData["message"] = "This Submission Has Been Created From Uploaded File: " + FileName + " If you do not click submit to save Submission Points before exiting this screen they will be lost";

            _context.SaveChanges();

            return(RedirectToAction("Submission", new RouteValueDictionary(
                                        new { controller = "Submission", action = "Submission", newSubmissionList = JsonConvert.SerializeObject(headers.ToList()), id = submission.Id })));
        }