public void DeleteIdeaIntellectual(IIdeaDatabaseDataContext dc, IdeaIntellectualProperty ideaIntellectualProperty)
 {
     if (ideaIntellectualProperty != null)
     {
         dc.IdeaIntellectualProperties.Remove(ideaIntellectualProperty);
     }
 }
Exemplo n.º 2
0
        public RESTAPIIntellectualInterchange(IdeaIntellectualProperty ideaIntellectualProperty)
        {
            AttachmentsList = new List <RESTAPIIdeaAttachmentInterchange>();

            string Awsip, ITGIP, folderName, path, fileName, portNumber, AWSIdeaIPFolder, AWSIdeaAttachmentFolder;

            ITGIP = WebConfigurationManager.AppSettings["ITGIP"];
            string domain = HttpContext.Current.Request.Url.Scheme;

            Awsip                   = WebConfigurationManager.AppSettings["AWSHost"];
            portNumber              = WebConfigurationManager.AppSettings["AWSHostPort"];
            AWSIdeaIPFolder         = WebConfigurationManager.AppSettings["AWSIdeaIPFolder"];
            AWSIdeaAttachmentFolder = WebConfigurationManager.AppSettings["AWSIdeaAttachmentFolder"];
            bool IsS3Enabled = Convert.ToBoolean(WebConfigurationManager.AppSettings["IsS3Enabled"]);

            if (ideaIntellectualProperty != null)
            {
                IntellectualId     = ideaIntellectualProperty.IntellectualId;
                RecordId           = ideaIntellectualProperty.RecordId;
                Status             = ideaIntellectualProperty.Status;
                FiledDate          = ideaIntellectualProperty.FiledDate?.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'");
                ApplicationNumber  = ideaIntellectualProperty.ApplicationNumber;
                PatentId           = ideaIntellectualProperty.PatentId;
                CreatedDate        = ideaIntellectualProperty.CreatedDate?.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'");
                ModifiedDate       = ideaIntellectualProperty.ModifiedDate?.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'");
                InventionReference = ideaIntellectualProperty.InventionReference;


                foreach (var attachment in ideaIntellectualProperty.IdeaAttachments)
                {
                    if (attachment.IntellectualPropertyId != null)
                    {
                        folderName = attachment.FolderName;
                        fileName   = attachment.AttachedFileName;

                        if (IsS3Enabled)
                        {
                            path = new Uri(string.Format(@"{0}/{1}/{2}/{3}/{4}", Awsip, AWSIdeaAttachmentFolder, attachment.IdeaId, folderName, fileName)).ToString();
                        }
                        else
                        {
                            path = string.Format(@"{0}://{1}:{2}/{3}/{4}/{5}/{6}", domain, ITGIP, portNumber, AWSIdeaAttachmentFolder, attachment.IdeaId, AWSIdeaIPFolder, fileName);
                        }


                        AttachmentsList.Add(
                            new RESTAPIIdeaAttachmentInterchange
                        {
                            IdeaAttachmentID = attachment.IdeaAttachmentId,
                            AttachedFileName = attachment.AttachedFileName,
                            FileExtention    = attachment.FileExtention.Trim(),
                            FileSizeInByte   = attachment.FileSizeInByte,
                            FolderName       = attachment.FolderName,
                            CreatedDate      = attachment.CreatedDate?.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'"),
                            FilePath         = path
                        });
                    }
                }
            }
        }
 public void AddIdeaIntellectual(IIdeaDatabaseDataContext dc, IdeaIntellectualProperty ideaIntellectual)
 {
     if (ideaIntellectual != null)
     {
         dc.IdeaIntellectualProperties.Add(ideaIntellectual);
     }
 }
        public void GetIntellectualProperties(RestAPIGetIntellectualResponse response, int IntellectualId)
        {
            List <RESTAPIIntellectualInterchange> intellectualInterchangeList = null;

            DatabaseWrapper.databaseOperation(response,
                                              (context, query) =>
            {
                intellectualInterchangeList = new List <RESTAPIIntellectualInterchange>();
                IdeaIntellectualProperty ideaIntellectualProperty = query.GetIdeaIntellectualById(context, IntellectualId);

                if (ideaIntellectualProperty != null)
                {
                    RESTAPIIntellectualInterchange intellectualInterchange = new RESTAPIIntellectualInterchange(ideaIntellectualProperty);
                    intellectualInterchangeList.Add(intellectualInterchange);
                }
                response.Status = Success;
            }
                                              , readOnly: true
                                              );

            if (intellectualInterchangeList != null && intellectualInterchangeList.Count > 0)
            {
                response.IdeaIntellectList.AddRange(intellectualInterchangeList);
            }
        }
        public void DeleteIntellectProperty(ResponseBase response, int IntellectualId)
        {
            DatabaseWrapper.databaseOperation(response,
                                              (context, query) =>
            {
                IdeaIntellectualProperty ideaIntellectualProperty = query.GetIdeaIntellectualById(context, IntellectualId);

                if (ideaIntellectualProperty != null)
                {
                    query.DeleteIdeaIntellectual(context, ideaIntellectualProperty);
                    response.Status = Success;
                }
                else
                {
                    response.ErrorList.Add(Faults.IdeaIntellectNotFound);
                    response.Status = Failure;
                    return;
                }
                context.SubmitChanges();
            }
                                              , readOnly: false
                                              );

            if (response == null && response.ErrorList.Count != 0)
            {
                response.ErrorList.Add(Faults.ServerIsBusy);
            }
        }
        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 void UploadIntellectualAttachmentAsync(RestAPIUpdateIntellectResponse IntellectualAttachmentResponse, InMemoryMultipartFormDataStreamProvider dataStreamProvider)
        {
            IdeaIntellectualProperty  intellectualProperty = null;
            UpdateIntellectualRequest updateIntellectual   = dataStreamProvider.UpdateIntellectualRequest;

            dataStreamProvider.UpdateIntellectualRequest.ideaAttachments.ToList().ForEach((ideaAttachment) =>
            {
                ideaAttachment.IdeaId = updateIntellectual.IdeaId;
            });

            DatabaseWrapper.databaseOperation(response,
                                              (context, query) =>
            {
                intellectualProperty = query.GetIdeaIntellectualById(context, updateIntellectual.IntellectualId);
            }
                                              , readOnly: true
                                              );

            foreach (IdeaAttachmentRequest ideaAttachmentRequest in updateIntellectual.ideaAttachments)
            {
                string inputFileName = ideaAttachmentRequest.AttachedFileName;
                string folderpath    = UploadPath(ideaAttachmentRequest, intellectualProperty.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 UpdateIntellectProperty(RestAPIUpdateIntellectResponse response, UpdateIntellectualRequest request)
        {
            DatabaseWrapper.databaseOperation(response,
                                              (context, query) =>
            {
                IdeaIntellectualProperty intellectualProperty = query.GetIdeaIntellectualById(context, request.IntellectualId);

                if (intellectualProperty != null)
                {
                    if (!string.IsNullOrEmpty(request.RecordId))
                    {
                        intellectualProperty.RecordId = request.RecordId;
                    }
                    if (request.Status.GetValueOrDefault(0) != 0)
                    {
                        intellectualProperty.Status = request.Status;
                    }
                    if (!string.IsNullOrEmpty(request.ApplicationNumber))
                    {
                        intellectualProperty.ApplicationNumber = request.ApplicationNumber;
                    }
                    if (!string.IsNullOrEmpty(request.PatentId))
                    {
                        intellectualProperty.PatentId = request.PatentId;
                    }
                    if (!string.IsNullOrEmpty(request.InventionReference))
                    {
                        intellectualProperty.InventionReference = request.InventionReference;
                    }
                    if (request.FiledDate.HasValue)
                    {
                        intellectualProperty.FiledDate = request.FiledDate;
                    }

                    intellectualProperty.ModifiedDate = DateTime.UtcNow;
                }
                else
                {
                    response.ErrorList.Add(Faults.IdeaIntellectNotFound);
                    response.Status = Failure;
                    return;
                }

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

                intellectualProperty.AttachmentCount = intellectualProperty.IdeaAttachments.Count;
                intellectualProperty.IsAttachment    = intellectualProperty.IdeaAttachments.Count == 0 ? false : true;
                context.SubmitChanges();
                response.Status = Success;
            }
                                              , readOnly: false
                                              );

            if (response == null && response.ErrorList.Count != 0)
            {
                response.ErrorList.Add(Faults.ServerIsBusy);
            }
        }