Exemplo n.º 1
0
        public void Create(Puzzle model)
        {
            if (model == null)
            {
                return;
            }

            db.Puzzles.Add(model);
            db.SaveChanges();
        }
Exemplo n.º 2
0
        public IHttpActionResult Post(DTOProduct dtoProduct)
        {
            // Create a new Product
            var NewProduct = new Product();

            NewProduct.Name  = dtoProduct.ProductName;
            NewProduct.Price = Convert.ToDecimal(dtoProduct.ProductPrice);
            // Save the Product
            db.Products.Add(NewProduct);
            db.SaveChanges();
            // Populate the ID that was created and pass it back
            dtoProduct.Id = NewProduct.Id;
            // Return the Product
            return(Created(dtoProduct));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 若已有使用者直接回傳,沒有則新增後回傳
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public User CheckOrCreate(User model)
        {
            var data = db.Users.Include(x => x.Team).FirstOrDefault(x => x.ProfileId == model.ProfileId);

            if (data == null)
            {
                data            = model;
                data.Id         = Ci.Sequential.Guid.Create();
                data.CreateTime = DateTime.Now;
                data.ModifyTime = DateTime.Now;
                data.Picture    = $"https://graph.facebook.com/{model.ProfileId}/picture?type=large";
                db.Users.Add(data);
            }

            db.SaveChanges();

            return(data);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 設定開始 Tour 計時
        /// </summary>
        /// <param name="teamId"></param>
        public Guid SetTeamStart(Guid teamId)
        {
            var team        = GetByIdIncludeAll(teamId);
            var tourPuzzles = team.Tour.TourPuzzles;
            var records     = team.TeamRecords;

            if (team.CurrentPuzzleId.HasValue && records.Any())
            {
                return(team.CurrentPuzzleId.Value);
            }

            if (!team.CurrentPuzzleId.HasValue)
            {
                var firstTourPuzzle = tourPuzzles.OrderBy(x => x.Sort).First();
                var record          = new TeamRecord();
                record.Id              = Ci.Sequential.Guid.Create();
                record.TeamId          = team.Id;
                record.CreateTime      = DateTime.Now;
                record.ModifyTime      = DateTime.Now;
                record.PuzzleStartTime = DateTime.Now;
                record.TourPuzzleId    = firstTourPuzzle.Id;
                record.Sort            = firstTourPuzzle.Sort;
                team.TeamRecords.Add(record);

                team.CurrentPuzzleId       = tourPuzzles.First(x => x.Sort == 1).PuzzleId;
                team.CurrentTourPuzzleId   = firstTourPuzzle.Id;
                team.CurrentTourPuzzleSort = firstTourPuzzle.Sort;
            }
            else
            {
                team.CurrentPuzzleId = team.TeamRecords.OrderByDescending(x => x.Sort).First().TourPuzzle.PuzzleId;
            }

            db.SaveChanges();

            return(team.CurrentPuzzleId.Value);
        }