Example #1
0
        public IList <PositionWhereWasSeenInfo> PositionsWhereWasSeen(int eventId, int userId)
        {
            var eventt = Events[eventId];
            var user   = Users[userId];

            DateTime to = SystemDateTime.Now;

            if (eventt.Status == EventStatusEnum.InProgress || eventt.Status == EventStatusEnum.InEmergency)
            {
                to = SystemDateTime.Now;
            }
            else if (eventt.Status == EventStatusEnum.Completed)
            {
                to = eventt.EndDateTime;
            }
            else
            {
                return(new List <PositionWhereWasSeenInfo>());
            }

            return(SoughtPersonAnswers.Where(x => x.TargetUser == user && x.Seen == true && x.When >= eventt.BeginDateTime && x.When <= to)
                   .OrderBy(x => x.When)
                   .Select(x => new PositionWhereWasSeenInfo()
            {
                Id = x.Id,
                Longitude = x.Longitude,
                Latitude = x.Latitude,
                When = x.When,
                Status = x.IsOk.HasValue ? (x.IsOk.Value ? 20 : 10) : 0
            }).ToList());
        }
Example #2
0
        public void SoughtPersonDismiss(SoughtPersonDismissParameters parameters)
        {
            var soughtPersonAswer = new SoughtPersonAnswer()
            {
                When       = parameters.When,
                Seen       = false,
                SourceUser = Users[parameters.SourceUserId],
                TargetUser = Users[parameters.TargetUserId],
            };

            SoughtPersonAnswers.Put(soughtPersonAswer);
        }
Example #3
0
        public void SoughtPersonSeen(SoughtPersonSeenParameters parameters)
        {
            decimal?latitude   = null;
            decimal?longitude  = null;
            var     sourceUser = Users[parameters.SourceUserId];
            var     targetUser = Users[parameters.TargetUserId];

            if (parameters.When.HasValue)
            {
                Positions.Where(c => c.UserId == parameters.TargetUserId && c.Creation <= parameters.When)
                .OrderByDescending(x => x.Creation).Take(1).ForEach(i =>
                {
                    latitude  = i.Latitude;
                    longitude = i.Longitude;
                });
            }
            else
            {
                parameters.When = SystemDateTime.Now;
                Positions.Where(c => c.UserId == parameters.SourceUserId && c.Creation <= parameters.When)
                .OrderByDescending(x => x.Creation).Take(1).ForEach(i =>
                {
                    latitude  = i.Latitude;
                    longitude = i.Longitude;
                });
            }

            var soughtPersonAswer = new SoughtPersonAnswer()
            {
                When       = parameters.When.HasValue?parameters.When.Value.ToTimeZoneTime():default(DateTime?),
                Seen       = true,
                Latitude   = latitude,
                Longitude  = longitude,
                IsOk       = parameters.IsOk,
                SourceUser = sourceUser,
                TargetUser = targetUser,
            };

            SoughtPersonAnswers.Put(soughtPersonAswer);
        }
Example #4
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"));
        }