Esempio n. 1
0
        public HttpResponseMessage AddCar(CarRegistrationDto carRegistrationDto)
        {
            string numberPlate   = carRegistrationDto.Number_Plate;
            string make          = carRegistrationDto.Make;
            string model         = carRegistrationDto.Model;
            int    year          = carRegistrationDto.Year;
            int    numberOfSeats = carRegistrationDto.Number_Of_Seats;
            string ownerId       = carRegistrationDto.Owner_ID;

            if (!isUserIdEqualToLoggedInUser(ownerId))
            {
                var       message = string.Format("Permission denied");
                HttpError err     = new HttpError(message);
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, err));
            }
            else
            {
                bool success = carBusiness.AddCar(numberPlate, make, model, year, numberOfSeats, ownerId);

                if (!success)
                {
                    var       message = string.Format(carBusiness.CarRegistrationValidationMessage(numberPlate, make, model, year, numberOfSeats, ownerId));
                    HttpError err     = new HttpError(message);
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, err));
                }
                else
                {
                    var message = string.Format("Car registered successfully!");
                    return(Request.CreateResponse(HttpStatusCode.OK, string.Format(message)));
                }
            }
        }