public async Task <Viatic> ToViaticAsync(ViaticViewModel model, string path, bool isNew) { var viatic = new Viatic { Id = isNew ? 0 : model.Id, Description = model.Description, ImageUrl = path, InvoiceDate = model.InvoiceDate, InvoiceAmmount = model.InvoiceAmmount, ViaticName = model.ViaticName, ViaticType = model.ViaticType, Traveler = await _context.Travelers.FindAsync(model.Traveler), Trip = await _context.Trips.FindAsync(model.TripId), }; return(viatic); }
public async Task <IActionResult> Viatics(ViaticViewModel model) { if (ModelState.IsValid) { var path = string.Empty; if (model.ImageFile != null) { path = await _imageHelper.UploadImageAsync(model.ImageFile); } var viatic = await _converterHelper.ToViaticAsync(model, path, true); _context.Viatics.Add(viatic); await _context.SaveChangesAsync(); return(RedirectToAction("Details", "Home", new { id = model.TripId })); } return(View(model)); }
// TODO: CREATE VIATIC public async Task <IActionResult> Viatics(int?id) { if (id == null) { return(NotFound()); } var trip = await _context.Trips.FindAsync(id.Value); if (trip == null) { return(NotFound()); } var model = new ViaticViewModel { TripId = trip.Id, InvoiceDate = DateTime.Today }; return(View(model)); }
public async Task <IActionResult> EditViatic(ViaticViewModel model) { if (ModelState.IsValid) { var path = model.ImageUrl; if (model.ImageFile != null) { path = await _imageHelper.UploadImageAsync(model.ImageFile); } var viatic = await _converterHelper.ToViaticAsync(model, path, false); _context.Viatics.Update(viatic); await _context.SaveChangesAsync(); return(RedirectToAction("DetailsTrip", "Travelers", new { id = model.TripId })); } return(View(model)); }
public ViaticsPage() { InitializeComponent(); BindingContext = new ViaticViewModel(); }