Ejemplo n.º 1
0
        public FileTransferResponse Put(FileTransferRequest fileToPush)
        {
            var fileTransferResponse = CheckFileTransferRequest(fileToPush);

            if (fileTransferResponse.ResponseStatus == "FileIsValed")
            {
                try
                {
                    SaveFileStream(System.Configuration.ConfigurationManager.AppSettings["SavedLocation"] + "\\" + fileToPush.FileName, new MemoryStream(fileToPush.Content));
                    return(new FileTransferResponse
                    {
                        CreateAt = DateTime.Now,
                        FileName = fileToPush.FileName,
                        Message = "File was transfered",
                        ResponseStatus = "Successful"
                    });
                }
                catch (Exception ex)
                {
                    return(new FileTransferResponse
                    {
                        CreateAt = DateTime.Now,
                        FileName = fileToPush.FileName,
                        Message = ex.Message,
                        ResponseStatus = "Error"
                    });
                }
            }

            return(fileTransferResponse);
        }
Ejemplo n.º 2
0
        private FileTransferResponse CheckFileTransferRequest(FileTransferRequest fileToPush)
        {
            if (fileToPush != null)
            {
                if (!string.IsNullOrEmpty(fileToPush.FileName))
                {
                    if (fileToPush.Content != null)
                    {
                        return(new FileTransferResponse
                        {
                            CreateAt = DateTime.Now,
                            FileName = fileToPush.FileName,
                            Message = string.Empty,
                            ResponseStatus = "FileIsValed"
                        });
                    }

                    return(new FileTransferResponse
                    {
                        CreateAt = DateTime.Now,
                        FileName = "No Name",
                        Message = " File Content is null",
                        ResponseStatus = "Error"
                    });
                }

                return(new FileTransferResponse
                {
                    CreateAt = DateTime.Now,
                    FileName = "No Name",
                    Message = " File Name Can't be Null",
                    ResponseStatus = "Error"
                });
            }

            return(new FileTransferResponse
            {
                CreateAt = DateTime.Now,
                FileName = "No Name",
                Message = " File Can't be Null",
                ResponseStatus = "Error"
            });
        }