Esempio n. 1
0
        public int Save(CaptureImageDTO dto)
        {
            CaptureImageDAO b    = new CaptureImageDAO();
            int             resp = b.Save(dto);

            return(resp);
        }
Esempio n. 2
0
        public int Save(CaptureImageDTO dto)
        {
            try
            {
                using (SEDESOLEntities db = new SEDESOLEntities())
                {
                    byte[] imgBytes;
                    if (dto.FromCam)
                    {
                        imgBytes = Convert.FromBase64String(dto.ImageFileB64);
                    }
                    else
                    {
                        imgBytes = dto.ImageFile;
                    }
                    CAPTURE_IMAGE captureEntity = new CAPTURE_IMAGE
                    {
                        Name       = dto.Name,
                        ImageFile  = imgBytes,
                        ImagePath  = dto.ImagePath,
                        Id_Capture = dto.Id_Capture
                    };

                    db.CAPTURE_IMAGE.Add(captureEntity);
                    if (db.SaveChanges() > 0)
                    {
                        dto.Id = captureEntity.Id;

                        return(dto.Id);
                    }
                    else
                    {
                        return(0);
                    }
                }
            }
            catch (Exception ex)
            {
                return(0);
            }
        }
Esempio n. 3
0
        public ActionResult UploadFiles(string pFileCam, HttpPostedFileBase pFile, string pType)
        {
            string responseS           = string.Empty;
            SedesolServiceClient proxy = new SedesolServiceClient();
            string viewContent         = string.Empty;
            int    countImage          = Convert.ToInt32(Session["CountImg"].ToString());

            try
            {
                if (countImage < Convert.ToInt32(ConfigurationManager.AppSettings["maxCountFiles"].ToString()))
                {
                    if (pType == "1")
                    {
                        if (pFileCam != string.Empty)
                        {
                            string[]        ar           = pFileCam.Split(',');
                            CaptureModel    captureModel = (CaptureModel)Session["CaptureModel"];
                            CaptureImageDTO dto          = new CaptureImageDTO();

                            dto.Id_Capture   = captureModel.Capture.Id;
                            dto.FromCam      = false;
                            dto.ImageFile    = Convert.FromBase64String(ar[1]);
                            dto.ImageFileB64 = string.Empty;
                            dto.ImagePath    = string.Empty;
                            dto.Name         = "test";

                            int response = proxy.SaveCaptureImage(dto);
                            if (response > 0)
                            {
                                responseS = "SUCCESS";
                            }
                        }
                        else
                        {
                            responseS = "Debe activar la cámara y tomar la foto.";
                        }
                    }
                    else
                    {
                        //fileupload
                        if (Request.Files.Count > 0 && pFile != null)
                        {
                            if (pFile.ContentType == "image/jpeg")
                            {
                                if (pFile.ContentLength <= (1048576))
                                {
                                    string fname;
                                    //bool success = false;

                                    if (Request.Browser.Browser.ToUpper() == "IE" || Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER")
                                    {
                                        string[] testfiles = pFile.FileName.Split(new char[] { '\\' });
                                        fname = testfiles[testfiles.Length - 1];
                                    }
                                    else
                                    {
                                        fname = pFile.FileName;
                                    }

                                    BinaryReader binaryReader = new BinaryReader(pFile.InputStream);
                                    byte[]       binaryData   = binaryReader.ReadBytes((int)pFile.InputStream.Length);

                                    CaptureModel    captureModel = (CaptureModel)Session["CaptureModel"];
                                    CaptureImageDTO dto          = new CaptureImageDTO();

                                    dto.Id_Capture   = captureModel.Capture.Id;
                                    dto.FromCam      = false;
                                    dto.ImageFile    = binaryData;
                                    dto.ImageFileB64 = string.Empty;
                                    dto.ImagePath    = string.Empty;
                                    dto.Name         = fname;

                                    int response = proxy.SaveCaptureImage(dto);
                                    if (response > 0)
                                    {
                                        responseS = "SUCCESS";
                                    }
                                }
                                else
                                {
                                    responseS = "Tamaño máximo permitido: 1MB.";
                                }
                            }
                            else
                            {
                                responseS = "El archivo ingresado debe ser en formato jpg.";
                            }
                        }
                        else
                        {
                            responseS = "Debe seleccionar un archivo.";
                        }
                    }
                }
                else
                {
                    responseS = "Máximo de imágenes por captura: " + ConfigurationManager.AppSettings["maxCountFiles"].ToString();
                }
            }
            catch (Exception ex)
            {
                responseS = "Error al guardar archivo. Contacte al Administrador.";
            }
            finally
            {
                CaptureModel           captureModel = (CaptureModel)Session["CaptureModel"];
                List <CaptureImageDTO> listImage    = new List <CaptureImageDTO>();

                listImage           = proxy.GetImageByCaptureId(captureModel.Capture.Id);
                Session["CountImg"] = null;
                Session.Add("CountImg", listImage.Count());

                foreach (CaptureImageDTO item in listImage)
                {
                    item.ImageFileB64 = "data:image/jpeg; base64," + Convert.ToBase64String(item.ImageFile);
                }
                proxy.Close();
                viewContent = ConvertViewToString("ImageList", listImage);
            }
            var sjonResult = Json(new { message = responseS, PartialView = viewContent });

            sjonResult.MaxJsonLength = int.MaxValue;

            return(sjonResult);
        }
Esempio n. 4
0
        public int SaveCaptureImage(CaptureImageDTO dto)
        {
            CaptureImageDAL dal = new CaptureImageDAL();

            return(dal.Save(dto));
        }