Esempio n. 1
0
        public async Task Add(ClientDocumentType clientDoc)
        {
            try
            {
                var existeClient = await GetById(clientDoc.Client_Id);

                var existedoc = await GetById(clientDoc.DocumentType_Id);

                if (existeClient != null & existedoc != null)
                {
                    if (existeClient.Client_Id == clientDoc.Client_Id && existedoc.DocumentType_Id == clientDoc.DocumentType_Id)
                    {
                        await _clientDocumentTypeRepository.Add(clientDoc);
                    }
                }
                else
                {
                    var message = "No existe datos relacionados con el client_Id o documentType_id";
                    throw new BusinessException(MessageCodes.PROPERTY_NO_VALID, GetErrorDescription(MessageCodes.PROPERTY_NO_VALID), "");
                }
            }
            catch (Exception ex)
            {
                throw new BusinessException(MessageCodes.PROPERTY_NO_VALID, GetErrorDescription(MessageCodes.PROPERTY_NO_VALID), ex.Message);
            }
        }
Esempio n. 2
0
        public ActionResult UploadDocument(int id, ClientDocumentType docType)
        {
            List <FileUploadResponse> files = new List <FileUploadResponse>();

            foreach (string fileName in HttpContext.Request.Files)
            {
                var file = Request.Files[fileName];
                if (file != null && file.ContentLength > 0)
                {
                    ClientDocument clientDoc = _fileService.SaveDocument(file, User.Identity.GetUserId(), docType, id);

                    files.Add(new FileUploadResponse
                    {
                        name         = clientDoc.File.Name,
                        size         = clientDoc.File.ContentLengthInBytes,
                        thumbnailUrl = clientDoc.File.ThumbnailPath ?? "/Content/assets/img/filetypes/" + clientDoc.File.Extension.Replace(".", "") + ".png",
                        deleteUrl    = Url.Action("DeleteDoc", "File", new { id = clientDoc.FileId, area = "Agent", fn = clientDoc.File.Name }),
                        deleteType   = "GET",
                        url          = clientDoc.File.RelativePath,
                        docType      = clientDoc.DocumentType.ToString()
                    });
                }
            }
            return(Json(new FileResponseModel {
                files = files
            }, JsonRequestBehavior.AllowGet));
        }
        public async Task <bool> Update(ClientDocumentType clientDoc)
        {
            var currentclientdoc = await GetById(clientDoc.ClientDocumentType_Id);

            currentclientdoc.Client_Id       = clientDoc.Client_Id;
            currentclientdoc.DocumentType_Id = clientDoc.DocumentType_Id;
            currentclientdoc.Path            = clientDoc.Path;

            int rows = await _context.SaveChangesAsync();

            return(rows > 0);
        }
Esempio n. 4
0
 public async Task <bool> Update(ClientDocumentType clieDoc)
 {
     return(await _clientDocumentTypeRepository.Update(clieDoc));
 }
