Ejemplo n.º 1
0
        public HttpResponseMessage AddImage()
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest,
                                                  ErrorsManager.GetErrors(ModelState)));
                }

                var httpRequest = HttpContext.Current.Request;

                //Upload image
                var postedFile = httpRequest.Files["image"];

                // Create a unique file name:
                string fileName = Guid.NewGuid() + ".jpg";

                // Find the entire path to the uploads directory on server:
                string filePath = HttpContext.Current.Server.MapPath("~/Images/" + fileName);

                //Save image
                postedFile.SaveAs(filePath);

                return(Request.CreateResponse(HttpStatusCode.Created, fileName));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(
                           HttpStatusCode.InternalServerError,
                           ErrorsManager.GetInnerMessage(ex)));
            }
        }
Ejemplo n.º 2
0
        public HttpResponseMessage SearchCar(SearchCarDTO searchedCar)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest,
                                                  ErrorsManager.GetErrors(ModelState)));
                }

                List <displayCarDTO> allAvlableCars = logic.SearchCar(searchedCar);
                return(Request.CreateResponse(HttpStatusCode.OK, allAvlableCars));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(
                           HttpStatusCode.InternalServerError,
                           ErrorsManager.GetInnerMessage(ex)));
            }
        }
Ejemplo n.º 3
0
        public HttpResponseMessage AddCarBrand(carTypeDTO carBrand)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest,
                                                  ErrorsManager.GetErrors(ModelState)));
                }

                string addedCarBrand = logic.addCarType(carBrand);
                return(Request.CreateResponse(HttpStatusCode.Created, addedCarBrand));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(
                           HttpStatusCode.InternalServerError,
                           ErrorsManager.GetInnerMessage(ex)));
            }
        }
Ejemplo n.º 4
0
        public HttpResponseMessage getAllCars()
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest,
                                                  ErrorsManager.GetErrors(ModelState)));
                }

                List <displayCarDTO> getAllCars = logic.GetAllCars();
                return(Request.CreateResponse(HttpStatusCode.OK, getAllCars));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(
                           HttpStatusCode.InternalServerError,
                           ErrorsManager.GetInnerMessage(ex)));
            }
        }