Ejemplo n.º 1
0
        public ExeResult Create(GenreModel genreToDB)
        {
            message.Clear();
            ValidationCharacterLenght(genreToDB);

            Genres genreTemp = _repository.GetByName(genreToDB.Name);

            if (genreTemp != null)
            {
                if (genreTemp.Name == genreToDB.Name)
                {
                    message.Add("This Name already exists.");
                }
            }

            if (message.Count != 0)
            {
                return(new ExeResult(message));
            }

            var genre = ControlTools.MapTo <GenreModel, Genres>(genreToDB);

            genreToDB.Id = _repository.Create(genre);
            if (genreToDB.Id == 0)
            {
                return(new ExeResult(new List <string>()
                {
                    "Genre not create"
                }));
            }

            return(new ExeResult(new List <string>()));;
        }
Ejemplo n.º 2
0
        public ExeResult Update(PublisherModel model)
        {
            message.Clear();
            if (model.Name.Length > MaxNameSize)
            {
                message.Add($"Long name >{MaxNameSize}.");
            }

            var publish = ControlTools.MapTo <PublisherModel, Publisher>(model);
            var result  = ControlTools.DbExec(_repository.Update, publish, "Publisher not update");

            return(result);
        }
Ejemplo n.º 3
0
        public ExeResult Update(GameModel model)
        {
            ExeResult exRes = AllValidationWithErrorMessge(model);

            if (exRes.IsError)
            {
                return(exRes);
            }

            var game = ControlTools.MapTo <GameModel, Games>(model);

            exRes = ControlTools.DbExec(_repository.Update, game, "Game not update");
            return(exRes);
        }
Ejemplo n.º 4
0
        public ExeResult Delete(PublisherModel model)
        {
            if (_repository.GetById(model.Id) == null)
            {
                return(new ExeResult(new List <string>()
                {
                    "This publisher is unknown."
                }));
            }

            var publisher = ControlTools.MapTo <PublisherModel, Publisher>(model);
            var result    = ControlTools.DbExec(_repository.Delete, publisher, "Genre not delete");

            return(result);
        }
Ejemplo n.º 5
0
        public ExeResult Delete(GameModel model)
        {
            if (_repository.GetById(model.Id) == null)
            {
                return(new ExeResult(new List <string>()
                {
                    "This game is unknown."
                }));
            }

            var game   = ControlTools.MapTo <GameModel, Games>(model);
            var result = ControlTools.DbExec(_repository.Delete, game, "Game not delete");

            return(result);
        }
Ejemplo n.º 6
0
        public ExeResult Delete(GenreModel genreToDB)
        {
            message.Clear();
            if (_repository.GetById(genreToDB.Id) == null)
            {
                return(new ExeResult(new List <string>()
                {
                    "This genre is unknown."
                }));
            }

            var genre  = ControlTools.MapTo <GenreModel, Genres>(genreToDB);
            var result = ControlTools.DbExec(_repository.Delete, genre, "Genre not delete");

            return(result);
        }
Ejemplo n.º 7
0
        public ExeResult Update(GenreModel genreToDB)
        {
            message.Clear();
            //Нужна ли эта проверка
            //if (_repository.GetById(genreToDB.Id) == null) message.Add("This genre is unknown.");

            ValidationCharacterLenght(genreToDB);
            if (message.Count != 0)
            {
                return(new ExeResult(message));
            }

            var genre  = ControlTools.MapTo <GenreModel, Genres>(genreToDB);
            var result = ControlTools.DbExec(_repository.Update, genre, "Genre not update");

            return(result);
        }
Ejemplo n.º 8
0
        public IEnumerable <GenreModel> GetAll()
        {
            List <GenreModel> genresModel = new List <GenreModel>();
            var result             = _repository.GetAll();
            ParallelLoopResult res = Parallel.ForEach(result, item =>
            {
                genresModel.Add(ControlTools.MapTo <Genres, GenreModel>(item));
            });

            //очень не красиво тута
            while (!res.IsCompleted)
            {
            }
            ;

            return(genresModel);
        }
