예제 #1
0
        public ActionResult PatchCar(int id, [FromBody] Car model)
        {
            var car = Cars.FirstOrDefault(x => x.Id == id);

            if (car == null)
            {
                return(NotFound("Masina nu a fost gasita"));
            }

            if (model.Manufacteur != null)
            {
                car.Manufacteur = model.Manufacteur;
            }
            if (model.Model != null)
            {
                car.Model = model.Model;
            }
            if (model.Year != null)
            {
                car.Year = model.Year;
            }
            if (model.CylindricCapacity != 0)
            {
                car.CylindricCapacity = model.CylindricCapacity;
            }

            var links = Hypermedia.CarMedia(car);

            return(Ok(new { Cars = car, Links = links }));
        }
예제 #2
0
        public ActionResult InsertCar([FromBody] Car model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

            Cars.Add(model);

            var links = Hypermedia.CarMedia(model);

            return(Ok(new { Cars = model, Links = links }));
        }
예제 #3
0
        public ActionResult <Car> GetById(int id)
        {
            var car = Cars.FirstOrDefault(x => x.Id == id);

            if (car == null)
            {
                return(NotFound("Masina nu a fost gasita"));
            }

            var links = Hypermedia.CarMedia(car);

            return(Ok(new { Cars = car, Links = links }));
        }
예제 #4
0
        public ActionResult UpdateCar(int id, [FromBody] Car model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

            var car = Cars.FirstOrDefault(x => x.Id == id);

            if (car == null)
            {
                return(NotFound("Masina nu a fost gasita"));
            }

            car = model;

            var links = Hypermedia.CarMedia(car);

            return(Ok(new { Cars = car, Links = links }));
        }
예제 #5
0
        public ActionResult BuyCar(int id, [FromBody] Customer c)
        {
            string name = c.Name;
            var    car  = Cars.FirstOrDefault(x => x.Id == id);

            if (car == null)
            {
                return(NotFound("Masina nu a fost gasita"));
            }

            var customer = Customers.Where(x => x.Name == name).FirstOrDefault();

            if (customer == null)
            {
                customer = new Customer(name);
                Customers.Add(customer);
            }

            customer.OwnedCars.Add(car);

            var links = Hypermedia.CarMedia(car);

            return(Ok(new { Customer = customer, Links = links }));
        }