private int AddAttachmentFiles(string appId, int customerId, long creditCheckingId, ICollection <AttachmentUploadResource> attachmentUploadResourceFiles, string createdByUserId) { // Upsert Attachment rows for this App. and Customer IEnumerable <Attachment> attachmentsFromRepo = _attachmentRepo.Query(a => a.AppId == appId && a.CustomerId == customerId); int seq = 1; if (attachmentsFromRepo != null) { // Loop by New Upload files from User foreach (var newAttachment in attachmentUploadResourceFiles) { var existingAttachment = _attachmentRepo.FindByKey(seq, newAttachment.AppId, newAttachment.CustomerId); // Add new if not found if (existingAttachment == null) { _attachmentRepo.Add(new Attachment { Id = seq, AppId = newAttachment.AppId, CustomerId = newAttachment.CustomerId, CCCreditChkId = creditCheckingId, AttachmentType = newAttachment.AttachmentType, Name = newAttachment.Name, FileName = string.Empty, Remark = string.Empty, Status = BusinessConstant.StatusActive, CreateBy = createdByUserId, CreateDate = DateTime.Now, UpdateBy = createdByUserId, UpdateDate = DateTime.Now }); } else { existingAttachment.Id = seq; existingAttachment.AppId = newAttachment.AppId; existingAttachment.CustomerId = newAttachment.CustomerId; existingAttachment.CCCreditChkId = creditCheckingId; existingAttachment.AttachmentType = newAttachment.AttachmentType; existingAttachment.Name = newAttachment.Name; existingAttachment.FileName = string.Empty; existingAttachment.Remark = string.Empty; existingAttachment.Status = BusinessConstant.StatusActive; existingAttachment.CreateBy = createdByUserId; existingAttachment.CreateDate = DateTime.Now; existingAttachment.UpdateBy = createdByUserId; existingAttachment.UpdateDate = DateTime.Now; } // //drSubAttachment.Attachment_CCCreditChkID = this.CCCreditChk_ID; seq++; } //_attachmentRepo.Commit(); } return(seq); }