Beispiel #1
0
        // POST: api/Sport
        public HttpResponseMessage Post([FromBody] Sport sport)
        {
            HttpResponseMessage response;

            if (sport == null)
            {
                response = Request.CreateResponse(HttpStatusCode.NoContent, "Invalid JSON Passed.");
                return(response);
            }

            if (string.IsNullOrWhiteSpace(sport.name))
            {
                response = Request.CreateResponse(HttpStatusCode.PartialContent, "Sport Name is empty.");
                return(response);
            }

            if (sport.userId <= 0)
            {
                response = Request.CreateResponse(HttpStatusCode.PartialContent, "User Id is empty.");
                return(response);
            }

            long sportId = _iSportRepository.InsertSport(sport);

            if (sportId != -1)
            {
                response = Request.CreateResponse(HttpStatusCode.OK, "Sport added successfully.");
            }
            else
            {
                response = Request.CreateResponse(HttpStatusCode.Conflict, "Error adding sport.");
            }

            return(response);
        }