Пример #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);
        }
Пример #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);
        }
Пример #3
0
        public JsonResult Edit(GameCountPlanViewModel model, int marketingYearId)
        {
            string message = String.Empty;

            try
            {
                _gameCountPlanService.UpdateGameHuntPlan(model, marketingYearId);
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            return(Json(new { message }, JsonRequestBehavior.AllowGet));
        }