Exemplo n.º 1
0
    public async Task <ActionResult> Edit(int id, [Bind] EditChargeForm formulaire)
    {
        if (ModelState.IsValid)
        {
            Charge charge = new Charge
            {
                IdCharge     = formulaire.IdCharge,
                IdHistory    = Convert.ToInt32(formulaire.HistoryId),
                IdProvider   = Convert.ToInt32(formulaire.ProviderName),
                Entitled     = formulaire.Entitled,
                Amount       = formulaire.Amount,
                BillNumber   = formulaire.BillNumber,
                DeliveryDate = formulaire.DeliveryDate
            };

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(Baseurl);
                client.DefaultRequestHeaders.Clear();

                StringContent content = new StringContent(JsonConvert.SerializeObject(charge));
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                HttpResponseMessage Res = await client.PutAsync($"Charge/Update", content);

                if (!Res.IsSuccessStatusCode) /*error handling*/ } {
        }

        return(RedirectToAction("Index"));
    }
    else
    {
        return(View());
    }
}
Exemplo n.º 2
0
    // GET: Charge/Edit/5
    public async Task <ActionResult> Edit(string id)
    {
        EditChargeForm model = new EditChargeForm();

        model = await GetDetails(id);

        List <GetCarForm> carList = await CarController.GetCarList();

        List <SelectListItem> getcarformList = new List <SelectListItem>();

        foreach (GetCarForm Car in carList)
        {
            getcarformList.Add(new SelectListItem {
                    Text = Car.ChassisNumber + " - " + Car.ModelName, Value = Car.IdCar.ToString()
                }
                               );
        }

        List <GetHistoryForm> historyList = await HistoryController.GetHistoryList();

        List <SelectListItem> gethistoryformList = new List <SelectListItem>();

        foreach (GetHistoryForm History in historyList)
        {
            var data = (from b in carList
                        where b.IdCar == History.IdCar
                        select b.ChassisNumber).FirstOrDefault();
            var data2 = (from b in carList
                         where b.IdCar == History.IdCar
                         select b.ModelName).FirstOrDefault();

            gethistoryformList.Add(new SelectListItem
                {
                    Selected = (History.IdHistory == Convert.ToInt32(model.HistoryId)),
                    Text     = data + " - " + data2,
                    Value    = History.IdHistory.ToString()
                });
        }

        List <GetProviderForm> providerList = await ProviderController.GetProviderList();

        List <SelectListItem> getproviderformList = new List <SelectListItem>();

        foreach (GetProviderForm Provider in providerList)
        {
            getproviderformList.Add(new SelectListItem {
                    Text = Provider.Name, Value = Provider.IdProvider.ToString()
                });
        }

        model.ProviderList = getproviderformList;
        model.HistoryList  = gethistoryformList;
        return(View(model));
    }
Exemplo n.º 3
0
        // GET: Provider/Details/5
        public async Task <EditChargeForm> GetDetails(string id)
        {
            Charge         ModelGlobal = default(Charge);
            EditChargeForm ModelLocal  = default(EditChargeForm);

            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($"Charge/Get/{id}");

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