Esempio n. 5
0
        public ClientDocument SaveDocument(HttpPostedFileBase file, string getUserId, ClientDocumentType docType, int id)
        {
            var client = _dbContext.Clients.Find(id);

            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            var uploadRelativePath = PathHelper.GetUploadRelativePath(id);
            var fullFileName       = HttpContext.Current.Server.MapPath(Path.Combine(uploadRelativePath, file.FileName));

            var uploadThumbRelativePath = PathHelper.GetUploadThumbRelativePath(id);
            var fullThumbName           = HttpContext.Current.Server.MapPath(Path.Combine(uploadThumbRelativePath, file.FileName));



            file.SaveAs(fullFileName);

            var wt24File = new Wt24File
            {
                Name                 = file.FileName,
                Mime                 = file.ContentType,
                Extension            = Path.GetExtension(fullFileName),
                ContentLengthInBytes = file.ContentLength,
                RelativePath         = Path.Combine(uploadRelativePath, file.FileName),
                Filetype             = FileTypesHelper.FindTypeByExtension(fullFileName),
            };

            if (FileTypesHelper.ImageExtensions.Any(c => c.ToLower() == Path.GetExtension(file.FileName).ToLower()))
            {
                //todo: save different sizes for thumbs
                var source = File.ReadAllBytes(fullFileName);
                using (var inStream = new MemoryStream(source))
                {
                    using (var imageFactory = new ImageFactory(preserveExifData: true))
                    {
                        imageFactory.Load(inStream).Watermark(new TextLayer()
                        {
                            DropShadow = true,
                            FontFamily = FontFamily.GenericSansSerif,
                            Text       = "wohnungstausch24",
                            Style      = FontStyle.Bold,
                            FontColor  = Color.Black,
                            Opacity    = 48,
                            FontSize   = 48
                        })
                        .Format(new JpegFormat())
                        .Save(fullFileName)
                        .Resize(new ResizeLayer(new Size(390, 260), ResizeMode.Max))
                        .Save(fullThumbName);
                    }
                }
                wt24File.Name = file.FileName;
                wt24File.ContentLengthInBytes = file.ContentLength;
                wt24File.Filetype             = FileTypesHelper.FindTypeByExtension(fullFileName);

                wt24File.Mime          = FileTypesHelper.GetMimeFromFile(fullFileName);
                wt24File.Extension     = Path.GetExtension(fullFileName);
                wt24File.ThumbnailPath = Path.Combine(uploadThumbRelativePath, file.FileName);
                wt24File.RelativePath  = Path.Combine(uploadRelativePath, file.FileName);
            }
            else if (FileTypesHelper.VideoExtensions.Any(c => c == Path.GetExtension(file.FileName)))
            {
                var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fullFileName);

                var outputFormat = NReco.VideoConverter.Format.webm;

                var thumbName                  = fileNameWithoutExtension + ".jpg";
                var newVideoFileName           = outputFormat + "_" + FrameSize.hd720 + "_" + fileNameWithoutExtension + "." + outputFormat;
                var fullVideoThumbName         = HttpContext.Current.Server.MapPath(Path.Combine(uploadThumbRelativePath, thumbName));
                var convertedVideoRelativePath = Path.Combine(uploadRelativePath, newVideoFileName);
                var convertedVideoFullPath     = HttpContext.Current.Server.MapPath(convertedVideoRelativePath);

                var ffMpeg   = new FFMpegConverter();
                var settings = new ConvertSettings {
                    VideoFrameSize = FrameSize.hd480
                };
                FFMpegInput[] input = { new FFMpegInput(fullFileName) };
                ffMpeg.ConvertMedia(input, convertedVideoFullPath, outputFormat, settings);
                ffMpeg.GetVideoThumbnail(convertedVideoFullPath, fullVideoThumbName);

                File.Delete(fullFileName);

                var fileInfo = new FileInfo(convertedVideoFullPath);

                wt24File.Filetype             = FileTypesHelper.FindTypeByExtension(convertedVideoFullPath);
                wt24File.Mime                 = FileTypesHelper.GetMimeFromFile(convertedVideoFullPath);
                wt24File.Extension            = Path.GetExtension(convertedVideoFullPath);
                wt24File.ContentLengthInBytes = (int)fileInfo.Length;
                wt24File.ThumbnailPath        = Path.Combine(uploadThumbRelativePath, thumbName);
                wt24File.RelativePath         = convertedVideoRelativePath;
                wt24File.Name                 = newVideoFileName;
            }


            var docFile = new ClientDocument {
                File = wt24File, DocumentType = docType, Client = client, ClientId = id, FileId = wt24File.Id
            };

            _dbContext.Clients.Find(id).ClientDocuments.Add(docFile);

            _dbContext.SaveChanges();

            return(docFile);
        }
 public async Task Add(ClientDocumentType clientDoc)
 {
     _context.ClientDocumentType.Add(clientDoc);
     await _context.SaveChangesAsync();
 }