public User createUser(User toSave) { if (_repo.getUserFromDatabase(toSave.citizenServiceNumber) != null) { return(null); } toSave.password = generatePassword(toSave.password); RegistrationModel model = new RegistrationModel { LastName = toSave.lastName, CitizenServiceNumber = toSave.citizenServiceNumber, FirstName = toSave.firstName }; HttpResponseMessage response = RestHelper.AasHttpClient() .PostAsync($"owners", RestHelper.ConvertToSendableHttpObject(model)).Result; response.EnsureSuccessStatusCode(); string msg = response.Content.ReadAsStringAsync().Result; RestUserModel mod = JsonConvert.DeserializeObject <RestUserModel>(msg); toSave.address = mod.Address; toSave.birthDay = DateTime.ParseExact(mod.Birthday, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture); toSave.cars = _carService.GetCarsOfUserFromAAS(toSave.citizenServiceNumber) as List <Car>; toSave.Language = "NLD"; toSave.lastSyncTime = DateTime.Now; toSave.invoices = new List <Invoice>(); return(_repo.Add(toSave)); }
public List <Invoice> GetAllInvoices(long citizenServiceNumber) { HttpResponseMessage response = RestHelper.AasHttpClient().GetAsync($"invoices/" + citizenServiceNumber).Result; response.EnsureSuccessStatusCode(); var foundInvoices = response.Content.ReadAsStringAsync().Result; var invoiceModels = JsonConvert.DeserializeObject <List <RestInvoiceModel> >(foundInvoices); List <Invoice> foundInvoicesJson = new List <Invoice>(); invoiceModels.ForEach(i => foundInvoicesJson.Add(new Invoice() { invoiceNr = i.invoiceNr, paymentStatus = (PaymentStatus)Enum.Parse(typeof(PaymentStatus), i.paymentStatus), period = i.date, totalAmount = i.totalAmount })); foundInvoicesJson.ForEach(i => { if (_repo.GetSpecificInvoice(i.invoiceNr) == null) { _repo.Add(i); } }); return(foundInvoicesJson); }
public IEnumerable <Car> GetCarsOfUserFromAAS(long csn) { HttpResponseMessage response = RestHelper.AasHttpClient().GetAsync($"cars/" + csn).Result; response.EnsureSuccessStatusCode(); var foundCars = response.Content.ReadAsStringAsync().Result; var userCars = JsonConvert.DeserializeObject <IEnumerable <Car> >(foundCars); List <Car> filledCars = new List <Car>(); userCars.ToList().ForEach(c => { Car cr = GetCar(c.CarID); filledCars.Add(cr ?? c); }); return(filledCars); }
public void updateInvoice(int paidInvoiceId) { Invoice invoice = _repo.GetSpecificInvoice(paidInvoiceId); invoice.paymentStatus = 0; _repo.Update(invoice); RestInvoiceModel restInvoiceModel = new RestInvoiceModel(); restInvoiceModel.invoiceNr = invoice.invoiceNr; restInvoiceModel.paymentStatus = "PAID"; var JsonObject = JsonConvert.SerializeObject(restInvoiceModel); var httpContent = new StringContent(JsonObject); httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); HttpResponseMessage response = RestHelper.AasHttpClient().PutAsync($"invoices", httpContent).Result; response.EnsureSuccessStatusCode(); }