Пример #1
0
        public ActionResult ImportGenre()
        {
            if (!IsAuthorized("ImportGenre", OperationResult))
            {
                return(View("OperationResult", new OperationResultModel(OperationResult)));
            }

            TaskImportGenreModel viewModel = new TaskImportGenreModel();

            return(View(viewModel));
        }
Пример #2
0
        public ActionResult ImportGenre(TaskImportGenreModel viewModel)
        {
            viewModel.OperationResult.Clear();

            string path = "";

            try
            {
                if (!IsAuthorized("ImportGenre", viewModel.OperationResult))
                {
                    return(View("OperationResult", new OperationResultModel(viewModel.OperationResult)));
                }
                else if (ValidateModelState())
                {
                    if (viewModel.Upload != null && viewModel.Upload.ContentLength > 0)
                    {
                        // Save file

                        string file = Path.GetFileName(viewModel.Upload.FileName);
                        path = Path.Combine(Server.MapPath(LibraryHelper.AppSettings <string>("DirectoryImport")), file);
                        viewModel.Upload.SaveAs(path);

                        // Read file and Create Genre

                        // Application
                        IChinookGenericApplication <Genre> genreApplication =
                            DependencyResolver.Current.GetService <IChinookGenericApplication <Genre> >();
                        Application.ImportGenreTXTApplication(viewModel.OperationResult, path, genreApplication);

                        // Persistence
                        IChinookUnitOfWork unitOfWork =
                            DependencyResolver.Current.GetService <IChinookUnitOfWork>();
                        Application.ImportGenreTXTPersistence(viewModel.OperationResult, path, unitOfWork);
                    }
                }
            }
            catch (Exception exception)
            {
                viewModel.OperationResult.ParseException(exception);
            }
            finally
            {
                if (!String.IsNullOrEmpty(path))
                {
                    System.IO.File.Delete(path);
                }
            }

            return(View(viewModel));
        }