Exemple #1
0
        public async Task <ActionResult <GeoMessage> > PostGeoMessage(GeoMessage geoMessage)
        {
            var newGeoMessage = new GeoMessage
            {
                Message   = geoMessage.Message,
                Latitude  = geoMessage.Latitude,
                Longitude = geoMessage.Longitude
            };

            var geoMessageV2DTO = new Models.V1.GeoMessageV1_DTO
            {
                Message   = newGeoMessage.Message,
                Latitude  = newGeoMessage.Latitude,
                Longitude = newGeoMessage.Longitude
            };

            var newGeoMessageV2 = new GeoMessageV2
            {
                Latitude  = geoMessageV2DTO.Latitude,
                Longitude = geoMessageV2DTO.Longitude
            };


            await _context.AddAsync(newGeoMessage);

            await _context.AddAsync(newGeoMessageV2);

            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetGeoMessage", new { id = newGeoMessage.ID }, newGeoMessage));
        }
        public async Task <ActionResult <GeoMessageV2_DTO> > PostGeoMessage(GeoMessageV2_Input_DTO message)
        {
            var user = await _context.MyUsers.FindAsync(_userManager.GetUserId(User));

            var newMessage = new GeoMessageV2()
            {
                Title     = message.Title,
                Body      = message.Body,
                Author    = $"{user.FirstName} {user.LastName}",
                Longitude = message.Longitude,
                Latitude  = message.Latitude
            };
            await _context.AddAsync(newMessage);

            await _context.SaveChangesAsync();

            var messageDTO = new GeoMessageV2_DTO
            {
                Message = new Messages
                {
                    Body   = newMessage.Body,
                    Title  = newMessage.Title,
                    Author = newMessage.Author
                },
                Longitude = newMessage.Longitude,
                Latitude  = newMessage.Latitude
            };

            return(CreatedAtAction(nameof(GetGeoMessage), new { id = newMessage.Id }, messageDTO));
        }
            public async Task <ActionResult <GeoMessageV2> > PostGeoMessages(V1GetDTO geoMessages)
            {
                var V2Model = new GeoMessageV2
                {
                    Message = new Message
                    {
                        Body = geoMessages.Message
                    },
                    Longitude = geoMessages.Longitude,
                    Latitude  = geoMessages.Latitude
                };

                _context.GeoMessageV2.Add(V2Model);
                await _context.SaveChangesAsync();

                return(CreatedAtAction("GetGeoMessages", new { id = V2Model.ID }, V2Model));
            }
Exemple #4
0
        public async Task <ActionResult <GeoMessageV2DTO> > PostGeoMessage(V2InputDTO geoMessage)
        {
            var user = await _context.User.FindAsync(_userManager.GetUserId(User));

            var msg = new GeoMessageV2()
            {
                Title     = geoMessage.Title,
                Body      = geoMessage.Body,
                Author    = $"{user.FirstName} {user.LastName}",
                Longitude = geoMessage.Longitude,
                Latitude  = geoMessage.Latitude
            };
            await _context.AddAsync(msg);

            await _context.SaveChangesAsync();

            var messageDTO = new GeoMessageV2DTO
            {
                Message = new Message
                {
                    Title  = msg.Title,
                    Body   = msg.Body,
                    Author = msg.Author
                },
                Longitude = msg.Longitude,
                Latitude  = msg.Latitude
            };


            return(CreatedAtAction("GetGeoMessage", new { id = msg.Id }, messageDTO));

            /*_context.GeoMessages.Add(geoMessage);
             * await _context.SaveChangesAsync();
             *
             * return CreatedAtAction("GetGeoMessage", new { id = geoMessage.Id }, geoMessage);*/
        }
Exemple #5
0
 private bool IsInRange(GeoMessageV2 gm, int minLon, int maxLon, int minLat, int maxLat)
 {
     return(gm.Longitude > minLon && gm.Longitude < maxLon &&
            gm.Latitude > minLat && gm.Latitude < maxLat);
 }