public RESTAPIIdeaAttachmentsInterchange(IdeaAttachment ideaAttachment)
        {
            string Awsip, ITGIP, hostName, portNumber, AWSIdeaIPFolder, AWSIdeaAttachmentFolder;
            int    ideaId;
            string domain = HttpContext.Current.Request.Url.Scheme;

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

            if (ideaAttachment != null)
            {
                IdeaAttachmentID = ideaAttachment.IdeaAttachmentId;
                AttachedFileName = ideaAttachment.AttachedFileName;
                FileExtention    = ideaAttachment.FileExtention;
                FileSizeInByte   = ideaAttachment.FileSizeInByte;
                CreatedDate      = ideaAttachment.CreatedDate?.ToUniversalTime().ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'");
                FolderName       = ideaAttachment.FolderName;

                if (IsS3Enabled)
                {
                    FilePath = new Uri(string.Format(@"{0}/{1}/{2}/{3}/{4}", Awsip, AWSIdeaAttachmentFolder, ideaAttachment.IdeaId, ideaAttachment.FolderName, ideaAttachment.AttachedFileName)).ToString();
                }
                else
                {
                    ITGIP    = WebConfigurationManager.AppSettings["ITGIP"];
                    FilePath = string.Format(@"{0}://{1}:{2}/{3}/{4}/{5}/{6}", domain, ITGIP, portNumber, AWSIdeaAttachmentFolder, ideaAttachment.IdeaId, ideaAttachment.FolderName, ideaAttachment.AttachedFileName);
                }
            }
        }
 public void DeleteIdeaAttachment(IIdeaDatabaseDataContext dc, IdeaAttachment ideaAttachment)
 {
     if (ideaAttachment != null)
     {
         dc.IdeaAttachments.Remove(ideaAttachment);
     }
 }
        public RestAPIDeleteAttachmentResponse DeleteIdeaAttachment(ResponseBase response, int IdeaAttachmentId)
        {
            RestAPIDeleteAttachmentResponse restAPIDeleteAttachmentResponse = new RestAPIDeleteAttachmentResponse();

            DatabaseWrapper.databaseOperation(response,
                                              (context, query) =>
            {
                IdeaAttachment ideaAttachment = query.GetIdeaAttachmentById(context, IdeaAttachmentId);

                if (ideaAttachment != null)
                {
                    query.DeleteIdeaAttachment(context, ideaAttachment);
                    response.Status = Success;
                }
                else
                {
                    response.ErrorList.Add(Faults.IdeaAttachmentNotFound);
                    response.Status = Failure;
                    return;
                }

                context.SubmitChanges();
            }
                                              , readOnly: false
                                              );

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

            return(restAPIDeleteAttachmentResponse);
        }
        public void SubmitIdeaAttachment(ResponseBase response, RestAPIIdeaSupportingRequest restAPIIdeaSupportingRequest, int UserID)
        {
            DatabaseWrapper.databaseOperation(response, (context, query) =>
            {
                Idea idea = query.GetIdeaById(context, restAPIIdeaSupportingRequest.IdeaId);
                if (idea == null)
                {
                    response.ErrorList.Add(Faults.IdeaNotFound);
                    return;
                }

                if (!string.IsNullOrWhiteSpace(restAPIIdeaSupportingRequest.Ideatags))
                {
                    tagUtil.InsertTags(response, idea, restAPIIdeaSupportingRequest.Ideatags, UserID);
                }

                if (!string.IsNullOrEmpty(restAPIIdeaSupportingRequest.GitRepo))
                {
                    idea.GitRepo = restAPIIdeaSupportingRequest.GitRepo;
                }

                List <IdeaAttachment> ideaAttachments = new List <IdeaAttachment>();
                if (restAPIIdeaSupportingRequest.ideaAttachments.Count > 0)
                {
                    restAPIIdeaSupportingRequest.ideaAttachments.ForEach((Id) =>
                    {
                        IdeaAttachment newIdea   = new IdeaAttachment();
                        newIdea.AttachedFileName = Id.AttachedFileName;
                        newIdea.FileExtention    = Id.FileExtention;
                        newIdea.FileSizeInByte   = Id.FileSizeInByte;
                        newIdea.IdeaId           = Id.IdeaId;
                        newIdea.CreatedDate      = DateTime.UtcNow;
                        newIdea.FolderName       = Id.DocumentTypeFolderName;
                        ideaAttachments.Add(newIdea);

                        if (Id.DocumentTypeFolderName == Enum.GetName(typeof(folderNames), folderNames.DefaultImage))
                        {
                            query.DeleteDefaultImageAttachment(context, idea.IdeaId);
                        }
                    });
                    idea.IdeaAttachments = ideaAttachments;
                    query.AddIdeaAttachments(context, ideaAttachments);
                }

                idea.ModifiedDate = DateTime.UtcNow;
                context.SubmitChanges();

                idea.AttachmentCount = idea.IdeaAttachments.Count;
                idea.IsAttachment    = idea.IdeaAttachments.Count == 0 ? false : true;

                context.SubmitChanges();
            }, readOnly: false
                                              );
            if (response == null && response.ErrorList.Count != 0)
            {
                response.ErrorList.Add(Faults.ServerIsBusy);
                return;
            }
        }
        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 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);
            }
        }