Beispiel #1
0
        // GET: Model/Details/5
        public async Task <ActionResult> Details(string id)
        {
            List <GetBrandForm> getbrandList = await BrandController.GetBrandList();

            Model        ModelGlobal = default(Model);
            GetModelForm ModelLocal  = default(GetModelForm);

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(Baseurl);
                client.DefaultRequestHeaders.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                HttpResponseMessage Res = await client.GetAsync($"Model/Get/{id}");

                if (Res.IsSuccessStatusCode)
                {
                    var EmpResponse = Res.Content.ReadAsStringAsync().Result;
                    ModelGlobal = JsonConvert.DeserializeObject <Model>(EmpResponse);
                    ModelLocal  = AutoMapper <Model, GetModelForm> .AutoMap(ModelGlobal);
                }
            }

            ModelLocal.BrandName = (from b in getbrandList
                                    where b.IdBrand == ModelLocal.IdBrand
                                    select b.Name).FirstOrDefault();

            return(View(ModelLocal));
        }
        // GET: Car/Create
        public async Task <ActionResult> Create()
        {
            List <SelectListItem> getmodelformList = new List <SelectListItem>();
            List <GetModelForm>   modelList        = await ModelController.GetModelList();

            List <GetBrandForm> brandList = await BrandController.GetBrandList();

            foreach (GetModelForm item in modelList)
            {
                item.Name = (from b in brandList
                             where b.IdBrand == item.IdBrand
                             select b.Name).FirstOrDefault() + " - " + item.Name;
            }

            foreach (GetModelForm Model in modelList)
            {
                getmodelformList.Add(new SelectListItem {
                    Text = Model.Name, Value = Model.IdModel.ToString()
                });
            }

            var model = new AddCarForm
            {
                ModelList = getmodelformList
            };

            return(View(model));
        }
        public static async Task <List <GetCarForm> > GetCarList()
        {
            //chargement de la liste des voitures dans une liste pour linq
            IEnumerable <Car> CarList        = null;
            List <GetCarForm> getcarformList = new List <GetCarForm>();

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(Baseurl);
                client.DefaultRequestHeaders.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                HttpResponseMessage Res = await client.GetAsync("Car/Get");

                if (Res.IsSuccessStatusCode)
                {
                    var EmpResponse = Res.Content.ReadAsStringAsync().Result;
                    CarList = JsonConvert.DeserializeObject <List <Car> >(EmpResponse);
                }

                foreach (Car car in CarList)
                {
                    getcarformList.Add(AutoMapper <Car, GetCarForm> .AutoMap(car));
                }
            }
            List <GetModelForm> getmodelformList = await ModelController.GetModelList();

            List <GetBrandForm> getBrandformList = await BrandController.GetBrandList();

            foreach (var item in getmodelformList)
            {
                var data = (from b in getBrandformList
                            where b.IdBrand == item.IdBrand
                            select b.Name).FirstOrDefault();
                item.Name = data + " - " + item.Name;
            }

            foreach (var item in getcarformList)
            {
                var data = (from b in getmodelformList
                            where b.IdModel == item.IdModel
                            select b.Name).FirstOrDefault();

                item.ModelName = data;
            }

            return(getcarformList);
        }
Beispiel #4
0
        // GET: Model
        public async Task <ActionResult> Index()
        {
            List <GetBrandForm> getbrandList = await BrandController.GetBrandList();

            List <GetModelForm> getmodelList = await ModelController.GetModelList();

            foreach (var item in getmodelList)
            {
                var data = (from b in getbrandList
                            where b.IdBrand == item.IdBrand
                            select b.Name).FirstOrDefault();

                item.BrandName = data;
            }

            return(View(getmodelList));
        }
Beispiel #5
0
        // GET: Model/Create
        public async Task <ActionResult> Create()
        {
            List <SelectListItem> getbrandformList = new List <SelectListItem>();
            List <GetBrandForm>   getbrandList     = await BrandController.GetBrandList();

            foreach (GetBrandForm Brand in getbrandList)
            {
                getbrandformList.Add(new SelectListItem {
                    Text = Brand.Name, Value = Brand.IdBrand.ToString()
                });
            }

            var model = new AddModelForm
            {
                BrandList = getbrandformList
            };

            return(View(model));
        }
Beispiel #6
0
    // GET: Model/Edit/5
    public async Task <ActionResult> Edit(string id)
    {
        List <SelectListItem> getbrandformList = new List <SelectListItem>();
        List <GetBrandForm>   getbrandList     = await BrandController.GetBrandList();

        EditModelForm model = new EditModelForm();

        model = await GetDetails(id);

        foreach (GetBrandForm Brand in getbrandList)
        {
            getbrandformList.Add(new SelectListItem {
                    Text = Brand.Name, Value = Brand.IdBrand.ToString()
                }
                                 );
        }

        model.BrandList = getbrandformList;
        return(View(model));
    }