예제 #1
0
        public void Create(HuntCreateModel model, int userId)
        {
            GameDto game         = null;
            int?    huntedGameId = null;

            if (model.GameType.HasValue & model.GameKind.HasValue)
            {
                game = _gameDao.Get(model.GameType.Value, model.GameKind.Value, model.GameSubKind).FirstOrDefault();

                var huntGameDto = new HuntedGameDto
                {
                    GameId     = game.Id,
                    GameClass  = model.GameClass,
                    GameWeight = model.GameWeight
                };

                huntedGameId = _huntedGameDao.Insert(huntGameDto);
            }

            int regionId = _regionDao.GetRegionId(model.City, model.Circuit, model.District);

            UserDto user = _userDao.GetById(userId);

            var huntDto = new HuntDto
            {
                HuntsmanId   = user.HuntsmanId,
                HuntedGameId = huntedGameId,
                RegionId     = regionId,
                Shots        = model.Shots,
                Date         = model.Date
            };

            _huntDao.Insert(huntDto);
        }
예제 #2
0
        public JsonResult Create(HuntCreateModel model)
        {
            HttpCookie userCookie = Request.Cookies["User"];

            if (userCookie == null)
            {
                return(Json(new { data = false }, JsonRequestBehavior.AllowGet));
            }

            string userIdString = userCookie["UserId"];

            if (!Int32.TryParse(userIdString, out int userId))
            {
                return(Json(new { data = false }, JsonRequestBehavior.AllowGet));
            }

            _huntService.Create(model, userId);
            return(Json(new { data = true }, JsonRequestBehavior.AllowGet));
        }