Exemplo n.º 1
0
        public IHttpActionResult PostUserLocation(UserLocation userlocation)
        {
            var currentUserId = User.Identity.GetUserId();
            var currentTeamName = manager.FindById(currentUserId).TeamName;

            userlocation.TeamName = currentTeamName;

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.UserLocations.Add(userlocation);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = userlocation.Id }, userlocation);
        }
Exemplo n.º 2
0
        // PUT api/UserLocation/5
        public IHttpActionResult PutUserLocation(int id, UserLocation userlocation)
        {
            //get user id and teamname
            var currentUserId = User.Identity.GetUserId();
            var currentTeamName = manager.FindById(currentUserId).TeamName;

            userlocation.TeamName = currentTeamName;

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != userlocation.Id)
            {
                return BadRequest();
            }

            db.Entry(userlocation).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserLocationExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }