コード例 #1
0
            public async Task <ActionResult <GeoMessagesV2> > PostGeoMessages(v2PostDTO geoMessagesDTO)
            {
                //Försök hämta hem User via api nycklen
                //Här hittar hämtar vi inskriven api nyckel
                string token = Request.Headers[ApiKeyConstants.HttpHeaderField];

                if (token == null)
                {
                    token = Request.Query[ApiKeyConstants.HttpQueryParamKey];
                }
                //Matcha api nyckel med en userID
                var userApiDB = await _context.ApiTokens.FirstOrDefaultAsync(o => o.Value == token);

                var userID = userApiDB.User;

                GeoMessagesV2 geoMessagesV2 = new GeoMessagesV2()
                {
                    Message = new Message()
                    {
                        Author = userApiDB.User.FirstName + " " + userApiDB.User.LastName
                        ,
                        Body  = geoMessagesDTO.Message.Body,
                        Title = geoMessagesDTO.Message.Title
                    },
                    latitude  = geoMessagesDTO.latitude,
                    longitude = geoMessagesDTO.longitude
                };

                _context.geoMessagesV2.Add(geoMessagesV2);
                await _context.SaveChangesAsync();

                return(CreatedAtAction("GetGeoMessages", new { id = geoMessagesV2.Id }, geoMessagesV2));
            }
コード例 #2
0
            public async Task <ActionResult <GeoMessagesV2> > PostGeoMessages(v1GetDTO geoMessages)
            {
                var v2modell = new GeoMessagesV2 {
                    Message = new Message {
                        Body = geoMessages.Message
                    },
                    longitude = geoMessages.longitude,
                    latitude  = geoMessages.latitude
                };

                _context.geoMessagesV2.Add(v2modell);
                await _context.SaveChangesAsync();

                return(CreatedAtAction("GetGeoMessages", new { id = v2modell.Id }, v2modell));
            }