Example #1
0
 public void UploadGame(UploadGame uploadGame)
 {
     if (uploadGame.Key == "")
     {
         dbContext.Game.Add(uploadGame.Game);
         dbContext.SaveChanges();
     }
 }
Example #2
0
        public ActionResult CreateAccount(CreateAccount createAccount)
        {
            try
            {
                if (!dbContext.User.Any(e => e.Email == createAccount.Email || e.Username == createAccount.Username))
                {
                    var result = PasswordHasher.Hash(createAccount.Password);

                    User user = new User();
                    user.CreatedDatetime = DateTime.Now;
                    user.Email           = createAccount.Email;
                    user.Username        = createAccount.Username;
                    user.Password        = result.password;
                    user.Salt            = result.salt;

                    dbContext.User.Add(user);

                    dbContext.SaveChanges();
                    return(StatusCode((int)HttpStatusCode.OK));
                }
                else
                {
                    if (dbContext.User.Any(e => e.Email == createAccount.Email))
                    {
                        Request.HttpContext.Response.StatusCode = (int)HttpStatusCode.Conflict;
                        return(Content("Email"));
                    }
                    else
                    {
                        Request.HttpContext.Response.StatusCode = (int)HttpStatusCode.Conflict;
                        return(Content("Username"));
                    }
                }
            }
            catch (Exception ex)
            {
                return(StatusCode((int)HttpStatusCode.ServiceUnavailable));
            }
        }
Example #3
0
        private void Save(object sender, EventArgs e)
        {
            int lastPuzzleId = GetLastPuzzleId();
            int newPuzzleId  = ++lastPuzzleId;

            using (var db = new PuzzleContext())
            {
                List <Puzzle> cells = new List <Puzzle>();
                for (int r = 0; r < 9; r++)
                {
                    for (int c = 0; c < 9; c++)
                    {
                        cells.Add(new Puzzle()
                        {
                            row = r, col = c, puzzleId = newPuzzleId, value = puzzleView.cellValues[r, c]
                        });
                    }
                }
                db.PuzzleCells.AddRange(cells);
                db.SaveChanges();
            }

            UpdatePuzzleIds();
        }
Example #4
0
        public ActionResult DeleteLog_withoutspace(string time)
        {
            User u = (User)Session["User"];

            ViewBag.account = u.user_account;
            Score[]     sList = sc.ScoreList.Where(s => s.uploader == u.user_account && s.uploadtime == time).ToArray();
            Puzzle[]    pList = pc.PuzzleList.Where(p => p.uploader == u.user_account && p.uploadtime == time).ToArray();
            Knowledge[] kList = kc.KnowledgeList.Where(k => k.uploader == u.user_account && k.uploadtime == time).ToArray();
            for (int i = 0; i < sList.Length; i++)
            {
                if (ModelState.IsValid)
                {
                    sc.ScoreList.Remove(sList[i]);
                    sc.SaveChanges();
                }
                else
                {
                    return(Content("error"));
                }
            }
            for (int i = 0; i < kList.Length; i++)
            {
                if (ModelState.IsValid)
                {
                    kc.KnowledgeList.Remove(kList[i]);
                    kc.SaveChanges();
                }
                else
                {
                    return(Content("error"));
                }
            }
            for (int i = 0; i < pList.Length; i++)
            {
                if (ModelState.IsValid)
                {
                    pc.PuzzleList.Remove(pList[i]);
                    pc.SaveChanges();
                }
                else
                {
                    return(Content("error"));
                }
            }
            sList = sc.ScoreList.ToArray();
            int max_index = Convert.ToInt32(time);

            for (int i = 0; i < sList.Length; i++)
            {
                if (Convert.ToInt32(sList[i].updatetime) > max_index)
                {
                    max_index = (Convert.ToInt32(sList[i].updatetime));
                }
            }
            for (int i = Convert.ToInt32(time) + 1; i <= max_index; i++)
            {
                string temp = i.ToString();
                sList = sc.ScoreList.Where(s => s.updatetime == temp).ToArray();
                for (int j = 0; j < sList.Length; j++)
                {
                    Score s = sList[j];
                    s.updatetime = (i - 1).ToString();
                    sc.ScoreList.Attach(s);
                    sc.Entry(s).State = System.Data.EntityState.Modified;
                }
                sc.SaveChanges();
            }
            return(Content("ok"));
        }