Esempio n. 1
0
        public void AddGameHuntPlan(GameCountPlanViewModel model, int marketingYearId)
        {
            IList <GameDto> games = _gameDao.GetByKindName(model.GameKindName);

            if (!String.IsNullOrWhiteSpace(model.GameSubKindName))
            {
                games = games.Where(x => x.SubKindName == model.GameSubKindName).ToList();
            }

            int gameId = games.Select(x => x.Id).FirstOrDefault();
            IList <GameCountFor10MarchDto> existingGameCountPlanDto = _gameCountFor10MarchDao.GetByMarketingYear(marketingYearId);

            if (existingGameCountPlanDto.Any(x => x.GameId == gameId && x.Class == model.Class))
            {
                throw new Exception($"Plan liczebności zwierzyny {model.GameKindName} - {model.GameSubKindName} - {model.ClassName} już istnieje! Proszę użyć opcji edycji istniejącego już planu.");
            }

            var dto = new GameCountFor10MarchDto
            {
                GameId          = gameId,
                Class           = model.Class,
                Count           = model.Count,
                MarketingYearId = marketingYearId
            };

            _gameCountFor10MarchDao.Insert(dto);
        }
Esempio n. 2
0
        public void UpdateGameHuntPlan(GameCountPlanViewModel model, int marketingYearId)
        {
            var dto = new GameCountFor10MarchDto
            {
                Id              = model.Id,
                GameId          = model.GameId,
                Class           = model.Class,
                Count           = model.Count,
                MarketingYearId = marketingYearId
            };

            _gameCountFor10MarchDao.Update(dto);
        }
Esempio n. 3
0
        public void Insert(GameCountFor10MarchDto dto)
        {
            var entity = new Entities.GameCountFor10March
            {
                GameId          = dto.GameId,
                Class           = dto.Class,
                Count           = dto.Count,
                MarketingYearId = dto.MarketingYearId
            };

            using (var db = new DbContext())
            {
                db.GameCountFor10March.Add(entity);
                db.SaveChanges();
            }
        }
Esempio n. 4
0
        private IList <GameCountFor10MarchDto> ToDtos(IList <Entities.GameCountFor10March> entityList)
        {
            var dtos = new List <GameCountFor10MarchDto>();

            foreach (Entities.GameCountFor10March entity in entityList)
            {
                var dto = new GameCountFor10MarchDto
                {
                    Id              = entity.Id,
                    GameId          = entity.GameId,
                    Class           = entity.Class,
                    Count           = entity.Count,
                    MarketingYearId = entity.MarketingYearId
                };
                dtos.Add(dto);
            }
            return(dtos);
        }
Esempio n. 5
0
        public void Update(GameCountFor10MarchDto dto)
        {
            using (var db = new DbContext())
            {
                Entities.GameCountFor10March gameCountFor10MarchPlan;
                if (dto.Id > 0)
                {
                    gameCountFor10MarchPlan = db.GameCountFor10March.Single(x => x.Id == dto.Id);
                }
                else if (dto.GameId > 0 && dto.MarketingYearId > 0)
                {
                    gameCountFor10MarchPlan = db.GameCountFor10March.Single(x => x.GameId == dto.GameId && x.MarketingYearId == dto.MarketingYearId);
                }
                else
                {
                    throw new Exception($"Nie można edytować planu liczebności zwierzyny");
                }

                gameCountFor10MarchPlan.Count = dto.Count;

                db.SaveChanges();
            }
        }