Esempio n. 1
0
        public async Task <IEnumerable <dynamic> > SaveOrUpdateAttachment(ImagePlottingAttachmentViewModel ipavm)
        {
            string sql = "dbo.EAppSavePlottingAttachment";

            using (var conn = util.MasterCon())
            {
                try
                {
                    return(await(conn.QueryAsync <dynamic>(sql, new
                    {
                        ipavm.PlottingAttachId,
                        ipavm.PlantAreaId,
                        ipavm.EquipmentId,
                        ipavm.UnitType,
                        ipavm.UnitId,
                        ipavm.PlotType,
                        ipavm.FileName,
                        ipavm.LogicalName,
                        ipavm.PhysicalPath,
                        ipavm.Active,
                        ipavm.UserId
                    }, commandType: CommandType.StoredProcedure)));
                }
                catch (Exception ex)
                {
                    throw new CustomException("Unable to Save Or Update, Please Contact Support!!!", "Error", true, ex);
                }
            }
        }
        public async Task <IActionResult> UploadFiles()
        {
            try
            {
                CurrentUser cUser = new CurrentUser(HttpContext, _configuration);

                var          customHeaders = Request.Headers;
                StringValues aId           = "";
                StringValues PlantAreaId   = "";
                StringValues EquipmentId   = "";
                StringValues UnitType      = "";
                StringValues UnitId        = "";
                StringValues PlotType      = "";
                StringValues ImageHeight   = "";
                StringValues ImageWidth    = "";
                if (customHeaders.ContainsKey("aId") && customHeaders.ContainsKey("Type"))
                {
                    customHeaders.TryGetValue("plantAreaId", out PlantAreaId);
                    customHeaders.TryGetValue("equipmentId", out EquipmentId);
                    customHeaders.TryGetValue("unitType", out UnitType);
                    customHeaders.TryGetValue("unitId", out UnitId);
                    customHeaders.TryGetValue("plotType", out PlotType);
                    List <FileUploadViewModel> fuvms = await fileUploadService.UploadFiles(Request, HttpContext);

                    foreach (FileUploadViewModel fuvm in fuvms)
                    {
                        ImagePlottingAttachmentViewModel ipavm = new ImagePlottingAttachmentViewModel();
                        ipavm.PlottingAttachId = 0;
                        if (PlotType == "PL")
                        {
                            ipavm.PlantAreaId = Int32.Parse(PlantAreaId);
                        }
                        if (PlotType == "EQ")
                        {
                            ipavm.EquipmentId = Int32.Parse(EquipmentId);
                        }
                        if (PlotType == "AS")
                        {
                            ipavm.UnitType = UnitType;
                            ipavm.UnitId   = Int32.Parse(UnitId);
                        }
                        ipavm.PlotType     = PlotType;
                        ipavm.FileName     = fuvm.OriginalFileName;
                        ipavm.LogicalName  = fuvm.LogicalFileName;
                        ipavm.PhysicalPath = fuvm.PhysicalFilePath;
                        ipavm.Active       = "Y";
                        ipavm.UserId       = cUser.UserId;
                        await imagePlottingRepo.SaveOrUpdateAttachment(ipavm);
                    }
                }

                return(Json("Success"));
            }
            catch (CustomException cex)
            {
                var responseObj = new EmaintenanceMessage(cex.Message, cex.Type, cex.IsException, cex.Exception?.ToString());
                return(StatusCode(StatusCodes.Status500InternalServerError, responseObj));
            }
            catch (Exception ex)
            {
                return(Ok(new EmaintenanceMessage(ex.Message)));
            }
        }