Esempio n. 1
0
        private async Task <AttachmentEditOutput> ExecuteNewAttachment(AttachmentEditInput input)
        {
            Attachment attachment = new Attachment(DateTime.Now, input.Name, input.SourceReference);

            attachment.Description = input.Description;
            switch (input.AttachmentBy)
            {
            case GetAttachmentBy.PART:
                attachment.PartId = input.EntityId;
                break;

            case GetAttachmentBy.PARTINSTANCE:
                attachment.PartInstanceId = input.EntityId;
                break;

            case GetAttachmentBy.PRICE:
                attachment.PriceId = input.EntityId;
                break;

            case GetAttachmentBy.DISTRIBUTOR:
                attachment.DistributorId = input.EntityId;
                break;

            case GetAttachmentBy.MANUFACTURER:
                attachment.ManufacturerId = input.EntityId;
                break;

            default:
                return(new AttachmentEditOutput(null, false, "Invalid Entity Type"));
            }
            var response = await FileService.UploadFileAsync(input.SourceReference, input.Name);

            if (!string.IsNullOrEmpty(response))
            {
                attachment.FileReference = response;
                var entity = await this._attachmentRepositry.AddAsync(attachment);

                var count = await this._unitOfWork.Save();

                if (count > 0)
                {
                    return(new AttachmentEditOutput(entity, true, "Success"));
                }
                else
                {
                    await FileService.DeleteFileAsync(input.SourceReference);

                    await this._unitOfWork.Undo();

                    return(new AttachmentEditOutput(null, false, "Save Failed"));
                }
            }
            else
            {
                return(new AttachmentEditOutput(null, false, "Error Uploading File"));
            }
        }
Esempio n. 2
0
        public async Task <AttachmentEditOutput> Execute(AttachmentEditInput input)
        {
            switch (input.AttachmentOperation)
            {
            case AttachmentOperation.DELETE:
                return(await this.ExecuteDeleteAttachment(input));

            case AttachmentOperation.NEW:
                return(await this.ExecuteNewAttachment(input));

            default:
                return(new AttachmentEditOutput(null, false, "Invalid Attachment Operation"));
            }
        }
Esempio n. 3
0
        private async Task <AttachmentEditOutput> ExecuteDeleteAttachment(AttachmentEditInput input)
        {
            var attachment = await this._attachmentRepositry.GetEntityAsync(e => e.Id == input.AttachmentId);

            if (attachment != null)
            {
                var response = await FileService.DeleteFileAsync(attachment.FileReference);

                if (response)
                {
                    var entity = await this._attachmentRepositry.DeleteAsync(attachment);

                    var count = await this._unitOfWork.Save();

                    if (count > 0)
                    {
                        return(new AttachmentEditOutput(entity, true, "Success"));
                    }
                    else
                    {
                        await FileService.DeleteFileAsync(input.SourceReference);

                        await this._unitOfWork.Undo();

                        return(new AttachmentEditOutput(null, false, "Save Failed"));
                    }
                }
                else
                {
                    return(new AttachmentEditOutput(null, false, "Invalid Entity Type"));
                }
            }
            else
            {
                return(new AttachmentEditOutput(null, false, "Attachment Not Found"));
            }
        }