예제 #1
0
        /// <summary>
        /// convert attachment view model to domain
        /// </summary>
        /// <param name="attachmentModel"></param>
        /// <returns></returns>
        public DebitMemoAttachment ConvertToDomain(AttachmentModel attachmentModel)
        {
            DebitMemoAttachment attachment = new DebitMemoAttachment();

            byte[] tempFile = new byte[attachmentModel.Attachment.ContentLength];

            var trimmedFileName = string.Empty;

            if (attachmentModel.Attachment.FileName.EndsWith("png"))
            {
                trimmedFileName = attachmentModel.Attachment.FileName.Replace(".png", "");
            }
            else if (attachmentModel.Attachment.FileName.EndsWith("jpg"))
            {
                trimmedFileName = attachmentModel.Attachment.FileName.Replace(".jpg", "");
            }
            else if (attachmentModel.Attachment.FileName.EndsWith("pdf"))
            {
                trimmedFileName = attachmentModel.Attachment.FileName.Replace(".pdf", "");
            }

            attachment.DebitMemoId = attachmentModel.DebitMemoId;
            attachment.Name        = trimmedFileName;
            attachment.Type        = attachmentModel.Attachment.ContentType;
            attachment.Length      = attachmentModel.Attachment.ContentLength;
            attachment.Content     = tempFile;

            return(attachment);
        }
예제 #2
0
        /// <summary>
        /// convert attachment to view model
        /// </summary>
        /// <param name="attachment"></param>
        /// <returns></returns>
        public DebitMemoAttachmentViewModel ConvertToView(DebitMemoAttachment attachment)
        {
            DebitMemoAttachmentViewModel model = new DebitMemoAttachmentViewModel();

            model.DebitMemoAttachmentId = attachment.DebitMemoAttachmentId;
            model.AttachmentName        = (!string.IsNullOrEmpty(attachment.Name)) ? attachment.Name : "N/A";

            return(model);
        }
예제 #3
0
        /// <summary>
        /// get debit memo attachment by id
        /// </summary>
        /// <param name="attachmentId"></param>
        /// <returns></returns>
        public DebitMemoAttachment GetDebitMemoAttachment(Guid attachmentId)
        {
            var debitMemoAttachment = new DebitMemoAttachment();

            try
            {
                debitMemoAttachment = _db.DebitMemoAttachment.FirstOrDefault(x => x.DebitMemoAttachmentId == attachmentId);
            }
            catch (Exception ex)
            {
                logger.ErrorFormat("Error getting debit memo attachment: {0} ", ex.ToString());
            }

            return(debitMemoAttachment);
        }
예제 #4
0
        /// <summary>
        /// save debit memo attachment
        /// </summary>
        /// <param name="newDebitMemoAttachment"></param>
        /// <returns></returns>
        public OperationResult SaveDebitMemoAttachment(DebitMemoAttachment newDebitMemoAttachment)
        {
            var operationResult = new OperationResult();

            try
            {
                var existingDebitMemoAttachment = _db.DebitMemoAttachment.FirstOrDefault(x => x.Name.ToLower() == newDebitMemoAttachment.Name.ToLower() && x.DebitMemoId == newDebitMemoAttachment.DebitMemoId);

                if (existingDebitMemoAttachment == null)
                {
                    logger.Debug("DebitMemoAttachment is being created...");

                    var insertedDebitMemoAttachment = _db.DebitMemoAttachment.Add(newDebitMemoAttachment);

                    _db.SaveChanges();

                    operationResult.Success     = true;
                    operationResult.Message     = "Success";
                    operationResult.ReferenceId = insertedDebitMemoAttachment.DebitMemoAttachmentId;
                    operationResult.Name        = insertedDebitMemoAttachment.Name;
                }
                else
                {
                    operationResult.Success = false;
                    operationResult.Message = "Duplicate Entry";
                }
            }
            catch (Exception ex)
            {
                operationResult.Success = false;
                operationResult.Message = "Error";
                logger.ErrorFormat("Error saving new DebitMemoAttachment: {0} ", ex.ToString());
            }

            return(operationResult);
        }