Beispiel #1
0
 protected void PopulateEventModel(Models.EventModel model, DataAccess.Event data)
 {
     model.Id               = data.EventId;
     model.Name             = data.Name;
     model.Character_Cd     = data.Character_Cd;
     model.EndTime          = data.EndTime;
     model.TimeToEnd        = data.EndTime - DateTime.Now;
     model.TimeToEndHours   = model.TimeToEnd.HasValue ? (model.TimeToEnd.Value.Hours + model.TimeToEnd.Value.Days * 24) : 0;
     model.TimeToEndMinutes = model.TimeToEnd.HasValue ? (model.TimeToEnd.Value.Minutes) : 0;
     model.RewardType_Cd    = data.RewardType_Cd;
 }
Beispiel #2
0
        public ActionResult Edit(Models.EventModel model)
        {
            if (ModelState.IsValid)
            {
                using (var daEvent = new DataAccess.DataAccessObjects.Events())
                {
                    DataAccess.Event oEvent;
                    if (model.Id.HasValue)
                    {
                        oEvent = daEvent.LoadEvent(model.Id.Value);
                    }
                    else
                    {
                        oEvent = new DataAccess.Event();
                    }

                    oEvent.Name          = model.Name;
                    oEvent.Character_Cd  = model.Character_Cd;
                    oEvent.RewardType_Cd = model.RewardType_Cd;

                    DateTime?EndTime = null;

                    if (model.TimeToEndHours > 0 || model.TimeToEndMinutes > 0)
                    {
                        EndTime = DateTime.Now;

                        EndTime = EndTime.Value.AddHours(model.TimeToEndHours);
                        EndTime = EndTime.Value.AddMinutes(model.TimeToEndMinutes);
                    }

                    oEvent.EndTime = EndTime;

                    daEvent.SaveEvent(oEvent, Request.UserHostAddress);

                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                PopulateLists(model);
                return(View(model));
            }
        }
Beispiel #3
0
        private Models.API.EventDTO SetDTO(DataAccess.Event oEvent)
        {
            return(new Models.API.EventDTO()
            {
                EventId = oEvent.EventId,
                Name = oEvent.Name,
                EndTime = oEvent.EndTime.GetValueOrDefault(),

                Character_CD = !oEvent.Character_Cd.HasValue ? null :
                               new Models.API.CodeValueDTO()
                {
                    CodeValue = oEvent.Character_Cd.Value,
                    Description = oEvent.Character.Description,
                    CodeTableId = oEvent.Character.CodeTableId
                },
                RewardType_CD = new Models.API.CodeValueDTO()
                {
                    CodeValue = oEvent.RewardType_Cd,
                    Description = oEvent.RewardType.Description,
                    CodeTableId = oEvent.RewardType.CodeTableId
                }
            });
        }
Beispiel #4
0
        public IActionResult Post([FromBody] IEnumerable <Event> events)
        {
            using (var context = new DataAccess.bkContext())
            {
                var currentEvents = context.Events.ToList();

                IList <DataAccess.Event> eventRange = new List <DataAccess.Event>();

                foreach (Event _event in events)
                {
                    var curr = currentEvents.SingleOrDefault(c => c.EventId == _event.id);

                    if (curr != null)
                    {
                        //update current
                        curr.jsonData = JsonConvert.SerializeObject(_event);
                    }
                    else
                    {
                        //create new
                        DataAccess.Event dbEvent = new DataAccess.Event();
                        dbEvent.EventId    = _event.id;
                        dbEvent.jsonData   = JsonConvert.SerializeObject(_event);
                        dbEvent.HasMessage = false;
                        eventRange.Add(dbEvent);
                    }
                }

                context.Events.AddRange(eventRange);

                var ids           = events.Select(e => e.id);
                var eventToDelete = currentEvents.Select(c => c.EventId).Except(ids);

                //delete old
                if (eventToDelete.Count() > 0)
                {
                    context.Events.RemoveRange(currentEvents.Where(c => eventToDelete.Contains(c.EventId)));
                }

                context.SaveChanges();
            }

            using (var context = new DataAccess.bkContext())
            {
                //make messages
                var eventsToAnalys = context.Events.Where(e => e.HasMessage == false).ToList();

                DrawFootballStrategy drawFootball = new DrawFootballStrategy();
                DrawHockeyStrategy   drawHockey   = new DrawHockeyStrategy();

                IList <DataAccess.Event> toSend = new List <DataAccess.Event>();

                foreach (var ev in eventsToAnalys)
                {
                    var obj = JsonConvert.DeserializeObject <Event>(ev.jsonData);

                    //football
                    if (obj.gameId == 33 && drawFootball.Check(obj))
                    {
                        toSend.Add(ev);
                    }

                    //hockey
                    if (obj.gameId == 31 && drawHockey.Check(obj))
                    {
                        toSend.Add(ev);
                    }
                }

                if (toSend.Count > 0)
                {
                    System.Text.StringBuilder sb = new System.Text.StringBuilder();
                    foreach (var ev in toSend)
                    {
                        var obj = JsonConvert.DeserializeObject <Event>(ev.jsonData);

                        if (obj.gameId == 31)
                        {
                            sb.AppendLine("Hockey");
                        }

                        if (obj.gameId == 33)
                        {
                            sb.AppendLine("Football");
                        }
                        sb.AppendLine(obj.eventTitle);
                        sb.AppendLine("Bet to Draw");
                        sb.AppendLine();

                        ev.HasMessage = true;
                    }

                    context.Messages.Add(new DataAccess.Message()
                    {
                        MessageBody = sb.ToString(),
                        Sent        = false
                    });

                    context.SaveChanges();
                }
            }

            return(Ok(1));
        }