Exemple #1
0
        public IActionResult ConsolePlay([FromBody] ConsolePlayDto consoleplay)
        {
            var consolePlayDtos = _mapper.Map <ConsolePlayDto>(consoleplay);

            var consolePlay = _consoleService.CreateConsolePlay(consolePlayDtos);

            return(Ok(new {
                Id = consolePlay.Id,
                ConsoleId = consolePlay.ConsoleId,
                UserId = consolePlay.UserId,
                Gamer = consolePlay.Gamer,
                Price = consolePlay.Price,
                isFixedTime = consolePlay.isFixedTime,
                FixedTime = consolePlay.FixedTime,
                PlayStart = consolePlay.PlayStart,
                PlayFinish = consolePlay.PlayFinish
            }));
        }
Exemple #2
0
        public ConsolePlay CreateConsolePlay(ConsolePlayDto consolePlayDto)
        {
            var consolePlay = _mapper.Map <ConsolePlay>(consolePlayDto);

            consolePlay.PlayStart  = System.DateTime.Now.ToString();
            consolePlay.PlayFinish = "Waiting";
            if (consolePlay.Gamer == 0)
            {
                consolePlay.Gamer = 2;
            }
            consolePlay.Price = (_context.Consoles.Find(consolePlay.ConsoleId).StandartPrice *consolePlay.Gamer) / 2;


            var GetPromotion = from PC in _context.PromotionConsoles
                               join P in _context.Promotions on PC.promotionId equals P.Id
                               join C in _context.Consoles on PC.consoleId equals C.Id
                               where PC.consoleId == consolePlayDto.ConsoleId
                               select new {
                PromotionId   = PC.promotionId,
                PromotionName = P.PromotionName,
                PromotionDesc = P.PromotionDesc,
                Price         = P.Price,
                AllTime       = P.AllTime,
                DateStart     = P.DateStart,
                DateEnd       = P.DateEnd,
                HourStart     = P.HourStart,
                HourEnd       = P.HourEnd,
                ConsoleId     = PC.consoleId,
                ConsoleName   = C.ConsoleName,
                ConsoleNumber = C.ConsoleNumber,
                Type          = C.Type,
                StandartPrice = C.StandartPrice,
                CurrentPrice  = C.CurrentPrice
            } into PCtable
            group PCtable by PCtable.PromotionId into g
                select new PromotionRelation {
                PromotionId   = g.FirstOrDefault().PromotionId,
                PromotionName = g.FirstOrDefault().PromotionName,
                PromotionDesc = g.FirstOrDefault().PromotionDesc,
                Price         = g.FirstOrDefault().Price,
                AllTime       = g.FirstOrDefault().AllTime,
                DateStart     = g.FirstOrDefault().DateStart,
                DateEnd       = g.FirstOrDefault().DateEnd,
                HourStart     = g.FirstOrDefault().HourStart,
                HourEnd       = g.FirstOrDefault().HourEnd,
                Console       = g.Select(x => new ConsoleProm {
                    ConsoleId     = x.ConsoleId,
                    ConsoleName   = x.ConsoleName,
                    ConsoleNumber = x.ConsoleNumber,
                    Type          = x.Type,
                    StandartPrice = x.StandartPrice,
                    CurrentPrice  = x.CurrentPrice,
                }).ToList()
            };


            var resultList = GetPromotion.ToList();

            if (resultList.Count > 0)
            {
                for (int i = 0; i < resultList.Count; i++)
                {
                    System.DateTime        DateTimeStart = new System.DateTime();
                    System.DateTime        DateTimeEnd   = new System.DateTime();
                    List <System.DateTime> DateTimeList  = new List <System.DateTime>();
                    if (resultList[i].AllTime == true)
                    {
                        if (System.DateTime.Parse(resultList[i].HourStart).TimeOfDay > System.DateTime.Parse(resultList[i].HourEnd).TimeOfDay)
                        {
                            DateTimeStart = System.DateTime.Now.Date + System.DateTime.Parse(resultList[i].HourStart).TimeOfDay;
                            DateTimeEnd   = System.DateTime.Now.Date + System.DateTime.Parse(resultList[i].HourEnd).TimeOfDay;
                            DateTimeList.Add(DateTimeStart);
                            DateTimeList.Add(System.DateTime.Parse("23:59:59"));
                            DateTimeList.Add(System.DateTime.Parse("00:00:00"));
                            DateTimeList.Add(DateTimeEnd);
                        }
                        else
                        {
                            DateTimeStart = System.DateTime.Now.Date + System.DateTime.Parse(resultList[i].HourStart).TimeOfDay;
                            DateTimeEnd   = System.DateTime.Now.Date + System.DateTime.Parse(resultList[i].HourEnd).TimeOfDay;
                        }
                    }
                    else
                    {
                        if (System.DateTime.ParseExact(resultList[i].DateStart, "d/M/yyyy", null).Date <= System.DateTime.Now
                            &&
                            System.DateTime.ParseExact(resultList[i].DateEnd, "d/M/yyyy", null).Date >= System.DateTime.Now
                            )
                        {
                            if (System.DateTime.Parse(resultList[i].HourStart).TimeOfDay > System.DateTime.Parse(resultList[i].HourEnd).TimeOfDay)
                            {
                                DateTimeStart = System.DateTime.Now.Date + System.DateTime.Parse(resultList[i].HourStart).TimeOfDay;
                                DateTimeEnd   = System.DateTime.Now.Date + System.DateTime.Parse(resultList[i].HourEnd).TimeOfDay;
                                DateTimeList.Add(DateTimeStart);
                                DateTimeList.Add(System.DateTime.Parse("23:59:59"));
                                DateTimeList.Add(System.DateTime.Parse("00:00:00"));
                                DateTimeList.Add(DateTimeEnd);
                            }
                            else
                            {
                                DateTimeStart = System.DateTime.Now.Date + System.DateTime.Parse(resultList[i].HourStart).TimeOfDay;
                                DateTimeEnd   = System.DateTime.Now.Date + System.DateTime.Parse(resultList[i].HourEnd).TimeOfDay;
                            }
                        }
                        //DateTimeStart =  System.DateTime.ParseExact(resultList[i].DateStart,"d/M/yyyy",  null).Date + System.DateTime.Parse(resultList[i].HourStart).TimeOfDay;
                        //DateTimeEnd =  System.DateTime.ParseExact(resultList[i].DateEnd,"d/M/yyyy",  null).Date + System.DateTime.Parse(resultList[i].HourEnd).TimeOfDay;
                    }
                    if (DateTimeList.Count > 0)
                    {
                        if (
                            DateTimeList[0] <= System.DateTime.Now
                            &&
                            DateTimeList[1] >= System.DateTime.Now
                            ||
                            DateTimeList[2] <= System.DateTime.Now
                            &&
                            DateTimeList[3] >= System.DateTime.Now
                            )
                        {
                            consolePlay.Price = (resultList[i].Price * consolePlay.Gamer) / 2;
                        }
                    }
                    else
                    {
                        if (
                            DateTimeStart <= System.DateTime.Now
                            &&
                            DateTimeEnd >= System.DateTime.Now
                            )
                        {
                            consolePlay.Price = (resultList[i].Price * consolePlay.Gamer) / 2;
                        }
                    }
                }
            }
            _context.Add(consolePlay);
            _context.SaveChanges();
            return(consolePlay);
        }