public void UploadIntellectualAttachmentAsync(RestAPIAddIntellectualResponse IntellectualAttachmentResponse, InMemoryMultipartFormDataStreamProvider dataStreamProvider)
        {
            SubmitIntellectualRequest submitIntellectual = dataStreamProvider.SubmitIntellectualrequest;

            dataStreamProvider.SubmitIntellectualrequest.ideaAttachments.ToList().ForEach((ideaAttachment) =>
            {
                ideaAttachment.IdeaId = submitIntellectual.IdeaId;
            });


            foreach (IdeaAttachmentRequest ideaAttachmentRequest in submitIntellectual.ideaAttachments)
            {
                string inputFileName = ideaAttachmentRequest.AttachedFileName;
                string folderpath    = UploadPath(ideaAttachmentRequest, submitIntellectual.IdeaId);
                string filepath      = Path.Combine(folderpath, inputFileName);
                logger.Info($"IntellectualAttachmentResponse==Folder path={folderpath}");


                if (IsS3Enable)
                {
                    UploadRequestToS3(folderpath, filepath, ideaAttachmentRequest.stream);
                }
                else
                {
                    SaveAttachments(ideaAttachmentRequest.stream, inputFileName, folderpath);
                }
            }
        }
        public void SubmitIdeaIntellectual(RestAPIAddIntellectualResponse response, SubmitIntellectualRequest request)
        {
            DatabaseWrapper.databaseOperation(response,
                                              (context, query) =>
            {
                Idea idea = query.GetIdea(context, request.IdeaId, request.UserID, Enums.Relation.NoneRel);
                if (idea == null)
                {
                    response.ErrorList.Add(Faults.IdeaNotFound);
                    return;
                }

                IdeaIntellectualProperty ideaIntellectualProperty = new IdeaIntellectualProperty()
                {
                    IdeaId             = request.IdeaId,
                    RecordId           = request.RecordId,
                    Status             = request.Status,
                    FiledDate          = request.FiledDate,
                    ApplicationNumber  = request.ApplicationNumber,
                    PatentId           = request.PatentId,
                    CreatedDate        = DateTime.UtcNow,
                    ModifiedDate       = DateTime.UtcNow,
                    IsAttachment       = request.IsAttachment,
                    AttachmentCount    = request.AttachmentCount,
                    UserId             = request.UserID,
                    InventionReference = request.InventionReference
                };

                // insert idea intellectual attachment
                if (request.AttachmentCount != 0)
                {
                    request.ideaAttachments.ToList().ForEach((attachment) =>
                    {
                        IdeaAttachment ideaAttach   = new IdeaAttachment();
                        ideaAttach.IdeaId           = request.IdeaId;
                        ideaAttach.AttachedFileName = attachment.AttachedFileName;
                        ideaAttach.FileExtention    = attachment.FileExtention;
                        ideaAttach.FileSizeInByte   = attachment.FileSizeInByte;
                        ideaAttach.CreatedDate      = DateTime.UtcNow;
                        ideaAttach.FolderName       = attachment.DocumentTypeFolderName;
                        ideaIntellectualProperty.IdeaAttachments.Add(ideaAttach);
                    });
                }

                query.AddIdeaIntellectual(context, ideaIntellectualProperty);
                context.SubmitChanges();
                response.IntellectualId = ideaIntellectualProperty.IntellectualId;
            }
                                              , readOnly: false
                                              );

            if (response.ErrorList.Count != 0)
            {
                response.ErrorList.Add(Faults.ServerIsBusy);
                return;
            }
        }
        public RestAPIAddIntellectualResponse SubmitIntellectual(InMemoryMultipartFormDataStreamProvider provider, int UserID)
        {
            RestAPIAddIntellectualResponse intellectualResponse = new RestAPIAddIntellectualResponse()
            {
                Status = Success
            };

            SubmitIntellectualRequest submitIntellectual = provider.SubmitIntellectualrequest;

            submitIntellectual.UserID = UserID;

            try
            {
                if (provider.attachFileCount != 0)
                {
                    submitIntellectual.IsAttachment    = true;
                    submitIntellectual.AttachmentCount = provider.attachFileCount;
                }

                ideautils.SubmitIdeaIntellectual(intellectualResponse, submitIntellectual);

                if (intellectualResponse.ErrorList.Count != 0)
                {
                    intellectualResponse.Status = Failure;
                }

                if (provider.SubmitIntellectualrequest.files.Count == 0)
                {
                    return(intellectualResponse);
                }


                fileUtil.UploadIntellectualAttachmentAsync(intellectualResponse, provider);

                if (intellectualResponse.ErrorList.Count != 0)
                {
                    intellectualResponse.Status = Failure;
                }
            }
            catch (Exception ex)
            {
                intellectualResponse.Status = Failure;
                throw new Exception(ex.Message, ex);
            }

            return(intellectualResponse);
        }