Example #1
0
        public void StartCollaborativeSearch(Event eventt)
        {
            var now       = SystemDateTime.Now;
            var searchers = AreYouOkEvents.Where(x => x.Event == eventt && x.ReplyDatetime != null).ToList();

            foreach (var areYouOkEvent in searchers)
            {
                var list = areYouOkEvent.Target.Devices.Select(x => new BodySend()
                {
                    Token = x.Token,
                    Body  = $"Se declaro una emergencia en el evento {eventt.Name}",
                    Title = "Encuentrame",
                    Data  = new
                    {
                        Created           = now,
                        EventId           = eventt.Id,
                        EmergencyDateTime = eventt.EmergencyDateTime.Value,
                        Type = "Event.StartCollaborativeSearch",
                    }
                }).ToList();



                ExpoPushHelper.SendPushNotification(list);
            }
        }
Example #2
0
        public void CancelAskFromEvent(Event eventt)
        {
            var areYouOks = AreYouOkEvents.Where(x => x.Event == eventt);

            foreach (var areYouOk in areYouOks)
            {
                AreYouOkEvents.Remove(areYouOk);
            }
        }
Example #3
0
        public ActionResult PersonMonitor(int eventId, int userId)
        {
            var eventt = EventCommand.Get(eventId);
            var user   = UserCommand.Get(userId);

            var seenInfo = AreYouOkCommand.GetSeenInfo(eventId, userId);

            if (seenInfo == null)
            {
                seenInfo = new SeenInfo();
            }

            if (LoggedUserIs(RoleEnum.EventAdministrator) && eventt.Organizer.Id != GetLoggedUser().Id)
            {
                return(RedirectToAction("Monitor", "EventMonitor", new { id = eventId }));
            }

            var status = IAmOkEnum.WithoutAnswer;

            var statusRow = AreYouOkEvents.Where(x => x.Target == user && x.Event == eventt).FirstOrDefault();

            if (statusRow?.ReplyDatetime != null)
            {
                status = statusRow.IAmOk ? IAmOkEnum.Ok : IAmOkEnum.NotOk;
            }

            var eventPersonMonitorModel = new EventPersonMonitorModel()
            {
                Username          = user.Username,
                Image             = user.Image,
                EventId           = eventId,
                UserId            = userId,
                EventLatitude     = eventt.Latitude,
                EventLongitude    = eventt.Longitude,
                EventName         = eventt.Name,
                Status            = status,
                Seen              = seenInfo.Seen,
                SeenOk            = seenInfo.SeenOk,
                SeenNotOk         = seenInfo.SeenNotOk,
                SeenWithoutAnswer = seenInfo.SeenWithoutAnswer
            };

            return(View(eventPersonMonitorModel));
        }
Example #4
0
        public void AskFromEvent(Event eventt)
        {
            var now = SystemDateTime.Now;

            var activities = Activities.Where(x => x.Event == eventt);

            foreach (var activity in activities)
            {
                var areYouOk = new AreYouOkEvent();
                areYouOk.Event  = eventt;
                areYouOk.Target = activity.User;
                areYouOk.IAmOk  = false;

                AreYouOkEvents.Put(areYouOk);
            }


            CurrentUnitOfWork.Checkpoint();

            var listAsks = AreYouOkEvents.Where(x => x.Event == eventt);

            foreach (var areYouOkEvent in listAsks)
            {
                var list = areYouOkEvent.Target.Devices.Select(x => new BodySend()
                {
                    Token = x.Token,
                    Body  = "¿estas bien?",
                    Title = "Encuentrame",
                    Data  = new
                    {
                        Created      = now,
                        Id           = areYouOkEvent.Id,
                        SenderUserId = areYouOkEvent.Target.Id,
                        AskDatetime  = areYouOkEvent.Created,
                        Type         = "Areyouok.Ask",
                    }
                }).ToList();

                ExpoPushHelper.SendPushNotification(list);
            }
        }
Example #5
0
        public void Reply(ReplyParameters parameters)
        {
            var now       = SystemDateTime.Now;
            var replyUser = Users[parameters.UserId];

            var areYouOkActivities = AreYouOkActivities.Where(x => x.ReplyDatetime == null && x.Target == replyUser);

            foreach (var areYouOkActivity in areYouOkActivities)
            {
                areYouOkActivity.IAmOk         = parameters.IAmOk;
                areYouOkActivity.ReplyDatetime = SystemDateTime.Now;

                var list = areYouOkActivity.Sender.Devices.Select(x => new BodySend()
                {
                    Token = x.Token,
                    Body  = parameters.IAmOk ? $"{replyUser.FullName} ha indicado que está bien!" : $"{replyUser.FullName} esta con algun problema",
                    Title = "Encuentrame",
                    Data  = new
                    {
                        Created       = now,
                        Id            = areYouOkActivity.Id,
                        TargetUserId  = areYouOkActivity.Target.Id,
                        Ok            = parameters.IAmOk,
                        ReplyDatetime = areYouOkActivity.ReplyDatetime,
                        Type          = "Areyouok.Reply",
                    }
                }).ToList();

                ExpoPushHelper.SendPushNotification(list);
            }

            var areYouOkEvents = AreYouOkEvents.Where(x => x.ReplyDatetime == null && x.Target == replyUser);

            foreach (var areYouOkEvent in areYouOkEvents)
            {
                areYouOkEvent.IAmOk         = parameters.IAmOk;
                areYouOkEvent.ReplyDatetime = SystemDateTime.Now;
            }
        }
