示例#1
0
 public GuessModel(Guess guess)
 {
     this.Id = guess.Id;
     UserId = guess.UserId;
     Username = guess.User.UserName;
     GameId = guess.GameId;
     Number = guess.Number;
     DateMade = guess.DateMade;
     CowsCount = guess.CowsCount;
     BullsCount = guess.BullsCount;
 }
示例#2
0
        public IHttpActionResult Guess(int id, GuessModel model)
        {
            var userId = this.User.Identity.GetUserId();
            var author = this.data.Users.Find(userId);
            var newGuess = new Guess
            {
                UserId = userId,
                User = author,
                GameId = id,
                Number = model.Number,
                DateMade = DateTime.Now,
                CowsCount = 0,
                BullsCount = 0
            };


            this.data.Guesses.Add(newGuess);
            this.data.SaveChanges();

            var guessModel = new GuessModel(newGuess);

            // Send Notification to the guess maker
            string notificationMessage = "You have made new guess ("+model.Number+") on game №: " + id;
            SendNotification(id, userId, "GuessMade", notificationMessage);

            return Ok(guessModel);
        }