public IFormFile CreateFile(IFormFile file)
        {
            var supportedTypes = new[] { "doc", "docx", "pdf", "ppt", "xls" };

            var fileName = System.IO.Path.GetFileName(file.FileName);

            var fileExtension = System.IO.Path.GetExtension(file.FileName).Substring(1);

            using (var stream = new System.IO.MemoryStream())
            {
                file.CopyTo(stream);

                if (!supportedTypes.Contains(fileExtension))
                {
                    throw new NotSupportedException("Unsupported File Format");
                }

                var document = new DocumentFiles()
                {
                    FileId       = 0,
                    FileName     = fileName,
                    FileType     = file.ContentType,
                    DocumentFile = stream.ToArray(),
                    CreatedOn    = DateTime.Now
                };

                _context.DocumentFiles.Add(document);
                _context.SaveChanges();
            }

            return(file);
        }
Exemplo n.º 2
0
        public async Task <bool> DeleteFile([FromBody] int fileId)
        {
            using (var context = new DB_A12601_bielkaContext())
            {
                DocumentFiles fileEntity = context.DocumentFiles.FirstOrDefault(d => d.DcfId == fileId);


                if (fileEntity == null)
                {
                    return(true);
                }

                string filePath = _env.WebRootPath + fileEntity.DcfUrl;
                if (System.IO.File.Exists(filePath))
                {
                    System.IO.File.Delete(filePath);
                }


                context.DocumentFiles.Remove(fileEntity);
                await context.SaveChangesAsync();

                return(true);
            }
        }
        public async Task <ActionResult> DeleteFilesConfirmed(int id)
        {
            DocumentFiles documentfiles = await db.DocumentFiles.FindAsync(id);

            db.DocumentFiles.Remove(documentfiles);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
        public DocumentFilesDto UploadFiles(IFormFile file, string name, string description, int ownerId, string ownerType)
        {
            try
            {
                if (file == null)
                {
                    return(new DocumentFilesDto
                    {
                        Success = false,
                        ErrorMessage = "File is not selected"
                    });
                }

                string fileName = SaveFile(file);

                using (var context = new DB_A12601_bielkaContext())
                {
                    DocumentFiles fileEntity = new DocumentFiles
                    {
                        DcfUrl         = fileName,
                        DcfAuditCd     = DateTime.UtcNow,
                        DcfAuditCu     = User.GetUserId(),
                        DcfAuditMd     = DateTime.UtcNow,
                        DcfAuditMu     = User.GetUserId(),
                        DcfName        = name ?? string.Empty,
                        DcfDescription = description ?? string.Empty,
                    };

                    switch (ownerType)
                    {
                    case "contragent":
                        fileEntity.DcfCntId = ownerId;
                        break;

                    case "client":
                        fileEntity.DcfCliId = ownerId;
                        break;

                    case "offer":
                        fileEntity.DcfOfrId = ownerId;
                        break;
                    }

                    context.Add(fileEntity);
                    context.SaveChanges();
                    return(new DocumentFilesDto(fileEntity));
                }
            }
            catch (Exception ex)
            {
                return(new DocumentFilesDto
                {
                    Success = false,
                    ErrorMessage = ex.Message
                });
            }
        }
Exemplo n.º 5
0
 public DocumentFilesDto(DocumentFiles file)
 {
     Id            = file.DcfId;
     InvoiceId     = file.DcfInvId;
     ContragentId  = file.DcfCntId;
     IdtDocumentId = file.DcfIdcId;
     GoogleFileId  = file.DcfGoogleFileId;
     Name          = file.DcfName;
     Description   = file.DcfDescription;
     Url           = file.DcfUrl;
 }
        public async Task <ActionResult> DeleteFiles(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DocumentFiles documentfiles = await db.DocumentFiles.FindAsync(id);

            if (documentfiles == null)
            {
                return(HttpNotFound());
            }
            return(View(documentfiles));
        }
Exemplo n.º 7
0
        public bool DeleteIdDocumentFile([FromBody] int fileId)
        {
            using (DB_A12601_bielkaContext context = new DB_A12601_bielkaContext())
            {
                DocumentFiles docFile = context.DocumentFiles.FirstOrDefault(c => c.DcfId == fileId);

                if (docFile == null)
                {
                    return(false);
                }

                docFile.DcfAuditRd = DateTime.UtcNow;
                docFile.DcfAuditRu = User.GetUserId();
                context.SaveChanges();

                return(true);
            }
        }
Exemplo n.º 8
0
        public async Task <DocumentFilesDto> SaveFile(DocumentFilesDto file)
        {
            using (var context = new DB_A12601_bielkaContext())
            {
                DocumentFiles fileEntity = null;
                if (file.Id != 0)
                {
                    fileEntity = context.DocumentFiles.FirstOrDefault(d => d.DcfId == file.Id);
                }

                if (fileEntity == null)
                {
                    fileEntity = new DocumentFiles
                    {
                        DcfAuditCd = DateTime.UtcNow,
                        DcfAuditCu = User.GetUserId()
                    };
                    context.DocumentFiles.Add(fileEntity);
                }

                fileEntity.DcfIdcId       = file.IdtDocumentId;
                fileEntity.DcfAuditMd     = DateTime.UtcNow;
                fileEntity.DcfAuditMu     = User.GetUserId();
                fileEntity.DcfCliId       = file.ClientId;
                fileEntity.DcfCntId       = file.ContragentId;
                fileEntity.DcfDescription = file.Description;
                fileEntity.DcfInvId       = file.InvoiceId;
                fileEntity.DcfName        = file.Name;
                fileEntity.DcfOfrId       = file.OfferId;

                await context.SaveChangesAsync();

                file.Id = fileEntity.DcfId;
                return(file);
            }
        }
Exemplo n.º 9
0
        private IdentityDocumentsDto SaveDocument(IdentityDocumentsDto documentDto)
        {
            using (DB_A12601_bielkaContext context = new DB_A12601_bielkaContext())
            {
                IdentityDocuments document;
                if (documentDto.Id == 0)
                {
                    document = new IdentityDocuments
                    {
                        IdcAuditCd = DateTime.UtcNow,
                        IdcAuditCu = User.GetUserId()
                    };
                    context.IdentityDocuments.Add(document);
                }
                else
                {
                    document = context.IdentityDocuments.FirstOrDefault(d => d.IdcId == documentDto.Id);
                }

                document.IdcEmpId       = documentDto.EmployeeId;
                document.IdcAuditMd     = DateTime.UtcNow;
                document.IdcAuditMu     = User.GetUserId();
                document.IdcIssueDate   = documentDto.IssueDate;
                document.IdcNumber      = documentDto.Number;
                document.IdcParentIdcId = documentDto.ParentDocumentId;
                document.IdcRemarks     = documentDto.Remarks;
                document.IdcSeria       = documentDto.Seria;
                document.IdcType        = documentDto.Type;
                document.IdcValidFrom   = documentDto.ValidFrom;
                document.IdcValidTo     = documentDto.ValidTo;
                document.IdcVisaType    = documentDto.VisaType;

                context.SaveChanges();

                foreach (var file in documentDto.Files)
                {
                    DocumentFiles docFile = new DocumentFiles
                    {
                        DcfAuditCd     = DateTime.UtcNow,
                        DcfAuditCu     = User.GetUserId(),
                        DcfDescription = file.Description,
                        DcfName        = file.Name,
                        DcfIdcId       = document.IdcId,
                        DcfUrl         = file.Url
                    };

                    context.DocumentFiles.Add(docFile);
                }

                context.SaveChanges();

                documentDto.Id    = document.IdcId;
                documentDto.Files =
                    context.DocumentFiles.Where(d => d.DcfIdcId == document.IdcId)
                    .ToList()
                    .Select(d => new DocumentFilesDto(d))
                    .ToList();

                return(documentDto);
            }
        }
        public object GetDbObject(string table, AppUser appUser, Document document, int index = -1)
        {
            switch (table)
            {
            case "UserValues":
            {
                var userValues =
                    UserValues
                    .Where(x => x.AppUser.Id == appUser.Id)
                    .OrderByDescending(x => x.Id).FirstOrDefault();
                if (userValues == null)
                {
                    userValues = new UserValues {
                        AppUser = appUser
                    };
                    Add(userValues);
                    SaveChanges();
                }
                return(userValues);
            }

            case "DocumentEmail":
            {
                var documentEmail =
                    DocumentEmail
                    .Where(x => x.Document.Id == document.Id)
                    .OrderByDescending(x => x.Id)
                    .FirstOrDefault();
                if (documentEmail == null)
                {
                    documentEmail = new DocumentEmail {
                        Document = document
                    };
                    Add(documentEmail);
                    SaveChanges();
                }
                return(documentEmail);
            }

            case "Employer":
            {
                return(document.Employer);
            }

            case "CustomVariables":
            {
                if (index >= 1)
                {
                    var customVariable =
                        CustomVariables
                        .Where(x => x.Document.Id == document.Id)
                        .OrderBy(x => x.Id)
                        .Skip((int)index - 1)
                        .Take(1)
                        .FirstOrDefault();
                    if (customVariable == null)
                    {
                        customVariable = new CustomVariable {
                            Document = document
                        };
                        Add(customVariable);
                        SaveChanges();
                    }
                    return(customVariable);
                }
                else
                {
                    var customVariables =
                        CustomVariables
                        .Where(x => x.Document.Id == document.Id)
                        .OrderBy(x => x.Id);
                    return(customVariables);
                }
            }

            case "DocumentFiles":
            {
                if (index >= 1)
                {
                    var documentFile =
                        DocumentFiles
                        .Where(x => x.Document.Id == document.Id)
                        .OrderBy(x => x.Id)
                        .Skip((int)index - 1)
                        .Take(1)
                        .FirstOrDefault();
                    if (documentFile == null)
                    {
                        documentFile = new DocumentFile {
                            Document = document
                        };
                        Add(documentFile);
                        SaveChanges();
                    }
                    return(documentFile);
                }
                else
                {
                    return
                        (DocumentFiles
                         .Where(x => x.Document.Id == document.Id)
                         .OrderBy(x => x.Id)
                         .AsEnumerable <DocumentFile>());
                }
            }

            case "Document":
                return(document);

            case "SentApplications":
            {
                var sentApplications =
                    SentApplications
                    .Where(x => x.Document.AppUser.Id == appUser.Id)
                    .Include(x => x.Document)
                    .Include(x => x.Document.Employer)
                    .Include(x => x.UserValues)
                    .OrderByDescending(x => x.SentDate)
                    .AsEnumerable <SentApplication>();
                return(sentApplications);
            }

            default:
                throw new Exception($"Table not found: {table}");
            }
        }