public async Task <ActionResult> Edit([Bind(Include = DocumentValidationBinding)] FileDetailsViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                var userId    = this.UserId;
                var articleId = this.FakeArticleId;

                await this.service.UpdateMeta(
                    userId,
                    articleId,
                    new DocumentServiceModel
                {
                    Id            = model.DocumentId,
                    Comment       = model.Comment,
                    ContentType   = model.ContentType,
                    FileExtension = model.FileExtension,
                    FileName      = model.FileName
                });

                this.Response.StatusCode = (int)HttpStatusCode.Redirect;
                return(this.RedirectToAction(nameof(this.Index)));
            }

            this.Response.StatusCode = (int)HttpStatusCode.BadRequest;
            return(this.View(model));
        }
Esempio n. 2
0
        public static async Task <bool> DownloadFile(FileDetailsViewModel file)
        {
            try
            {
                //Send a response to try and download the file
                HttpResponseMessage resp = clientFiles.Download(new Guid(file.Id));

                byte[] bytes = resp.Content.ReadAsByteArrayAsync().Result;


                string localPath = System.IO.Path.Combine(Common.Instance.DocumentFilePath, file.Name);

                // var imagePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                //var imagePath1 = System.IO.Path.Combine(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryPictures).ToString(), "MyFolderName");


                FileStream wFile = new FileStream(localPath, FileMode.Create);
                wFile.Write(bytes, 0, bytes.Length);
                wFile.Close();
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        public FileDetailsPage(Guid fileId)
        {
            //HockeyApp.MetricsManager.TrackEvent("FileDetailsPage Initialize");
            NavigationPage.SetBackButtonTitle(this, "");
            BindingContext = viewModel = new FileDetailsViewModel();
            InitializeComponent();

            GetObicen(fileId);
        }
        /// <summary>
        /// Converts from.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns></returns>
        public FileDetailsViewModel ConvertFrom(FileDetailsModel model)
        {
            if (model == null)
            {
                return(null);
            }


            FileDetailsViewModel viewModel = new FileDetailsViewModel
            {
                ProcessingSummary = new FileProcessingSummaryViewModel
                {
                    TotalLines   = model.ProcessingSummary.TotalLines,
                    IgnoredLines = model.ProcessingSummary.IgnoredLines,
                    SuccessfullyProcessedLines = model.ProcessingSummary.SuccessfullyProcessedLines,
                    FailedLines       = model.ProcessingSummary.FailedLines,
                    NotProcessedLines = model.ProcessingSummary.NotProcessedLines,
                    RejectedLines     = model.ProcessingSummary.RejectedLines
                },
                ProcessingCompleted = model.ProcessingCompleted,
                EstateId            = model.EstateId,
                FileId          = model.FileId,
                FileImportLogId = model.FileImportLogId,
                FileLines       = new List <FileLineViewModel>(),
                FileLocation    = model.FileLocation,
                FileProfileId   = model.FileProfileId,
                MerchantId      = model.MerchantId,
                UserId          = model.UserId
            };

            if (model.FileLines.Any())
            {
                foreach (FileLineModel modelFileLine in model.FileLines)
                {
                    FileLineViewModel fileLineViewModel = new FileLineViewModel
                    {
                        LineData        = modelFileLine.LineData,
                        LineNumber      = modelFileLine.LineNumber,
                        TransactionId   = modelFileLine.TransactionId,
                        RejectionReason = modelFileLine.RejectionReason
                    };

                    // Translate the processing result
                    (FileLineProcessingResult result, String stringResult)processingResult = this.ConvertFrom(modelFileLine.ProcessingResult);

                    fileLineViewModel.ProcessingResult       = processingResult.result;
                    fileLineViewModel.ProcessingResultString = processingResult.stringResult;

                    viewModel.FileLines.Add(fileLineViewModel);
                }
            }

            return(viewModel);
        }
        public FileDetailsControl()
        {
            InitializeComponent();

            if (!DesignerProperties.GetIsInDesignMode(this))
            {
                var model = GroupsServiceLocator.Instance.Resolve<IFileDetailsModel>();
                if (model != null)
                {
                    DataContext = new FileDetailsViewModel(model);
                }
            }

            FileNameTextBox.KeyDown += OnKeyDown;
        }
        public async Task <IActionResult> GetFileLineListAsJson([FromQuery] Guid fileId,
                                                                CancellationToken cancellationToken)
        {
            try
            {
                String accessToken = await this.HttpContext.GetTokenAsync("access_token");

                FileDetailsModel fileDetailsModel = await this.ApiClient.GetFileDetails(accessToken, this.User.Identity as ClaimsIdentity, fileId, cancellationToken);

                FileDetailsViewModel viewModel = this.ViewModelFactory.ConvertFrom(fileDetailsModel);

                return(this.Json(Helpers.GetDataForDataTable(this.Request.Form, viewModel.FileLines)));
            }
            catch (Exception e)
            {
                Logger.LogError(e);
                return(this.Json(Helpers.GetErrorDataForDataTable <String>("Failed to get File Details Record")));
            }
        }
        private async Task <FileDetailsViewModel> GetDetails(object userId, object articleId, object id)
        {
            if (userId == null)
            {
                throw new ArgumentNullException(nameof(userId));
            }

            if (articleId == null)
            {
                throw new ArgumentNullException(nameof(articleId));
            }

            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            var document = await this.service.Get(userId, articleId, id);

            if (document == null)
            {
                throw new EntityNotFoundException();
            }

            var viewModel = new FileDetailsViewModel
            {
                ArticleId     = articleId.ToString(),
                DocumentId    = document.Id.ToString(),
                FileName      = document.FileName,
                FileExtension = document.FileExtension,
                Comment       = document.Comment,
                ContentType   = document.ContentType,
                ContentLength = document.ContentLength,
                DateCreated   = document.DateCreated,
                DateModified  = document.DateModified
            };

            return(viewModel);
        }
        private async Task <bool> GetFile(Guid fileId)
        {
            try
            {
                var file = await DocumentsService.GetFile(fileId);

                var item = new FileDetailsViewModel
                {
                    Id    = fileId.ToString(),
                    Name  = file.Name,
                    Title = file.Name,
                    Icon  = Common.CurrentWorkspace.WorkspaceURL.ToLower().Replace("/projectinsight.webapp", "") + file.UrlIcon
                };

                if (!string.IsNullOrEmpty(file.UrlThumbnail))
                {
                    item.Icon = Common.CurrentWorkspace.WorkspaceURL + file.UrlThumbnail.ToLower().Replace("/projectinsight.webapp", "") + "?api-token=" + Common.CurrentWorkspace.ApiToken;
                }
                if (file.UserCreated.Id.Value.Equals(Common.CurrentWorkspace.UserID))
                {
                    item.CanDelete = true;
                }

                if (file.UserCreated != null)
                {
                    item.Created = file.UserCreated.FirstName + " " + file.UserCreated.LastName + " ";
                }
                if (file.CreatedDateTimeUTC != null)
                {
                    item.Created += file.CreatedDateTimeUTC.Value.ToString("ddd M/d/yy h:mmtt");
                }
                if (!string.IsNullOrEmpty(item.Created))
                {
                    item.Created = "Created: " + item.Created;
                }


                if (file.UserUpdated != null)
                {
                    item.Updated = file.UserUpdated.FirstName + " " + file.UserUpdated.LastName + " ";
                }
                if (file.UpdatedDateTimeUTC != null)
                {
                    item.Updated += file.UpdatedDateTimeUTC.Value.ToString("ddd M/d/yy h:mmtt");
                }
                if (!string.IsNullOrEmpty(item.Updated))
                {
                    item.Updated = "Updated: " + item.Updated;
                }


                viewModel      = item;
                BindingContext = viewModel;
            }
            catch (Exception ex)
            {
                //AuthenticationService.Logout();
                return(false);
            }
            return(true);
        }
 public FileDetails(File file)
 {
     vm             = new FileDetailsViewModel(file);
     BindingContext = vm;
     InitializeComponent();
 }