public async Task <ActionResult> ReadWithData(Guid id, string token) { try { var usertoken = await Storage.FindUserByToken(token); var response = new FullTrip(await Storage.ReadTrip(id, usertoken.UserId)); if (response == null) { throw new ArgumentException("Such trip doesn't exist"); } response.Places = await Storage.ReadManyPlaces(response.PlaceIds ?? new Guid[0], usertoken.UserId); response.Goods = await Storage.ReadManyGoods(response.GoodIds ?? new Guid[0], usertoken.UserId); response.Goals = await Storage.ReadManyGoals(response.GoalIds ?? new Guid[0], usertoken.UserId); response.Purchases = await Storage.ReadManyPurchases(response.PurchaseIds ?? new Guid[0], usertoken.UserId); return(StatusCode(StatusCodes.Status200OK, response)); } catch (ArgumentException exeption) { return(StatusCode(StatusCodes.Status404NotFound, exeption.Message)); } catch (Exception exeption) { return(StatusCode(StatusCodes.Status500InternalServerError, exeption.Message)); } }
public static void SendRapport(int inCons, int inDest, DateTime inStart) { var xmlList = Serializer.Load(); for (int i = 0; i < xmlList.Count; i++) { if (xmlList[i].myTrip.User == inCons && xmlList[i].myTrip.Destination == inDest && xmlList[i].myTrip.Start == inStart) { FullTrip full = xmlList[i]; Trip trip = ModelTransformer.TripModel2Trip(full.myTrip); TripRepository.AddTrip(trip); foreach (var vac in full.myVacation) { vac.tripID = trip.tripID; VacationsRepository.AddVacation(ModelTransformer.VacationModel2Vacation(vac)); } foreach (var item in full.myVerifications) { item.tripID = trip.tripID; VerificationRepository.AddVerification(ModelTransformer.VerificationModel2Verification(item)); } xmlList.RemoveAt(i); } } Serializer.Overwrite(xmlList); }
public static void Save(FullTrip fullTrip) { var trips = new List <FullTrip>(); trips = Load(); trips.Add(fullTrip); var writer = new System.Xml.Serialization.XmlSerializer(typeof(List <FullTrip>)); var file = new System.IO.StreamWriter(Filename); writer.Serialize(file, trips); file.Close(); }
private void btnAddVerification_Click(object sender, RoutedEventArgs e) { double price; Double.TryParse(tbCost.Text, out price); FullTrip selectedItem = (FullTrip)cbPickTripExpensesTab.SelectedItem; var verification = new VerificationModel(); verification.cost = price; verification.note = tbCostNotes.Text; verification.date = dpExpence.DisplayDate; fulltrips[cbPickTripExpensesTab.SelectedIndex].myVerifications.Add(verification); Serializer.Overwrite(fulltrips); //List<FullTrip> test = new List<FullTrip>(); //test = (List<FullTrip>)cbPickTripExpensesTab.ItemsSource; MessageBox.Show("Kostnad tillagd till resan."); }
private void btnSend_Click(object sender, RoutedEventArgs e) { var realtrip = new Trip(); var trip = new TripModel(); //fyller modellen med information realtrip.origin = (int)cbCountryDeparture.SelectedValue; realtrip.destination = (int)cbCountryArrival.SelectedValue; realtrip.start = (DateTime)dpStartDate.SelectedDate; realtrip.end = (DateTime)dpEndDate.SelectedDate; var prepay = tbPrepaySum.Text; int prepaySum; int.TryParse(prepay, out prepaySum); realtrip.prepayment = prepaySum; realtrip.note = tbMotivation.Text; realtrip.boss = (int)cbBosses.SelectedItem; realtrip.user = HandleItems.GetCurrentUserId(); //validerar informationen som hämtats ut or boxarna if (Validering.CheckPrepaySum((int)realtrip.prepayment)) { var FullTrip = new FullTrip(); FullTrip.myTrip = ModelTransformer.Trip2TripModel(realtrip); foreach (Vacation item in lbVacations.Items) { FullTrip.myVacation.Add(ModelTransformer.Vacation2VacationModel(item)); } // DB!!! //TripRepository.AddTrip(realtrip); //foreach(var item in FullTrip.myVacation) //{ // var vacation = ModelTransformer.VacationModel2Vacation(item); // vacation.tripID = realtrip.tripID; // VacationsRepository.AddVacation(vacation); //} Serializer.Save(FullTrip); ClearFieldsAndReloadBoxes(); } }