Exemple #1
0
        public JsonResult SaveTest(string data)
        {
            if (Session["USER_LOGIN"] == null)
            {
                return(Json(RedirectToAction("Login", "Account")));
            }
            PageObject po = new PageObject();

            po.User = Session["USER_LOGIN"] as AppUser;
            Sample s = new Sample();

            s.UserLanguage = po.User.Language;
            SampleTestMsgWarpper ow = JsonConvert.DeserializeObject <SampleTestMsgWarpper>(data);
            ResultAPI            ra = s.UpdateTest(ow.form[0], ow.SUB_RES);

            if (ra.ResultStatus.ToUpper().Equals("OK"))
            {
                s = s.GetProductSamples(ow.form[0].hdnQaDOCNO);
                if ((null != s) && (null != s.MED_TRANSSAMPLEQA_SUBFORM) && (s.MED_TRANSSAMPLEQA_SUBFORM.Count > 0))
                {
                    foreach (Sample_QA item in s.MED_TRANSSAMPLEQA_SUBFORM)
                    {
                        item.DOCNO    = s.DOCNO;
                        item.SUPNAME  = s.SUPNAME;
                        item.PARTNAME = s.PARTNAME;
                    }
                    ra.ResultData = s;
                }
                if (null != s && null != s.MED_EXTFILES_SUBFORM && s.MED_EXTFILES_SUBFORM.Count > 0)
                {
                    foreach (SampleAttachments item in s.MED_EXTFILES_SUBFORM)
                    {
                        string[] arr = item.EXTFILENAME.Split('\\');
                        if (string.IsNullOrEmpty(arr[arr.Length - 1]))
                        {
                            //item.FILE_NAME = arr[0];
                            item.FOLDER = arr[1];
                        }
                        else
                        {
                            switch (arr.Length)
                            {
                            case 3:
                                item.FOLDER = arr[arr.Length - 2];
                                break;

                            case 4:
                                item.FOLDER = arr[arr.Length - 3] + @"\" + arr[arr.Length - 2];
                                break;

                            default:
                                item.FOLDER = arr[arr.Length - 2];
                                break;
                            }
                        }
                    }
                }
            }
            return(Json(ra));
        }
Exemple #2
0
        public JsonResult UploadFiles()
        {
            if (Session["USER_LOGIN"] == null)
            {
                return(Json(RedirectToAction("Login", "Account")));
            }
            PageObject po = new PageObject();

            po.User = Session["USER_LOGIN"] as AppUser;
            HttpFileCollectionBase files = Request.Files;
            SampleTestMsgWarpper   ow    = JsonConvert.DeserializeObject <SampleTestMsgWarpper>(Request.Form[0]);

            ResultAPI ra = null;

            //string decodedUrl = HttpUtility.UrlDecode();
            ow.files = new List <Attachments>();
            if (Request.Files.Count > 0)
            {
                //var file = Request.Files[0];
                Attachments a = null;
                for (int i = 0; i < Request.Files.Count; i++)
                {
                    var file = Request.Files[i];
                    a = new Attachments();
                    a.UserLanguage = po.User.Language;
                    if (file != null && file.ContentLength > 0)
                    {
                        string fileName = Path.GetFileName(file.FileName);
                        //string dir = Path.Combine(Server.MapPath("~/SupDocs/" + ow.form[0].hdnQaSUPNAME + "/" + ow.form[0].hdnQaDOCNO));
                        string dir = Path.Combine(Server.MapPath("~/SupDocs/" + ow.form[0].hdnQaSUPNAME));
                        //var path = Path.Combine(Server.MapPath("~/SupDocs/" + ow.form[0].hdnQaSUPNAME + "/" + ow.form[0].hdnQaDOCNO + "/"), ow.form[0].hdnQaDOCNO + "_" + fileName);
                        var path = Path.Combine(Server.MapPath("~/SupDocs/" + ow.form[0].hdnQaSUPNAME), ow.form[0].hdnQaDOCNO + "_" + fileName);
                        if (!Directory.Exists(dir))
                        {
                            Directory.CreateDirectory(dir);
                        }

                        a.FILE_NAME   = fileName.Split('.')[0];
                        a.EXTFILENAME = path;
                        file.SaveAs(path);
                        ow.files.Add(a);
                    }
                }

                ra = a.UploadSampleAttachments(ow.form[0], ow.files);
            }
            return(Json(ra));
        }