Example #6
0
        // GET: Database
        public ActionResult CreateDataMock(string password)
        {
            if (password != "destruir")
            {
                AddModelError("Contraseña incorrecta");
                return(View("Index"));
            }

            //Users
            var userAdmin = new User()
            {
                Username  = "******",
                Password  = "******",
                Firstname = "Admin",
                Lastname  = "Admin",
                Email     = "*****@*****.**",
                Role      = RoleEnum.Administrator,
            };

            Users.Put(userAdmin);



            var business1 = new Business()
            {
                Name    = "Pepsi Music",
                Cuit    = "20287495782",
                Created = SystemDateTime.Now,
                Address = new Address()
                {
                    City = "CABA",
                    FloorAndDepartament = "1 'C'",
                    Number   = "243",
                    Province = "CABA",
                    Street   = "Aguirre",
                    Zip      = "1414",
                }
            };

            Businesses.Put(business1);

            var user3 = new User()
            {
                Username  = "******",
                Password  = "******",
                Firstname = "juan",
                Lastname  = "organizador",
                Email     = "*****@*****.**",
                Role      = RoleEnum.EventAdministrator,
                Business  = business1,
            };

            Users.Put(user3);

            var user4 = new User()
            {
                Username  = "******",
                Password  = "******",
                Firstname = "fernando",
                Lastname  = "organizador",
                Email     = "*****@*****.**",
                Role      = RoleEnum.EventAdministrator,
                Business  = business1,
            };

            Users.Put(user4);


            var eventt1 = new Event()
            {
                Name          = "Obelisco",
                BeginDateTime = SystemDateTime.Now.AddHours(-3),
                EndDateTime   = SystemDateTime.Now.AddHours(3),
                Organizer     = user3,
                Status        = EventStatusEnum.InProgress,
                Address       = new Address()
                {
                    City = "CABA",
                    FloorAndDepartament = "",
                    Number   = "0",
                    Province = "CABA",
                    Street   = "Obelisco",
                    Zip      = "1414",
                },
                Latitude  = (decimal) - 34.60373,
                Longitude = (decimal) - 58.38157,
            };

            Events.Put(eventt1);

            var eventt2 = new Event()
            {
                Name          = "UTN",
                BeginDateTime = SystemDateTime.Now.AddHours(1),
                EndDateTime   = SystemDateTime.Now.AddHours(3),
                Organizer     = user4,
                Status        = EventStatusEnum.Pending,
                Address       = new Address()
                {
                    City = "CABA",
                    FloorAndDepartament = "",
                    Number   = "953",
                    Province = "CABA",
                    Street   = "Medrano",
                    Zip      = "1414",
                },
                Latitude  = (decimal) - 34.59858,
                Longitude = (decimal) - 58.41989,
            };

            Events.Put(eventt2);

            var dayRandom = new Random(SystemDateTime.Now.Millisecond);

            for (int ss = 0; ss < 50; ss++)
            {
                var bgdt = SystemDateTime.Now.AddDays(-1 * dayRandom.Next(0, 360));
                var ev   = new Event()
                {
                    Name          = $"Evento de prueba {ss}",
                    BeginDateTime = bgdt,
                    EndDateTime   = bgdt.AddHours(3),
                    Organizer     = user4,
                    Status        = bgdt < SystemDateTime.Now ? EventStatusEnum.Completed : EventStatusEnum.InProgress,
                    Address       = new Address()
                    {
                        City = "CABA",
                        FloorAndDepartament = "",
                        Number   = "953",
                        Province = "CABA",
                        Street   = "Medrano",
                        Zip      = "1414",
                    },
                    Latitude  = (decimal) - 34.59858,
                    Longitude = (decimal) - 58.41989,
                };

                if (dayRandom.Next(0, 360) < 36)
                {
                    ev.EmergencyDateTime = bgdt.AddHours(1);
                    if (ev.Status == EventStatusEnum.InProgress)
                    {
                        ev.Status = EventStatusEnum.InEmergency;
                    }
                }

                Events.Put(ev);
            }


            CreateUsers();


            CurrentUnitOfWork.Checkpoint();

            var listOfUsers = Users.Where(x => x.Role == RoleEnum.User).ToList();

            foreach (var user in listOfUsers)
            {
                var activityIn = new Activity()
                {
                    BeginDateTime = SystemDateTime.Now.AddDays(-1),
                    EndDateTime   = SystemDateTime.Now,
                    Event         = eventt1,
                    Latitude      = eventt1.Latitude,
                    Longitude     = eventt1.Longitude,
                    Name          = "actividad 1",
                    User          = user
                };
                Activities.Put(activityIn);
            }

            foreach (var user in listOfUsers)
            {
                var activityIn = new Activity()
                {
                    BeginDateTime = SystemDateTime.Now.AddDays(3),
                    EndDateTime   = SystemDateTime.Now.AddDays(4),
                    Event         = eventt2,
                    Latitude      = eventt2.Latitude,
                    Longitude     = eventt2.Longitude,
                    Name          = "actividad 2",
                    User          = user
                };
                Activities.Put(activityIn);
            }

            var dictionary = new Dictionary <int, dynamic>();

            foreach (var user in listOfUsers)
            {
                var position = new Position()
                {
                    Latitude  = eventt1.Latitude,
                    Longitude = eventt1.Longitude,
                    Creation  = eventt1.BeginDateTime,
                    UserId    = user.Id,
                };

                Positions.Put(position);
                dictionary[user.Id] = new { Latitude = eventt1.Latitude, Longitude = eventt1.Longitude };
            }

            var rnd = new Random(DateTime.Now.Millisecond);

            for (int ii = 0; ii < 180; ii = ii + 3)
            {
                foreach (var user in listOfUsers)
                {
                    var position = new Position()
                    {
                        Latitude  = dictionary[user.Id].Latitude + (decimal)rnd.Next(-3, 3) / 10000,
                        Longitude = dictionary[user.Id].Longitude + (decimal)rnd.Next(-3, 3) / 10000,
                        Creation  = eventt1.BeginDateTime.AddMinutes(ii),
                        UserId    = user.Id,
                    };

                    Positions.Put(position);

                    dictionary[user.Id] = new { Latitude = position.Latitude, Longitude = position.Longitude };
                }
            }


            CurrentUnitOfWork.Checkpoint();


            EventCommand.DeclareEmergency(eventt1.Id);


            CurrentUnitOfWork.Checkpoint();

            EventCommand.StartCollaborativeSearch(eventt1.Id);

            CurrentUnitOfWork.Checkpoint();

            foreach (var user in listOfUsers)
            {
                var nmb = rnd.Next(0, 10);
                if (nmb.NotIn(new[] { 0, 5, 8 }))
                {
                    if (nmb % 2 == 0)
                    {
                        AreYouOkCommand.Reply(new AreYouOkCommand.ReplyParameters()
                        {
                            UserId = user.Id,
                            IAmOk  = true,
                        });
                    }
                    else if (nmb % 2 != 0)
                    {
                        AreYouOkCommand.Reply(new AreYouOkCommand.ReplyParameters()
                        {
                            UserId = user.Id,
                            IAmOk  = false,
                        });
                    }
                }
            }
            CurrentUnitOfWork.Checkpoint();

            var soughtPeople = AreYouOkEvents.Where(x => x.Event == eventt1 && x.ReplyDatetime == null).ToList();
            var index        = soughtPeople.Count;

            foreach (var areYouOkEvent in AreYouOkEvents.Where(x => x.Event == eventt1 && x.IAmOk && x.ReplyDatetime != null))
            {
                var nmb = rnd.Next(0, 10);
                if (nmb.NotIn(new[] { 0, 5, 8 }))
                {
                    if (nmb % 2 == 0)
                    {
                        var soughtPersonAswer = new SoughtPersonAnswer()
                        {
                            When       = SystemDateTime.Now,
                            Seen       = true,
                            IsOk       = nmb.NotIn(new[] { 2 }),
                            SourceUser = areYouOkEvent.Target,
                            TargetUser = soughtPeople[rnd.Next(1, index) - 1].Target,
                        };

                        SoughtPersonAnswers.Put(soughtPersonAswer);
                    }
                    else if (nmb % 2 != 0)
                    {
                        var soughtPersonAswer = new SoughtPersonAnswer()
                        {
                            When       = SystemDateTime.Now,
                            Seen       = false,
                            SourceUser = areYouOkEvent.Target,
                            TargetUser = soughtPeople[rnd.Next(1, index) - 1].Target,
                        };

                        SoughtPersonAnswers.Put(soughtPersonAswer);
                    }
                }
            }



            return(View("IndexMessage", null, "Los datos de prueba se creo con exito"));
        }