예제 #1
0
        public async Task <IActionResult> SaveInfoSupervisor()
        {
            UserModel       userSession       = HttpContext.Session.Get <UserModel>("UserSesion");
            AssignmentModel asign             = HttpContext.Session.Get <AssignmentModel>("ReporModelSupervisor");
            ReportModel     reportModelResult = null;

            if (asign.Report == null)
            {
                reportModelResult = new ReportModel();
            }
            else
            {
                reportModelResult = asign.Report;
            }
            reportModelResult.NameFile = string.Empty;
            reportModelResult.FileData = new byte[] { };
            try {
                if (!Request.HasFormContentType)
                {
                    return(Json(new { content = "Error" }));
                }
                if (Request.Form.Files.Count > 0)
                {
                    if (Request.Form.Files["FileTechnical"] != null)
                    {
                        IFormFile file = Request.Form.Files["FileTechnical"];
                        byte[]    data;
                        using (var br = new BinaryReader(file.OpenReadStream()))
                            data = br.ReadBytes((int)file.OpenReadStream().Length);

                        reportModelResult.AssignmentId = asign.Id;
                        reportModelResult.FileData     = data;
                        reportModelResult.ModifiedBy   = userSession.Name;
                        reportModelResult.NameFile     = file.FileName.Trim();
                    }
                }
                List <FileModel> listFiles = new List <FileModel>();
                foreach (var item in reportModelResult.Files)
                {
                    FileModel newFile = new FileModel();
                    newFile = item;
                    if (item.Status != 2)
                    {
                        if (item.Status == 1)
                        {
                            newFile.FileData = new byte[] { };
                            newFile.Name     = string.Empty;
                        }
                        listFiles.Insert(0, newFile);
                    }
                }
                reportModelResult.AssignmentId = asign.Id;
                reportModelResult.Comment2     = Request.Form["Comment2"];
                string strCheck = Request.Form["Check"];
                reportModelResult.ActionType = Convert.ToInt16(Request.Form["action"]);
                if (strCheck == "on")
                {
                    reportModelResult.Check = true;
                }
                if (reportModelResult.ActionType == 2)
                {
                    reportModelResult.Sent2 = true;
                }
                reportModelResult.Files = listFiles;
                ClientResponse clientResponse = await _assignmentService.AddOrUpdateSendFileToReportSupervisor(reportModelResult);

                if (clientResponse == null || clientResponse.Status != System.Net.HttpStatusCode.OK)
                {
                    return(Json(new { content = "Error" }));
                }
            } catch (Exception) {
                return(Json(new { content = "Error" }));
            }
            return(Json(new { content = "Ok" }));
        }