Пример #1
0
        public IHttpActionResult Add_Lottezy(int lottezyId, [FromBody] ViewModelPrize viewModelPrize)
        {
            try
            {
                // MaiPH
                // check login
                String token = Request.Headers.Authorization.Scheme;
                tokenService.verifyToken(token);
                //
                using (var db = new XSKTDBDataContext())
                {
                    db.DeferredLoadingEnabled = false;
                    DateTime    date        = new DateTime(year: DateTime.Now.Year, month: DateTime.Now.Month, day: DateTime.Now.Day, hour: 0, minute: 00, second: 0);
                    PrizeDetail prizeDetail = db.PrizeDetails.Where(x => x.LoctionPrizeId == lottezyId).Where(x => x.DatePrize == date).FirstOrDefault();
                    if (prizeDetail == null)
                    {
                        Prize prize = new Prize
                        {
                            FirstPrize   = ConvertListToString(viewModelPrize.FirstPrize),
                            SecondPrize  = ConvertListToString(viewModelPrize.SecondPrize),
                            ThirdPrize   = ConvertListToString(viewModelPrize.ThirdPrize),
                            FourthPrize  = ConvertListToString(viewModelPrize.FourthPrize),
                            FifthPrize   = ConvertListToString(viewModelPrize.FifthPrize),
                            SixthPrize   = ConvertListToString(viewModelPrize.SixthPrize),
                            SeventhPrize = ConvertListToString(viewModelPrize.SeventhPrize),
                            SpecialPrize = ConvertListToString(viewModelPrize.SpecialPrize)
                        };
                        db.Prizes.InsertOnSubmit(prize);
                        db.SubmitChanges();
                        PrizeDetail detail = new PrizeDetail
                        {
                            LoctionPrizeId = lottezyId,
                            PrizeId        = prize.ID,
                            DatePrize      = date
                        };
                        db.PrizeDetails.InsertOnSubmit(detail);

                        db.SubmitChanges();
                        return(Ok(new Response
                        {
                            code = 0
                        }));
                    }
                }
            }
            catch
            {
                return(Ok(new Response
                {
                    code = 1
                }));
            }
            return(Ok(new Response
            {
                code = 1
            }));
        }
Пример #2
0
        public IHttpActionResult Update_Lottezy(int lottezyId, [FromBody] ViewModelPrize viewModelPrize)
        {
            try
            {
                // MaiPH
                // check login
                String token = Request.Headers.Authorization.Scheme;
                tokenService.verifyToken(token);


                using (var db = new XSKTDBDataContext())
                {
                    db.DeferredLoadingEnabled = false;
                    PrizeDetail prizeDetail = db.PrizeDetails.Where(x => x.LoctionPrizeId == lottezyId).Where(x => x.DatePrize == tachNgay(viewModelPrize.date)).FirstOrDefault();
                    if (prizeDetail != null)
                    {
                        Prize prize = db.Prizes.Single(x => x.ID == prizeDetail.PrizeId);
                        prize.FirstPrize   = ConvertListToString(viewModelPrize.FirstPrize);
                        prize.SecondPrize  = ConvertListToString(viewModelPrize.SecondPrize);
                        prize.ThirdPrize   = ConvertListToString(viewModelPrize.ThirdPrize);
                        prize.FourthPrize  = ConvertListToString(viewModelPrize.FourthPrize);
                        prize.FifthPrize   = ConvertListToString(viewModelPrize.FirstPrize);
                        prize.SixthPrize   = ConvertListToString(viewModelPrize.FirstPrize);
                        prize.SeventhPrize = ConvertListToString(viewModelPrize.FirstPrize);
                        prize.SpecialPrize = ConvertListToString(viewModelPrize.FirstPrize);
                        db.SubmitChanges();
                        return(Ok(new Response
                        {
                            code = 0
                        }));
                    }
                }
            }
            catch
            {
                return(Ok(new Response
                {
                    code = 1
                }));
            }
            return(Ok(new Response
            {
                code = 1
            }));
        }