예제 #1
0
 // PUT: api/CarType/5
 public IHttpActionResult Put(int id, [FromBody] Car editCar)
 {
     try
     {
         using (Car_RentalsEntities4 carDb = new Car_RentalsEntities4())
         {
             var updatedCarModel = carDb.Car_Types.FirstOrDefault(c => c.Model_Id == id);
             if (updatedCarModel == null)
             {
                 return(NotFound());
             }
             else
             {
                 updatedCarModel.Cost_pre_Day       = editCar.CostPerDay;
                 updatedCarModel.Delay_Cost_per_Day = editCar.DelayCostPerDay;
                 updatedCarModel.isGear             = editCar.IsGear;
                 updatedCarModel.Company_Name       = editCar.Manufacturer;
                 updatedCarModel.Model             = editCar.Model;
                 updatedCarModel.Manufactured_Year = editCar.YearManufactured;
                 carDb.SaveChanges();
                 return(Ok());
             }
         }
     }
     catch (Exception msg) {
         Console.WriteLine(msg);
         return(BadRequest());
     }
 }
 public IHttpActionResult Put(int id, [FromBody] CarsForRent rental)
 {
     try
     {
         using (Car_RentalsEntities4 rentalCardb = new Car_RentalsEntities4())
         {
             var UpdatedCar = rentalCardb.Cars_for_Rents.FirstOrDefault(c => c.License == id);
             if (UpdatedCar == null)
             {
                 return(NotFound());
             }
             else
             {
                 UpdatedCar.IsAvalible     = rental.IsAvalible;
                 UpdatedCar.IsUsable       = rental.IsUsable;
                 UpdatedCar.Branch_Id      = rental.Lot;
                 UpdatedCar.Car_Type_Id    = rental.CarType;
                 UpdatedCar.Distance_Usage = rental.CarUsage;
                 UpdatedCar.License        = rental.LicenseNumber;
                 UpdatedCar.CarImage       = rental.Image;
                 rentalCardb.SaveChanges();
                 return(Ok());
             }
         }
     }
     catch (Exception msg)
     {
         Console.WriteLine(msg);
         return(BadRequest());
     }
 }
예제 #3
0
        public IHttpActionResult Put(int id, [FromBody] SiteUser user)
        {
            try
            {
                using (Car_RentalsEntities4 db = new Car_RentalsEntities4())
                {
                    var UpdatedUser = db.Users.FirstOrDefault(c => c.TZ == id);
                    if (UpdatedUser == null)
                    {
                        return(NotFound());
                    }

                    else
                    {
                        UpdatedUser.User_Level = (int)user.Permissions;
                        UpdatedUser.User_Name  = user.UserName;
                        UpdatedUser.Birth_Date = user.Birthdate;
                        UpdatedUser.Email      = user.Email;
                        UpdatedUser.Gender     = user.Gender;
                        UpdatedUser.Password   = user.Password;
                        UpdatedUser.Full_name  = user.Fullname;
                        UpdatedUser.UserImage  = user.Image;
                        db.SaveChanges();
                        return(Ok());
                    }
                }
            }
            catch (Exception msg)
            {
                Console.WriteLine(msg);
                return(BadRequest());
            }
        }
예제 #4
0
 // PUT: api/Rentals/5
 public IHttpActionResult Put(int id, [FromBody] CarRentals rental)
 {
     try
     {
         using (Car_RentalsEntities4 carDb = new Car_RentalsEntities4())
         {
             var updatedRental = carDb.Rentals.FirstOrDefault(r => r.Rental_Id == id);
             if (updatedRental == null)
             {
                 return(NotFound());
             }
             else
             {
                 updatedRental.Rental_Id            = rental.RentalId;
                 updatedRental.RentCost             = rental.RentCost;
                 updatedRental.Start_Rental_Date    = rental.RentalStart;
                 updatedRental.User_Id              = rental.User;
                 updatedRental.End_Rental_Date      = rental.RentalEnd;
                 updatedRental.Car_Id               = rental.CarRented;
                 updatedRental.Actual_Date_Returned = rental.ActualReturn;
                 carDb.SaveChanges();
                 return(Ok());
             }
         }
     }
     catch (Exception msg)
     {
         Console.WriteLine(msg);
         return(BadRequest());
     }
 }