Ejemplo n.º 1
0
        public async Task <Element> CreateElementAsync(Zone zone, Element element)
        {
            if (context.Zones.Any(z => z.ZoneID == zone.ZoneID))
            {
                try
                {
                    element.ZoneID    = zone.ZoneID;
                    element.ElementId = Guid.NewGuid();
                    if (element.ElementType != null)
                    {
                        switch (element.ElementType)
                        {
                        case Element.ElementTypes.POINT:
                            context.Points.Add((Point)element);
                            await context.SaveChangesAsync();

                            return(element);

                        case Element.ElementTypes.POLYGON:
                            context.Polygons.Add((Polygon)element);
                            await context.SaveChangesAsync();

                            return(element);
                        }
                    }
                    throw new ArgumentException("Invalid element provided");
                }
                catch (Exception e)
                {
                    throw new ArgumentException("Invalid element provided", e.Message);
                }
            }
            throw new ArgumentException("Invalid zone provided");
        }
        public async Task <Zone> CreateZoneAsync(Zone zone, User user)
        {
            if (user.UserID == null || !context.Users.Any(usr => usr.UserID == user.UserID))
            {
                throw new ArgumentException("Invalid user provided");
            }
            try
            {
                zone.UserId       = user.UserID;
                zone.ParentZoneID = null;
                zone.ZoneID       = Guid.NewGuid();
                context.Zones.Add(zone);
                await context.SaveChangesAsync();

                return(zone);
            }
            catch (Exception)
            {
                throw new ArgumentException("Invalid Zone provided");
            }
        }
Ejemplo n.º 3
0
        public async Task <User> CreateUserAsync(User user)
        {
            if (!_ZoneDB.Users.Any(u => u.Email == user.Email))
            {
                user.UserID = Guid.NewGuid();
                _ZoneDB.Add(user);
                await _ZoneDB.SaveChangesAsync();

                user.Password = null;
                user.Email    = null;
                return(user);
            }
            else
            {
                throw new ArgumentException("User Email should be unique");
            }
        }
Ejemplo n.º 4
0
        public async Task <ReturnMessage> interpretInput(string query)
        {
            try
            {
                var      inputData = JsonConvert.DeserializeObject <LiveLocationMessage>(query);
                LiveUser liveUser  = null;

                if ((liveUser = ZoneDB.LiveUser
                                .Where(c => c.UserID == inputData.UserID).SingleOrDefault()) == null)
                {
                    liveUser = new LiveUser()
                    {
                        UserID = Guid.NewGuid()
                    };
                    ZoneDB.LiveUser.Add(liveUser);
                }
                if (inputData.Location != null)
                {
                    ZoneDB.LiveLocation.Add(new LiveLocation
                    {
                        UserID  = liveUser.UserID,
                        GeoJson = inputData.Location
                    });
                }
                await ZoneDB.SaveChangesAsync();

                return(new ReturnMessage()
                {
                    Weather = "In development",
                    UserID = liveUser.UserID
                });
            }
            catch (Exception e)
            {
                throw new ArgumentException("Invalid user id or location");
            }
        }