Пример #1
0
        public int NewMessage(Message message)
        {
            var accident = new Accident();

            try
            {
                var db = new ecologyWatchEntities();

                accident.Accident_Description = message.Description;
                accident.Status_Id            = 1;
                accident.Date         = DateTime.Now;
                accident.Place_Lat    = message.Latitude;
                accident.Place_Long   = message.Longitude;
                accident.Place_Adress = message.PlaceName;
                accident.Situation_Id = message.SituationId;

                db.Accident.Add(accident);
                db.SaveChanges();
            }
            catch
            {
                return(-1);
            }

            if (accident.Accident_Id > 0)
            {
                return(accident.Accident_Id);
            }

            return(-1);
        }
Пример #2
0
        public int CreateNewnUser(User_Data user_data)
        {
            var temp = new User_Data();

            try
            {
                var db = new ecologyWatchEntities();

                var list = db.User_Data.Where(u => (u.Login == user_data.Login));
                if (list == null)
                {
                    temp.Login         = user_data.Login;
                    temp.Password_Hash = user_data.Password_Hash;
                    temp.Email         = user_data.Email;
                    temp.Is_Active     = true;
                    temp.Joined_On     = DateTime.Now;

                    db.User_Data.Add(temp);
                    db.SaveChanges();
                }
            }
            catch
            {
                return(-1);
            }

            if (temp.User_Id > 0)
            {
                return(temp.User_Id);
            }

            return(-1);
        }
Пример #3
0
        public List <Message> SearchGeo(string text, double position_lat, double position_long, double radius)
        {
            List <Message> list = new List <Message>();
            var            minX = position_lat - radius / 111.3;
            var            maxX = position_lat + radius / 111.3;
            var            minY = position_long - radius / (111.3 * Math.Cos(position_lat));
            var            maxY = position_long + radius / (111.3 * Math.Cos(position_lat));

            try
            {
                var             db   = new ecologyWatchEntities();
                List <Accident> temp = db.Accident.Where(a => (a.Place_Lat >= minX) && (a.Place_Lat <= maxX) && (a.Place_Long >= minY) && (a.Place_Long <= maxY)).ToList();
                for (int i = 0; i < temp.Count; i++)
                {
                    list[i].Description = temp[i].Accident_Description;
                    list[i].SituationId = Convert.ToInt32(temp[i].Situation_Id);
                    list[i].Latitude    = Convert.ToDouble(temp[i].Place_Lat);
                    list[i].Longitude   = Convert.ToDouble(temp[i].Place_Long);
                    list[i].PlaceName   = temp[i].Place_Adress;
                }
            }
            catch { }

            return(list);
        }
Пример #4
0
        public List <Message> Search(string text, DateTime date_from, int start_from)
        {
            List <Message> list = new List <Message>();

            try
            {
                var             db   = new ecologyWatchEntities();
                List <Accident> temp = db.Accident.Where(a => ((a.Date >= date_from) && (a.Accident_Id >= start_from))).ToList();

                for (int i = 0; i < temp.Count; i++)
                {
                    list[i].Description = temp[i].Accident_Description;
                    list[i].SituationId = Convert.ToInt32(temp[i].Situation_Id);
                    list[i].Latitude    = Convert.ToDouble(temp[i].Place_Lat);
                    list[i].Longitude   = Convert.ToDouble(temp[i].Place_Long);
                    list[i].PlaceName   = temp[i].Place_Adress;
                }
            }
            catch
            {
            }
            return(list);
        }
Пример #5
0
        public List <Message> Search10(string text)
        {
            List <Message> list = new List <Message>();

            try
            {
                var             db   = new ecologyWatchEntities();
                List <Accident> temp = db.Accident.OrderByDescending(a => a.Date).Take(10).ToList();

                for (int i = 0; i < temp.Count; i++)
                {
                    list[i].Description = temp[i].Accident_Description;
                    list[i].SituationId = Convert.ToInt32(temp[i].Situation_Id);
                    list[i].Latitude    = Convert.ToDouble(temp[i].Place_Lat);
                    list[i].Longitude   = Convert.ToDouble(temp[i].Place_Long);
                    list[i].PlaceName   = temp[i].Place_Adress;
                }
            }
            catch
            {
            }
            return(list);
        }
Пример #6
0
        public int LoginUser(User_Data user_data)
        {
            var temp = new User_Data();

            try
            {
                var db = new ecologyWatchEntities();

                temp = db.User_Data.Where(u => ((u.Login == user_data.Login) && (u.Password_Hash == user_data.Password_Hash)));

                if (temp != null)
                {
                    return(1);
                }
                else
                {
                    return(-1);
                }
            }
            catch
            {
                return(-2);
            }
        }