public IActionResult cancelarTransporte(TransporteViewModel transporte) { success = !success; if (success) { string filepath = AppDomain.CurrentDomain.BaseDirectory + "\\ArchivosCompartidos\\touresbalon_orden_" + transporte.orderId + ".csv"; if (System.IO.File.Exists(filepath)) { using (StreamWriter sw = System.IO.File.AppendText(filepath)) { sw.Write($",C"); } return(Ok()); } else { return(BadRequest("reserva no existente")); } } else { return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public ActionResult <TransporteViewModel> Get(string nit) { var transporte = _transporteService.BuscarxNit(nit); if (transporte == null) { return(NotFound()); } var TransporteViewModel = new TransporteViewModel(transporte); return(TransporteViewModel); }
public ActionResult Edit(string Id) { var Transporte = new Transporte(); var model = new TransporteViewModel(); Transporte = Transporte.SelectTransporte(int.Parse(Id)); model.Id = Transporte.Id; model.Nombre = Transporte.Nombre; return(View(model)); }
public ActionResult Edit(TransporteViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var Transporte = new Transporte(); Transporte.UpdateTransporte(model.Id, model.Nombre); return(RedirectToAction("Index")); }
public IActionResult reservarPasaje(TransporteViewModel transporte) { success = !success; if (success) { return(Ok(WriteToFile(transporte))); } else { return(StatusCode(StatusCodes.Status500InternalServerError)); } }
// GET: Transportes public async Task <IActionResult> Index() { IEnumerable <Transporte> lista = await _repository.FindAll(); var lista_vm = new List <TransporteViewModel>(); foreach (Transporte t in lista) { var vm = new TransporteViewModel(t); lista_vm.Add(vm); } return(View(lista_vm)); }
public async Task <IEnumerable <TransporteViewModel> > GetConcursos() { IEnumerable <Transporte> lista = await _repository.FindAll(); IEnumerable <Link> lista_links = await _linkRepository.FindAll(); var lista_vm = new List <TransporteViewModel>(); foreach (var transporte in lista) { transporte.Link = lista_links.Single(l => l.Id == transporte.LinkId); var vm = new TransporteViewModel(transporte); lista_vm.Add(vm); } return(lista_vm); }
// GET: Transportes/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var transporte = await _repository.Get(id.Value); if (transporte == null) { return(NotFound()); } transporte.Link = await _linkRepository.Get(transporte.LinkId); TransporteViewModel vm = new TransporteViewModel(transporte); return(View(vm)); }
public async Task <IActionResult> GetTransportes([FromRoute] int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Transporte transporte = await _repository.Get(id); Link link = await _linkRepository.Get(transporte.LinkId); transporte.Link = link; TransporteViewModel vm = new TransporteViewModel(transporte); if (transporte == null) { return(NotFound()); } return(Ok(vm)); }
// GET: Transportes/Details/5 public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } var trasnporte = await _repository.Get(id.Value); if (trasnporte == null) { return(NotFound()); } trasnporte.Link = await _linkRepository.Get(trasnporte.LinkId); TransporteViewModel vm = new TransporteViewModel(trasnporte); ViewBag.ImagemPath = vm.ImagemPath; ViewBag.Alt = "Não tem imagem associada"; return(View(vm)); }
// GET: Transportes/Delete/5 public async Task <IActionResult> Delete(int?id) { if (id == null) { return(NotFound()); } var transporte = await _repository.Get(id.Value); if (transporte == null) { return(NotFound()); } var vm = new TransporteViewModel(transporte); Link link = await _linkRepository.Get(transporte.LinkId); vm.Link = link; vm.LinkId = link.Id; return(View(vm)); }
private void UpdateList(List <TransporteViewModel> ls) { if (Config.Get <List <TransporteViewModel> >("linea-" + _linea) == null && ls.Any()) { Config.Set("linea-" + _linea, ls); } ls = ls.OrderBy(y => y.Nombre).ToList(); try { for (int index = 0; index < ls.Count; index++) { TransporteViewModel transporteViewModel = ls[index]; Color randomColor = GetRandomColor(index); var routeLine = new MapPolyline { Path = new GeoCoordinateCollection(), StrokeColor = randomColor, StrokeThickness = 5.0, }; foreach (var location in transporteViewModel.Puntos) { routeLine.Path.Add(new GeoCoordinate(location.Y, location.X)); } App.MapViewModel.AddElement(new MapReference { Nombre = transporteViewModel.Nombre, Color = new SolidColorBrush(randomColor), }, routeLine); } SuccessFunc(); } catch { Config.Remove("linea-" + _linea); ErrorFunc(); } }
public async Task <IActionResult> Create([Bind("Id,Descricao,Nome,Url")] TransporteViewModel vm, IFormFile Imagem) { Transporte transporte = new Transporte(); if (ModelState.IsValid && Imagem != null && Imagem.Length > 0 && FilesHelper.VerifyFileSize(Imagem) && FilesHelper.VerifyFileExtension(Imagem.FileName)) { var upload = Path.Combine(_env.WebRootPath, "imagens", "transportes"); // guardar imagem using (var fileStream = new FileStream(Path.Combine(upload, Imagem.FileName), FileMode.Create)) { await Imagem.CopyToAsync(fileStream); } transporte.Nome = vm.Nome; transporte.Descricao = vm.Descricao; transporte.ImagemPath = "\\imagens\\transportes\\" + Imagem.FileName; transporte.ImagemUrl = HttpContext.Request.Host.Host + "/imagens/transportes/" + Imagem.FileName; if (vm.Url == null) { vm.Url = string.Empty; } // guardar link Link link = new Link { Categoria = Categoria.Transporte, Descricao = vm.Descricao, Url = vm.Url }; await _linkRepository.Save(link); transporte.Link = link; transporte.LinkId = link.Id; await _repository.Save(transporte); return(RedirectToAction("Index")); } return(View(vm)); }
private string WriteToFile(TransporteViewModel Message) { string path = AppDomain.CurrentDomain.BaseDirectory + "\\ArchivosCompartidos"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string filepath = AppDomain.CurrentDomain.BaseDirectory + "\\ArchivosCompartidos\\touresbalon_orden_" + Message.orderId + ".csv"; if (!System.IO.File.Exists(filepath)) { var records = new object[] { Message.nombre, Message.apellido, Message.fecha_salida, Message.num_viaje, Message.num_silla, }; // Build the file content var data = new StringBuilder(); data.AppendLine(string.Join(",", records)); byte[] buffer = Encoding.ASCII.GetBytes($"{data.ToString()}"); System.IO.File.WriteAllBytes($"{filepath}", buffer); } else { using (StreamWriter sw = System.IO.File.AppendText(filepath)) { sw.WriteLine(Message); } } return(filepath); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Descricao,ImagemPath,ImagemUrl,LinkId,Nome,Url")] TransporteViewModel vm, IFormFile Imagem) { if (id != vm.Id) { return(NotFound()); } Transporte transporte = await _repository.Get(id); if (ModelState.IsValid) { try { // editar imagem if (Imagem != null && Imagem.Length > 0 && FilesHelper.VerifyFileSize(Imagem) && FilesHelper.VerifyFileExtension(Imagem.FileName)) { var upload = Path.Combine(_env.WebRootPath, "imagens", "transportes"); // guardar imagem tamanho normal using (var fileStream = new FileStream(Path.Combine(upload, Imagem.FileName), FileMode.Create)) { await Imagem.CopyToAsync(fileStream); } // apagar imagem antiga var path = _env.WebRootPath + vm.ImagemPath; if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } transporte.ImagemPath = "\\imagens\\transportes\\" + Imagem.FileName; transporte.ImagemUrl = HttpContext.Request.Host.Host + "/imagens/transportes/" + Imagem.FileName; } transporte.Nome = vm.Nome; transporte.Descricao = vm.Descricao; if (vm.Url != null) { Link link = await _linkRepository.Get(transporte.LinkId); link.Descricao = vm.Descricao; link.Url = vm.Url; await _linkRepository.Update(link); } await _repository.Update(transporte); } catch (DbUpdateConcurrencyException) { if (!TransporteExists(transporte.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } return(View(vm)); }