예제 #1
0
        public HttpResponseMessage EditCarImage(int id)
        {
            try
            {
                using (logic)
                {
                    string fileName = Guid.NewGuid() + ".jpg";
                    string fullPath = HttpContext.Current.Server.MapPath("~/Uploads/" + fileName);


                    using (FileStream stream = new FileStream(fullPath, FileMode.Create))
                    {
                        HttpContext.Current.Request.InputStream.CopyTo(stream); // This will save the file
                    }

                    CarsDTO updatedCar = logic.EditPicture(id, fileName);

                    if (updatedCar == null)
                    {
                        return(Request.CreateResponse(HttpStatusCode.NotFound));
                    }

                    return(Request.CreateResponse(HttpStatusCode.OK, updatedCar));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(
                           HttpStatusCode.InternalServerError, ErrorsManager.GetInnerMeesage(ex)));
            }
        }
예제 #2
0
        public CarsDTO UpdateCar(CarsDTO givenCar)
        {
            Car carToUpdate = DB.Cars.Where(p => p.CarID == givenCar.id).SingleOrDefault();

            if (carToUpdate == null)
            {
                return(null);
            }
            carToUpdate.CarNumber         = givenCar.carNum;
            carToUpdate.ManufactorID      = givenCar.manufactor.id;
            carToUpdate.ModelID           = givenCar.model.id;
            carToUpdate.Year              = givenCar.year;
            carToUpdate.DesignID          = givenCar.design.id;
            carToUpdate.GearID            = givenCar.gear.id;
            carToUpdate.RentDayPrice      = givenCar.dailyRent;
            carToUpdate.LateDayRentPrice  = givenCar.lateRent;
            carToUpdate.BranchID          = givenCar.branch.id;
            carToUpdate.Picture           = givenCar.picture;
            carToUpdate.Kilometrage       = givenCar.kilometrage;
            carToUpdate.FunctionalForRent = givenCar.functional;


            DB.SaveChanges();
            return(givenCar);
        }
예제 #3
0
 public HttpResponseMessage AddCar(CarsDTO givenCar)
 {
     try
     {
         using (logic)
         {
             CarsDTO addedCar = logic.AddCar(givenCar);
             return(Request.CreateResponse(HttpStatusCode.Created, addedCar));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ErrorsManager.GetInnerMeesage(ex)));
     }
 }
예제 #4
0
        public CarsDTO EditPicture(int id, string imageCode)
        {
            Car carToUpdate = DB.Cars.Where(p => p.CarID == id).SingleOrDefault();

            if (carToUpdate == null)
            {
                return(null);
            }
            if (carToUpdate.Picture != imageCode && carToUpdate.Picture != null)
            {
                File.Delete(HttpContext.Current.Server.MapPath("~/Uploads/" + carToUpdate.Picture));
            }


            carToUpdate.Picture = imageCode;

            DB.SaveChanges();
            CarsDTO carToReturn = new CarsDTO
            {
                id         = carToUpdate.CarID,
                carNum     = carToUpdate.CarNumber,
                manufactor = new ManufactorsDTO {
                    id = carToUpdate.Manufactor.ManufactorID, manufactor = carToUpdate.Manufactor.Manufactor1
                },
                model = new ModelsDTO {
                    id = carToUpdate.Model.ModelID, manufactor = new ManufactorsDTO {
                        id = carToUpdate.Manufactor.ManufactorID, manufactor = carToUpdate.Manufactor.Manufactor1
                    }, model = carToUpdate.Model.Model1
                },
                design = new DesignsDTO {
                    id = carToUpdate.Design.DesignID, design = carToUpdate.Design.CarDesign
                },
                gear = new GearDTO {
                    id = carToUpdate.Gear.GearID, gear = carToUpdate.Gear.GearType
                },
                kilometrage = carToUpdate.Kilometrage,
                year        = carToUpdate.Year,
                functional  = carToUpdate.FunctionalForRent,
                dailyRent   = carToUpdate.RentDayPrice,
                lateRent    = carToUpdate.LateDayRentPrice,
                picture     = carToUpdate.Picture,
                branch      = new BranchesDTO {
                    id = carToUpdate.Branch.BranchID, address = carToUpdate.Branch.Address, city = carToUpdate.Branch.City
                }
            };

            return(carToReturn);
        }
예제 #5
0
 public HttpResponseMessage UpdateCars(CarsDTO givenCar, int id)
 {
     try
     {
         using (logic)
         {
             givenCar.id = id;
             CarsDTO updatedCar = logic.UpdateCar(givenCar);
             if (updatedCar == null)
             {
                 return(Request.CreateResponse(HttpStatusCode.NotFound));
             }
             return(Request.CreateResponse(HttpStatusCode.OK, updatedCar));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ErrorsManager.GetInnerMeesage(ex)));
     }
 }
예제 #6
0
        public HttpResponseMessage DeleteCarImage(int id)
        {
            try
            {
                using (logic)
                {
                    CarsDTO updatedCar = logic.EditPicture(id, null);

                    if (updatedCar == null)
                    {
                        return(Request.CreateResponse(HttpStatusCode.NotFound));
                    }

                    return(Request.CreateResponse(HttpStatusCode.OK, updatedCar));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(
                           HttpStatusCode.InternalServerError, ErrorsManager.GetInnerMeesage(ex)));
            }
        }
예제 #7
0
        public CarsDTO AddCar(CarsDTO givenCar)
        {
            Car carToAdd = new Car
            {
                CarNumber         = givenCar.carNum,
                ManufactorID      = givenCar.manufactor.id,
                ModelID           = givenCar.model.id,
                DesignID          = givenCar.design.id,
                Year              = givenCar.year,
                RentDayPrice      = givenCar.dailyRent,
                LateDayRentPrice  = givenCar.lateRent,
                GearID            = givenCar.gear.id,
                BranchID          = givenCar.branch.id,
                FunctionalForRent = givenCar.functional,
                Kilometrage       = givenCar.kilometrage,
                Picture           = givenCar.picture
            };

            DB.Cars.Add(carToAdd);
            DB.SaveChanges();
            givenCar.id = carToAdd.CarID;
            return(givenCar);
        }