Beispiel #1
0
        public void AddInfoRequest(string requestMessage, string sendById, IEnumerable <IFormFile> files = null)
        {
            var infoRequest = InfoRequest.Create(requestMessage, this.Id, sendById);

            if (files != null)
            {
                infoRequest.AddAttachments(files, false);
            }

            this.InfoRequests.Add(infoRequest);
        }
Beispiel #2
0
        public static Attachment Create(
            IFormFile file,
            CompanyContract contract        = null,
            InfoRequest infoRequest         = null,
            InfoRequest infoRequestResponse = null,
            Inquiry inquiry = null)
        {
            if (file.Length > MAX_SIZE || file.Length == 0)
            {
                throw new ArgumentOutOfRangeException("file", $"File attachment size can't be 0 or bigger then {MAX_SIZE}");
            }

            if (file.FileName.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
            {
                throw new ArgumentException("file", "File name contains invalid characters.");
            }

            var filePath = Path.GetTempFileName();

            using (var stream = new MemoryStream())
            {
                file.CopyTo(stream);
                var attachment = new Attachment()
                {
                    FileName              = file.FileName,
                    Extention             = Path.GetExtension(filePath),
                    UploadDate            = DateTime.Now,
                    File                  = stream.ToArray(),
                    ContractId            = contract?.Id,
                    InfoRequestId         = infoRequest?.Id,
                    InforequestResponseId = infoRequestResponse?.Id,
                    InquiryId             = inquiry?.Id
                };

                return(attachment);
            }
        }