Esempio n. 1
0
        public ActionResult Reset(TaskModel viewModel)
        {
            viewModel.OperationResult.Clear();

            try
            {
                if (!IsAuthorized("Reset", viewModel.OperationResult))
                {
                    return(View("OperationResult", new OperationResultModel(viewModel.OperationResult)));
                }
                else if (ValidateModelState())
                {
                    IChinookUnitOfWork unitOfWork = DependencyResolver.Current.GetService <IChinookUnitOfWork>();
                    Application.Reset(viewModel.OperationResult, unitOfWork);

                    viewModel.OperationResult.StatusMessage = TaskResetResources.Task + " Ok";
                }
            }
            catch (Exception exception)
            {
                viewModel.OperationResult.ParseException(exception);
            }

            return(JsonResultOperationResult(viewModel.OperationResult));
        }
        public bool Reset(ZOperationResult operationResult, IChinookUnitOfWork unitOfWork)
        {
            try
            {
                unitOfWork.ExecuteSQL("DELETE FROM InvoiceLine WHERE InvoiceLineId > 2240");
                unitOfWork.ExecuteSQL("DELETE FROM Invoice WHERE InvoiceId > 412");

                unitOfWork.ExecuteSQL("DELETE FROM CustomerDocument");
                unitOfWork.ExecuteSQL("DELETE FROM Customer WHERE CustomerId > 59");
                unitOfWork.ExecuteSQL("DELETE FROM Employee WHERE EmployeeId > 8");

                unitOfWork.ExecuteSQL("DELETE FROM PlaylistTrack WHERE PlaylistTrackId > 18 OR TrackId > 3503");
                unitOfWork.ExecuteSQL("DELETE FROM Track WHERE TrackId > 3503");
                unitOfWork.ExecuteSQL("DELETE FROM Playlist WHERE PlaylistId > 18");

                unitOfWork.ExecuteSQL("DELETE FROM Genre WHERE GenreId > 25");
                unitOfWork.ExecuteSQL("DELETE FROM MediaType WHERE MediaTypeId > 5");
                unitOfWork.ExecuteSQL("DELETE FROM Album WHERE AlbumId > 347");
                unitOfWork.ExecuteSQL("DELETE FROM Artist WHERE ArtistId > 275");
            }
            catch (Exception exception)
            {
                operationResult.ParseException(exception);
            }

            return(operationResult.Ok);
        }
Esempio n. 3
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));
        }
Esempio n. 4
0
        private static void ApplicationChinookReset()
        {
            Console.WriteLine("\nApplication Chinook RESET");

            var container = new UnityContainer();

            UnityHelper.RegisterMappings(container);

            ZOperationResult    operationResult = new ZOperationResult();
            IChinookUnitOfWork  unitOfWork      = (IChinookUnitOfWork)container.Resolve <IChinookUnitOfWork>();
            IChinookApplication application     = (IChinookApplication)container.Resolve <IChinookApplication>();

            application.Reset(operationResult, unitOfWork);

            if (!operationResult.Ok)
            {
                Console.WriteLine("\n");
                Console.WriteLine(operationResult.Text);
            }
        }
Esempio n. 5
0
 public MediaTypeController(IChinookUnitOfWork unitOfWork)
 {
     UnitOfWork = unitOfWork;
 }
 public ChinookGenericApplication(IChinookUnitOfWork unitOfWork, IAuditTrailManager auditTrailManager, ILogManager logManager, ISecurityManager securityManager)
     : base(unitOfWork, auditTrailManager, logManager, securityManager)
 {
 }
        public bool ImportGenreTXTPersistence(ZOperationResult operationResult, string filePath, IChinookUnitOfWork unitOfWork)
        {
            int genres = 0;

            try
            {
                // read record-by-record

                var asyncEngine = new FileHelperAsyncEngine <FileHelpersGenre>();
                IGenericRepository <Genre> repository = unitOfWork.GetRepository <Genre>();

                // Read
                using (asyncEngine.BeginReadFile(filePath))
                {
                    if (unitOfWork.BeginTransaction(operationResult))
                    {
                        try
                        {
                            foreach (FileHelpersGenre element in asyncEngine)
                            {
                                //operationResult.AddOperationError("", String.Format("Genre Name = {0}", element.Name));

                                Genre genre = new Genre(
                                    0,
                                    element.Name + " Persistence"
                                    );

                                if (repository.Create(operationResult, genre))
                                {
                                    if (unitOfWork.Save(operationResult))
                                    {
                                        genres++;
                                    }
                                }

                                if (!operationResult.Ok)
                                {
                                    break;
                                }
                            }
                        }
                        catch (Exception exception)
                        {
                            unitOfWork.RollbackTransaction(operationResult);
                            operationResult.ParseException(exception);
                        }
                        finally
                        {
                            unitOfWork.CommitTransaction(operationResult);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                operationResult.ParseException(exception);
            }

            if (operationResult.Ok)
            {
                operationResult.StatusMessage = String.Format("{0} Genres imported", genres);
            }

            return(operationResult.Ok);
        }
 public ChinookApplication(IChinookUnitOfWork unitOfWork, IAuditTrailManager auditTrailManager, ILogManager logManager)
 {
     _auditTrailManager = auditTrailManager;
     _logManager        = logManager;
 }
 public GenreController(IChinookUnitOfWork unitOfWork)
 {
     UnitOfWork = unitOfWork;
 }