Exemple #1
0
        public HttpResponseMessage Put([FromBody] Game game)
        {
            using (NBAEntities entities = new NBAEntities())
            {
                try
                {
                    var entity = entities.Games.FirstOrDefault(e => e.ID == game.ID);
                    if (entity == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Not found"));
                    }
                    else
                    {
                        entity.Team1       = game.Team1;
                        entity.Team2       = game.Team2;
                        entity.Period      = game.Period;
                        entity.Time        = game.Time;
                        entity.Description = game.Description;
                        entity.ScoreTeam1  = game.ScoreTeam1;
                        entity.ScoreTeam2  = game.ScoreTeam2;

                        entities.SaveChanges();
                        return(Request.CreateResponse(HttpStatusCode.OK, game));
                    }
                }
                catch (Exception ex)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
                }
            }
        }
Exemple #2
0
        public HttpResponseMessage Delete(int id)
        {
            try
            {
                using (NBAEntities entities = new NBAEntities())
                {
                    var entity = entities.Games.FirstOrDefault(e => e.ID == id);

                    if (entity == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "ID " + id.ToString() + " NOT FOUND"));
                    }
                    else
                    {
                        entities.Games.Remove(entity);
                        entities.SaveChanges();
                        return(Request.CreateResponse(HttpStatusCode.OK, entity));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Exemple #3
0
        private void btnSell_Click(object sender, RoutedEventArgs e)
        {
            NBAEntities ctx  = new NBAEntities();
            Customer    cust = new Customer();

            cust.Age            = int.Parse(ageTextBox.Text);
            cust.Licence_Number = licence_NumberTextBox.Text;

            ctx.Customers.Add(cust);

            Person psn = new Person();

            psn.Address   = addressTextBox.Text;
            psn.Name      = nameTextBox.Text;
            psn.Telephone = telephoneTextBox.Text;
            DataStore.addCustomer(cust, psn);

            int       Car_for_sale_ID = int.Parse(car_For_Sale_IdTextBox.Text);
            Cars_Sold cs = ctx.Cars_Sold.Where(sc => sc.Car_For_Sale_Id == Car_for_sale_ID).FirstOrDefault();

            Cars_Sold sale = new Cars_Sold();

            sale.Car_For_Sale_Id = Car_for_sale_ID;
            sale.Customer        = cust;
            sale.Date_Sold       = DateTime.Now;

            ctx.Cars_Sold.Add(sale);
            ctx.SaveChanges();
            MessageBox.Show("Car has been sold to new customer");
        }
        public DisplayListOfCarsforSale()
        {
            InitializeComponent();

            NBAEntities ctx = new NBAEntities();

            carsforSaleDG.ItemsSource = ctx.Database.SqlQuery <DisplayCarsForSale>("SELECT CarModel.Model, CarModel.Manufacturer, CarModel.NumberOfSeats, CarModel.EngineSize, CarModel.ModelID, IndividualCar.Body_Type, IndividualCar.Status, IndividualCar.Transmission, IndividualCar.Manufacture_Year,IndividualCar.Date_Imported, IndividualCar.Current_Mileage, IndividualCar.Colour, IndividualCar.CarID FROM CarModel INNER JOIN IndividualCar ON CarModel.ModelID = IndividualCar.Model_ID WHERE IndividualCar.Status = 'Available'").ToList();
        }
Exemple #5
0
 public HttpResponseMessage Get(int id)
 {
     using (NBAEntities entities = new NBAEntities())
     {
         var entity = entities.Games.FirstOrDefault(e => e.ID == id);
         if (entity != null)
         {
             return(Request.CreateResponse(HttpStatusCode.OK, entity));
         }
         else
         {
             return(Request.CreateErrorResponse(HttpStatusCode.NotFound,
                                                "Game with ID " + id.ToString() + " NOT FOUND"));
         }
     }
 }
Exemple #6
0
        public HttpResponseMessage Post([FromBody] Game game)
        {
            try
            {
                using (NBAEntities entities = new NBAEntities())
                {
                    entities.Games.Add(game);
                    entities.SaveChanges();

                    var message = Request.CreateResponse(HttpStatusCode.Created, game);
                    message.Headers.Location = new Uri(Request.RequestUri + game.ID.ToString());
                    return(message);
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Exemple #7
0
 public GameRepository(NBAEntities context)
 {
     this.context = context;
 }
Exemple #8
0
 public IEnumerable <Game> Get()
 {
     using (NBAEntities entities = new NBAEntities())
         return(entities.Games.ToList());
 }