Ejemplo n.º 9
0
        public IEnumerable <GameModel> GetAll()
        {
            List <GameModel> gameModel = new List <GameModel>();
            var result             = _repository.GetAll();
            ParallelLoopResult res = Parallel.ForEach(result, item =>
            {
                gameModel.Add(ControlTools.MapTo <Games, GameModel>(item));
            });

            //очень не красиво тута
            while (!res.IsCompleted)
            {
            }
            ;

            return(gameModel.AsParallel().Where(i => AllValidation(i)));
        }
Ejemplo n.º 10
0
        public IEnumerable <GameModel> GetByPublisher(int publisherId)
        {
            List <GameModel> gameModel = new List <GameModel>();
            var result             = _repository.GetGamesByPublisher(publisherId);
            ParallelLoopResult res = Parallel.ForEach(result, item =>
            {
                gameModel.Add(ControlTools.MapTo <Games, GameModel>(item));
            });

            //очень не красиво тута
            while (!res.IsCompleted)
            {
            }
            ;

            return(gameModel);
        }
Ejemplo n.º 11
0
        public ExeResult GetById(int id, out PublisherModel model)
        {
            model = ControlTools.MapTo <Publisher, PublisherModel>(_repository.GetById(id));
            if (model == null)
            {
                return(new ExeResult(new List <string>()
                {
                    "Unknown id"
                }));
            }
            if (model.Name.Length > MaxNameSize)
            {
                return(new ExeResult(new List <string>()
                {
                    $"Long name >{MaxNameSize}."
                }));
            }

            return(new ExeResult(null));
        }
Ejemplo n.º 12
0
        public ExeResult GetById(int id, out GameModel model)
        {
            model = ControlTools.MapTo <Games, GameModel>(_repository.GetById(id));
            if (model == null)
            {
                return(new ExeResult(new List <string>()
                {
                    "Unknown id"
                }));
            }
            ExeResult exRes = AllValidationWithErrorMessge(model);

            if (exRes.IsError)
            {
                model = null;
                return(exRes);
            }

            return(new ExeResult(new List <string>()));
        }
Ejemplo n.º 13
0
        public ExeResult GetById(int id, out GenreModel genreModel)
        {
            message.Clear();
            genreModel = ControlTools.MapTo <Genres, GenreModel>(_repository.GetById(id));
            if (genreModel == null)
            {
                return(new ExeResult(new List <string>()
                {
                    "Unknown id"
                }));
            }
            else
            {
                ValidationCharacterLenght(genreModel);
            }
            if (message.Count != 0)
            {
                return(new ExeResult(message));
            }

            return(new ExeResult(new List <string>()));
        }
Ejemplo n.º 14
0
        public ExeResult Create(GameModel model)
        {
            ExeResult exRes = AllValidationWithErrorMessge(model);

            if (exRes.IsError)
            {
                return(exRes);
            }

            var game = ControlTools.MapTo <GameModel, Games>(model);

            model.Id = _repository.Create(game);
            if (model.Id == 0)
            {
                return(new ExeResult(new List <string>()
                {
                    "Game not create"
                }));
            }

            return(new ExeResult(new List <string>()));;
        }
Ejemplo n.º 15
0
        public ExeResult Create(PublisherModel model)
        {
            message.Clear();
            if (model.Name.Length > MaxNameSize)
            {
                message.Add($"Long name >{MaxNameSize}.");
            }

            Publisher publisherTemp = _repository.GetByName(model.Name);

            if (publisherTemp != null)
            {
                if (publisherTemp.Name == model.Name)
                {
                    message.Add("This Name already exists.");
                }
            }

            if (message.Count != 0)
            {
                return(new ExeResult(message));
            }

            var publisher = ControlTools.MapTo <PublisherModel, Publisher>(model);

            model.Id = _repository.Create(publisher);
            if (model.Id == 0)
            {
                return(new ExeResult(new List <string>()
                {
                    "Publisher not create"
                }));
            }

            return(new ExeResult(new List <string>()));;
        }
Ejemplo n.º 16
0
        public GameModel GetByNameYearPublishing(GameModel model)
        {
            Games game = ControlTools.MapTo <GameModel, Games>(model);

            return(ControlTools.MapTo <Games, GameModel>(_repository.GetByNameYearPublishing(game)));
        }