private IHttpActionResult CreateUser(StarWarsUserCreationModel model)
        {
            Team team = new Team
            {
                Name = model.Name,
            };
            User user = new User
            {
                Name = model.Name,
                PhoneNumber = model.PhoneNo,
                Team = team,
            };
            

            using (TreasureContext db = new TreasureContext())
            {
                db.Teams.Add(team);
                db.Users.Add(user);
                db.SaveChanges();
                
                Dictionary<int, Page> pages = (from p in db.Page select p).ToDictionary(p=>p.PageID);
                

                int pointID = user.UserID%4;
                if (pointID%2 == 0) 
                    team.CurrentPage = pages[2];
                else
                    team.CurrentPage = pages[pointID];

                db.SaveChanges();

                return Ok(new StarWarsUserCreationViewModel{UserID = user.UserID});
            }
        }
 public IHttpActionResult Get(long id)
 {
     using (TreasureContext db = new TreasureContext())
     {
         User user = _userService.GetUserFromUserID(id, db);
         if (user == null) return BadRequest("Invalid User ID");
         return Ok(Map(user));
     }
 }
        public ActionResult InitialSetup()
        {
            TreasureContext db = new TreasureContext();

            Team team = new Team
            {
                CurrentPage = new Page{PageID=1},
                Name = "Team Win",
            };
            User rupesh = new User
            {
                Name = "Rupesh",
                PhoneNumber = "+447796616402",
                Team = team
            };
            User stu = new User
            {
                Name = "Rupesh",
                PhoneNumber = "+447796616402",
                Team = team
            };

            Page page1 = new Page();
            page1.Items.Add(new BasicSingleActionPageItem
            {
                ExpectedInput = "Hello",
                CorrectResponse = "Mary’s father has 5 daughters – Nana, Nene, Nini, Nono. What is the fifth daughters name?",
                IncorrectResponse = "Mary’s father has 5 daughters – Nana, Nene, Nini, Nono. What is the fifth daughters name?",
                ExpectedInputNumber = "+441506243065",
                NextPage = new Page{PageID = 2},
                Interaction = InteractionType.TextMessage,
            });
            Page page2 = new Page();
            page2.Items.Add(new BasicSingleActionPageItem
            {
                ExpectedInput = "Mary",
                CorrectResponse = "Hurrah!",
                IncorrectResponse = "No!",
                ExpectedInputNumber = "+441506243065",
                Interaction = InteractionType.TextMessage,
                NextPage = new Page{PageID = 2},
            });

            db.Teams.Add(team);
            db.Users.Add(rupesh);
            db.Users.Add(stu);

            db.Page.Add(page1);
            db.Page.Add(page2);

            db.SaveChanges();

            return Json("Done", JsonRequestBehavior.AllowGet);
        }
 private HttpResponseMessage GetResponse(SmsRequest req)
 {
     try
     {
         using (TreasureContext db = new TreasureContext())
         {
             User user = _userService.GetUserFromPhoneNo(req.From, db);
             if (user==null) return Request.CreateResponse(HttpStatusCode.OK, IDontKnowYou().Element, new XmlMediaTypeFormatter());
             TwilioResponse result = _storyTellerService.ReadStory(user, req.Body, req.To);
             db.SaveChanges();
             return Request.CreateResponse(HttpStatusCode.OK, result.Element, new XmlMediaTypeFormatter());
         }
     }
     catch (Exception e)
     {
         TwilioResponse resp = new TwilioResponse();
         resp.Say(e.Message);
         return Request.CreateResponse(HttpStatusCode.OK, resp.Element, new XmlMediaTypeFormatter());
     }
 }