public IHttpActionResult Delete([FromBody] Models.Inventory.Cars carsEntry)
        {
            try
            {
                var context = new EntityModels.Prod8Entities();
                var exists  = context.CARS_AVAILABILTY_CONTROL_TAB.Where(x => x.LOCATION_NO == carsEntry.LocationNo).FirstOrDefault();
                if (exists == null)
                {
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
                    {
                        ReasonPhrase = "No data found. Delete Failed"
                    });
                }
                context.CARS_AVAILABILTY_CONTROL_TAB.Remove(exists);
                context.SaveChanges();

                return(Ok(true));
            }
            catch (HttpResponseException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public IHttpActionResult Save([FromBody] Models.Inventory.Cars carsEntry, bool isAdd)
 {
     if (isAdd)
     {
         return(Add(carsEntry));
     }
     else
     {
         return(Edit(carsEntry));
     }
 }
        private IHttpActionResult Add([FromBody] Models.Inventory.Cars carsEntry)
        {
            try
            {
                var context = new EntityModels.Prod8Entities();
                //add new entry
                if (String.IsNullOrWhiteSpace(carsEntry.LocationNo) ||
                    String.IsNullOrWhiteSpace(carsEntry.LocationNo) ||
                    String.IsNullOrWhiteSpace(carsEntry.LocationNo) ||
                    String.IsNullOrWhiteSpace(carsEntry.LocationNo))
                {
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
                    {
                        ReasonPhrase = "One or more data fields is empty, null, or just not defined."
                    });
                }
                var newCar = new EntityModels.CARS_AVAILABILTY_CONTROL_TAB()
                {
                    LOCATION_NO             = carsEntry.LocationNo,
                    AVAILABILITY_CONTROL_ID = carsEntry.AvailabilityControlId,
                    REQUESTED_BY            = carsEntry.RequestedBy,
                    WAREHOUSE  = carsEntry.Warehouse,
                    ROWVERSION = DateTime.Today
                };
                context.CARS_AVAILABILTY_CONTROL_TAB.Add(newCar);
                context.SaveChanges();

                var car = new Models.Inventory.Cars()
                {
                    LocationNo            = newCar.LOCATION_NO,
                    AvailabilityControlId = newCar.AVAILABILITY_CONTROL_ID,
                    RequestedBy           = newCar.REQUESTED_BY,
                    Warehouse             = newCar.WAREHOUSE
                };


                return(Ok(car));
            }
            catch (HttpResponseException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private IHttpActionResult Edit([FromBody] Models.Inventory.Cars carsEntry)
        {
            try
            {
                var context        = new EntityModels.Prod8Entities();
                var carEntryFromDB = context.CARS_AVAILABILTY_CONTROL_TAB.Where(x => x.LOCATION_NO == carsEntry.LocationNo).FirstOrDefault();
                if (carEntryFromDB == null)
                {
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
                    {
                        ReasonPhrase = "No data for this entry exists."
                    });
                }
                //update entry then save
                carEntryFromDB.LOCATION_NO             = carsEntry.LocationNo;
                carEntryFromDB.AVAILABILITY_CONTROL_ID = carsEntry.AvailabilityControlId;
                carEntryFromDB.REQUESTED_BY            = carsEntry.RequestedBy;
                carEntryFromDB.WAREHOUSE = carsEntry.Warehouse;

                context.SaveChanges();

                var car = new Models.Inventory.Cars()
                {
                    LocationNo            = carEntryFromDB.LOCATION_NO,
                    AvailabilityControlId = carEntryFromDB.AVAILABILITY_CONTROL_ID,
                    RequestedBy           = carEntryFromDB.REQUESTED_BY,
                    Warehouse             = carEntryFromDB.WAREHOUSE
                };

                return(Ok(car));
            }
            catch (HttpResponseException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }