Ejemplo n.º 1
0
        // POST api/<controller>
        public HttpResponseMessage Post(HttpRequestMessage httpRequest, [FromBody] Location location)
        {
            var useremail = new TApiAuth().GetLoggedInUsername(Request);

            if (string.IsNullOrEmpty(useremail))
            {
                return(new HttpResponseMessage(HttpStatusCode.BadRequest));
            }
            var user = _userManager.GetUserFromMailId(useremail);

            if (user.isAdmin.HasValue && user.isAdmin.Value)
            {
                //check if user is admin
                location.Id = Guid.NewGuid().ToString();
                string message  = _locationManager.AddNewLocation(location);
                var    response = httpRequest.CreateResponse(message);
                response.StatusCode = System.Net.HttpStatusCode.Created;
                return(response);
            }
            else
            {
                return(new HttpResponseMessage(HttpStatusCode.Unauthorized));
            }
        }