private async Task Submit(string type) { string vehicleId; string authToken = (Application.Current as App).UserAuthToken; TyreType = type; string jsonData = string.Empty; if (type == CommonConstants.SameTypeTyre) { vehicleId = VehicleList.Where(v => v.VehicleNo == SameTyreSelectedVehicle).FirstOrDefault()?.VehicleId; SameTyre.TyreStatus = SameTypeTyreStatus; if (!ValidateFields()) { return; } jsonData = JsonConvert.SerializeObject( new { authToken, vehicleId, TyreType, SameTyre }); } else { vehicleId = VehicleList.Where(v => v.VehicleNo == DifferentTyreSelectedVehicle).FirstOrDefault()?.VehicleId; DifferentTypeTyre.FrontTyre.TyreStatus = DifferentTypeFrontTyreStatus; DifferentTypeTyre.RearTyre.TyreStatus = DifferentTypeRearTyreStatus; if (!ValidateFields()) { return; } jsonData = JsonConvert.SerializeObject( new { authToken, vehicleId, TyreType, DifferentTypeTyre }); } var result = await restServices.AddTyreInfo(jsonData); if (result.Status == CommonConstants.SuccessStatus) { } }
public TyreViewModel(IPageService pageService, string authToken) { restServices = new RestServices(); this.pageService = pageService; Task.Run(async() => { VehicleList = await restServices.GetVehicleList((Application.Current as App).UserAuthToken); VehicleNoList = VehicleList.Select(l => l.VehicleNo).ToList(); }); SameTyre = new Tyre(); DifferentTypeTyre = new DifferentTypeTyre { FrontTyre = new Tyre(), RearTyre = new Tyre() }; TyreStatusList = new List <string>() { CommonConstants.NewTyreType, CommonConstants.OldTyreType }; SubmitCommand = new Command <string>(async(type) => await Submit(type)); }