public ActionResult DeletePost(Visitantes visitante) { if (_unit.Visitantes.Delete(visitante)) { return(RedirectToAction("Index")); } return(PartialView(_unit.Visitantes.GetById(visitante.Id))); }
public ActionResult Create(Visitantes visitante) { if (ModelState.IsValid) { _unit.Visitantes.Insert(visitante); return(RedirectToAction("Index")); } return(PartialView("_Create", visitante)); }
public ActionResult Edit(Visitantes visitante) { if (_unit.Visitantes.Update(visitante)) { return(RedirectToAction("Index")); } return(PartialView("_Edit", visitante)); }
private void btnCheckIn_Click(object sender, EventArgs e) { bool temCarro = false; Visitante iVisitante = new Visitante(); iVisitante.Inscricao = txtInscricao.Text.Trim(); iVisitante.Nome = txtNome.Text.Trim(); Visitantes.Add(iVisitante); listarVisitantes.DataSource = null; listarVisitantes.DataSource = Visitantes; LimpaFormVisitante(); foreach (Viagem fViagem in Viagens) { if (fViagem.Passageiros.Count < fViagem.Carro.Lotacao && fViagem.Entrada < fViagem.Entrada.AddMinutes(30)) { fViagem.Passageiros.Add(iVisitante); fViagem.Carro.Lugares++; temCarro = true; if (fViagem.Carro.Lotacao == fViagem.Passageiros.Count) { fViagem.Saida = DateTime.Now; RecalcularSaidas(fViagem.Saida); } AtualizaInfo(); return; } else if (fViagem.Entrada.AddMinutes(30) < DateTime.Now) { fViagem.Saida = fViagem.Entrada.AddMinutes(30); } } if (!temCarro) { MessageBox.Show("Veículos indisponíveis", "Nenhum veículo disponível", MessageBoxButtons.OK); } }
public async Task <HttpResponseMessage> Add() { var folderName = "Content/Photos"; var CurrentTime = Helper.Now(); string json = ""; var fromAndroid = false; var PATH = HttpContext.Current.Server.MapPath("~/" + folderName); var rootUrl = Request.RequestUri.AbsoluteUri.Replace(Request.RequestUri.AbsolutePath, String.Empty); var streamProvider = new MultipartFormDataStreamProvider(PATH); if (Request.Content.IsMimeMultipartContent()) { await Request.Content.ReadAsMultipartAsync(streamProvider); var PIN = streamProvider.FormData["Pin"]; var Plate = streamProvider.FormData["Plate"]; var Cone = streamProvider.FormData["Cone"]; var IdStreet = Guid.Parse(streamProvider.FormData["IdStreet"]); var NumberHouse = streamProvider.FormData["NumberHouse"]; var IdSubject = Guid.Parse(streamProvider.FormData["IdSubject"]); var Photo = ""; Visitantes newVisitor = (from us in db.Visitantes where us.pin == PIN select us).FirstOrDefault(); Calles street = (from ca in db.Calles where ca.id_calle == IdStreet select ca).FirstOrDefault(); Asuntos subject = (from sub in db.Asuntos where sub.id_asunto == IdSubject select sub).FirstOrDefault(); Domicilios address = (from dom in db.Domicilios where dom.id_calle == IdStreet && dom.no_casa == NumberHouse select dom).FirstOrDefault(); if (newVisitor == null) { json = Helper.toJson(false, "No existe el visitante"); return(new HttpResponseMessage() { Content = new StringContent(json.ToString(), Encoding.UTF8, "application/json") }); } if (address == null) { json = Helper.toJson(false, "No existe el domicilio"); return(new HttpResponseMessage() { Content = new StringContent(json.ToString(), Encoding.UTF8, "application/json") }); } foreach (MultipartFileData fileData in streamProvider.FileData) { if (string.IsNullOrEmpty(fileData.Headers.ContentDisposition.FileName)) { return(Request.CreateResponse(HttpStatusCode.NotAcceptable, "This request is not properly formatted")); } string fileName = fileData.Headers.ContentDisposition.FileName; if (fileName.StartsWith("\"") && fileName.EndsWith("\"")) { fileName = fileName.Trim('"'); } if (fileName.Contains(@"/") || fileName.Contains(@"\")) { fileName = Path.GetFileName(fileName); } string ext = Path.GetExtension(fileName); var phototemp = Guid.NewGuid().ToString().ToUpper() + ext; var photo = Guid.NewGuid().ToString().ToUpper() + ext; var lastphoto = Guid.NewGuid().ToString().ToUpper() + ext; File.Move(fileData.LocalFileName, Path.Combine(PATH, phototemp)); string text = System.IO.File.ReadAllText(Path.Combine(PATH, phototemp)); string base64 = text.Split(',')[1]; if (Helper.IsBase64(base64)) { fromAndroid = true; byte[] bytes = Convert.FromBase64String(base64); using (Image image = Image.FromStream(new MemoryStream(bytes))) { image.Save(Path.Combine(PATH, photo), ImageFormat.Jpeg); // Or Png } } else { File.Move(fileData.LocalFileName, Path.Combine(PATH, photo)); } // First load the image somehow Image myImage = Image.FromFile(Path.Combine(PATH, photo), true); if (myImage.Width < myImage.Height) { Helper.RotateAndSaveImage(Path.Combine(PATH, photo), Path.Combine(PATH, lastphoto)); } else { myImage.Save(Path.Combine(PATH, lastphoto), System.Drawing.Imaging.ImageFormat.Jpeg); } // Save the image with a quality of 50% myImage.Dispose(); Image LastImage = Image.FromFile(Path.Combine(PATH, lastphoto), true); Helper.SaveJpeg(Path.Combine(PATH, "min" + lastphoto), LastImage, 40); LastImage.Dispose(); if (File.Exists(Path.Combine(PATH, phototemp))) { File.Delete(Path.Combine(PATH, phototemp)); } if (File.Exists(Path.Combine(PATH, photo))) { File.Delete(Path.Combine(PATH, photo)); } Photo = lastphoto; } try { Accesos acceso = new Accesos(); acceso.id_acceso = Guid.NewGuid(); acceso.id_visitante = newVisitor.id_visitante; acceso.id_asunto = IdSubject; acceso.id_domicilio = address.id_domicilio; acceso.fecha = Helper.Now(); acceso.placa = Plate == "undefined" ? "" : Plate; acceso.cono = Cone == "undefined" ? "" : Cone; acceso.identificacion = Photo; db.Accesos.Add(acceso); db.SaveChanges(); if (fromAndroid) { json = Helper.toJson(true, "Acceso Grabado"); } else { json = Helper.toJson(true, "Acceso Grabado"); } return(new HttpResponseMessage() { Content = new StringContent(json.ToString(), Encoding.UTF8, "application/json") }); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { //Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",ve.PropertyName, ve.ErrorMessage); EventLog eventLog = new EventLog("Application"); eventLog.Source = "BonaterraSite"; eventLog.WriteEntry("- Property: " + ve.PropertyName + ", Error: " + ve.ErrorMessage, EventLogEntryType.Information, 101, 1); } json = Helper.toJson(false, "No se pudo guardar el acceso"); return(new HttpResponseMessage() { Content = new StringContent(json.ToString(), Encoding.UTF8, "application/json") }); } throw; } } json = Helper.toJson(false, "Error"); return(new HttpResponseMessage() { Content = new StringContent(json.ToString(), Encoding.UTF8, "application/json") }); }
public async Task <HttpResponseMessage> UpdateAsync() { var folderName = "Content/Photos"; var CurrentTime = Helper.Now(); string json = ""; var PATH = HttpContext.Current.Server.MapPath("~/" + folderName); var rootUrl = Request.RequestUri.AbsoluteUri.Replace(Request.RequestUri.AbsolutePath, String.Empty); var streamProvider = new MultipartFormDataStreamProvider(PATH); if (Request.Content.IsMimeMultipartContent()) { await Request.Content.ReadAsMultipartAsync(streamProvider); var Id = Guid.Parse(streamProvider.FormData["Id"]); var Name = streamProvider.FormData["Name"]; var MidleName = streamProvider.FormData["MidleName"]; var LastName = streamProvider.FormData["LastName"]; var BirthDay = streamProvider.FormData["BirthDay"]; var Checked = streamProvider.FormData["Verificado"]; var Photo = streamProvider.FormData["Photo"]; Visitantes newVisitor = db.Visitantes.FirstOrDefault(s => s.id_visitante == Id); foreach (MultipartFileData fileData in streamProvider.FileData) { if (string.IsNullOrEmpty(fileData.Headers.ContentDisposition.FileName)) { return(Request.CreateResponse(HttpStatusCode.NotAcceptable, "This request is not properly formatted")); } string fileName = fileData.Headers.ContentDisposition.FileName; if (fileName.StartsWith("\"") && fileName.EndsWith("\"")) { fileName = fileName.Trim('"'); } if (fileName.Contains(@"/") || fileName.Contains(@"\")) { fileName = Path.GetFileName(fileName); } string ext = Path.GetExtension(fileName); var phototemp = Guid.NewGuid().ToString().ToUpper() + ext; File.Move(fileData.LocalFileName, Path.Combine(PATH, phototemp)); if (File.Exists(Path.Combine(PATH, newVisitor.foto))) { File.Delete(Path.Combine(PATH, newVisitor.foto)); } if (File.Exists(Path.Combine(PATH, "min" + newVisitor.foto))) { File.Delete(Path.Combine(PATH, "min" + newVisitor.foto)); } Photo = phototemp; Image LastImage = Image.FromFile(Path.Combine(PATH, phototemp), true); Helper.SaveJpeg(Path.Combine(PATH, "min" + phototemp), LastImage, 40); LastImage.Dispose(); } try { newVisitor.nombre = Name; newVisitor.apellido1 = MidleName; newVisitor.apellido2 = LastName; bool aux; if (Boolean.TryParse(Checked, out aux)) { newVisitor.verificado = Boolean.Parse(Checked); VerificacionVisitantes very = new VerificacionVisitantes(); very.IdVerificacion = Guid.NewGuid(); var CurrentUser = (IdentityPersonalizado)User.Identity; very.IdUsuario = CurrentUser.Id; very.IdVisitante = newVisitor.id_visitante; very.Fecha = Helper.Now(); db.VerificacionVisitantes.Add(very); } newVisitor.nacimiento = DateTime.ParseExact(BirthDay, @"d/M/yyyy", System.Globalization.CultureInfo.InvariantCulture); newVisitor.foto = Photo == null ? newVisitor.foto: Photo; db.SaveChanges(); json = Helper.toJson(true, "Visitante Actualizado"); return(new HttpResponseMessage() { Content = new StringContent(json.ToString(), Encoding.UTF8, "application/json") }); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } json = Helper.toJson(false, "No se pudo actualizar visitante"); return(new HttpResponseMessage() { Content = new StringContent(json.ToString(), Encoding.UTF8, "application/json") }); } throw; } } json = Helper.toJson(false, "Error"); return(new HttpResponseMessage() { Content = new StringContent(json.ToString(), Encoding.UTF8, "application/json") }); }
public async Task <HttpResponseMessage> Add() { var folderName = "Content/Photos"; var CurrentTime = Helper.Now(); string json = ""; var fromAndroid = false; var PATH = HttpContext.Current.Server.MapPath("~/" + folderName); var rootUrl = Request.RequestUri.AbsoluteUri.Replace(Request.RequestUri.AbsolutePath, String.Empty); var streamProvider = new MultipartFormDataStreamProvider(PATH); if (Request.Content.IsMimeMultipartContent()) { await Request.Content.ReadAsMultipartAsync(streamProvider); var Name = streamProvider.FormData["Name"]; var MidleName = streamProvider.FormData["MidleName"]; var LastName = streamProvider.FormData["LastName"]; var BirthDay = streamProvider.FormData["BirthDay"]; var Photo = streamProvider.FormData["Photo"]; Visitantes newVisitor = new Visitantes(); foreach (MultipartFileData fileData in streamProvider.FileData) { if (string.IsNullOrEmpty(fileData.Headers.ContentDisposition.FileName)) { return(Request.CreateResponse(HttpStatusCode.NotAcceptable, "This request is not properly formatted")); } string fileName = fileData.Headers.ContentDisposition.FileName; if (fileName.StartsWith("\"") && fileName.EndsWith("\"")) { fileName = fileName.Trim('"'); } if (fileName.Contains(@"/") || fileName.Contains(@"\")) { fileName = Path.GetFileName(fileName); } string ext = Path.GetExtension(fileName); var phototemp = Guid.NewGuid().ToString().ToUpper() + ext; var photo = Guid.NewGuid().ToString().ToUpper() + ext; var lastphoto = Guid.NewGuid().ToString().ToUpper() + ext; File.Move(fileData.LocalFileName, Path.Combine(PATH, phototemp)); string text = System.IO.File.ReadAllText(Path.Combine(PATH, phototemp)); string base64temp = text.Split(',')[0]; string base64 = text.Split(',')[1]; if (base64temp == "data:image/jpeg;base64") { fromAndroid = true; byte[] bytes = Convert.FromBase64String(base64); using (Image image = Image.FromStream(new MemoryStream(bytes))) { image.Save(Path.Combine(PATH, photo), ImageFormat.Jpeg); // } } else { File.Move(Path.Combine(PATH, phototemp), Path.Combine(PATH, photo)); } // First load the image somehow Image myImage = Image.FromFile(Path.Combine(PATH, photo), true); if (myImage.Width < myImage.Height) { Helper.RotateAndSaveImage(Path.Combine(PATH, photo), Path.Combine(PATH, lastphoto)); } else { myImage.Save(Path.Combine(PATH, lastphoto), ImageFormat.Jpeg); } // Save the image with a quality of 50% myImage.Dispose(); /* * Image LastImage = Image.FromFile(Path.Combine(PATH, lastphoto), true); * Helper.SaveJpeg(Path.Combine(PATH, "min" + lastphoto), LastImage, 40); * LastImage.Dispose(); */ Image imageX = Image.FromFile(Path.Combine(PATH, lastphoto), true); Image thumb = imageX.GetThumbnailImage(300, 180, () => false, IntPtr.Zero); thumb.Save(Path.Combine(PATH, "min" + lastphoto)); thumb.Dispose(); if (File.Exists(Path.Combine(PATH, phototemp))) { File.Delete(Path.Combine(PATH, phototemp)); } if (File.Exists(Path.Combine(PATH, photo))) { File.Delete(Path.Combine(PATH, photo)); } Photo = lastphoto; } try { var pins = (from vis in db.Visitantes select vis.pin).ToArray(); newVisitor.pin = Helper.GetPIN(pins); newVisitor.id_visitante = Guid.Parse(Guid.NewGuid().ToString().ToUpper()); newVisitor.nombre = Name; newVisitor.apellido1 = MidleName; newVisitor.apellido2 = LastName; newVisitor.nacimiento = DateTime.ParseExact(BirthDay, @"d/M/yyyy", System.Globalization.CultureInfo.InvariantCulture); Photo = Photo == "undefined" ? "" : Photo; newVisitor.foto = Photo == null ? "xxx" : Photo; db.Visitantes.Add(newVisitor); db.SaveChanges(); if (fromAndroid) { json = Helper.toJson(true, newVisitor.pin); } else { json = Helper.toJson(true, "Visitante Agregado"); } return(new HttpResponseMessage() { Content = new StringContent(json.ToString(), Encoding.UTF8, "application/json") }); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { //Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",ve.PropertyName, ve.ErrorMessage); EventLog eventLog = new EventLog("Application"); eventLog.Source = "BonaterraSite"; eventLog.WriteEntry("- Property: " + ve.PropertyName + ", Error: " + ve.ErrorMessage, EventLogEntryType.Information, 101, 1); } json = Helper.toJson(false, "No se pudo agregar visitante"); return(new HttpResponseMessage() { Content = new StringContent(json.ToString(), Encoding.UTF8, "application/json") }); } throw; } } json = Helper.toJson(false, "Error"); return(new HttpResponseMessage() { Content = new StringContent(json.ToString(), Encoding.UTF8, "application/json") }); }
public JsonResult GuardarPersonas(FormCollection f) { string activo = f["activo"]; Thread.CurrentThread.CurrentCulture = new CultureInfo("es-CR"); TimeZoneInfo setTimeZoneInfo; DateTime currentDateTime; //Set the time zone information to US Mountain Standard Time setTimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Central America Standard Time"); //Get date and time in US Mountain Standard Time currentDateTime = TimeZoneInfo.ConvertTime(DateTime.Now, setTimeZoneInfo); //Print out the date and time DateTime hora = currentDateTime; int x = 1; eResultado Resultado = new eResultado(); int id = Convert.ToInt32(f["departamento"]); try { using (DB_A1E868_ingresoCTPEntities bd = new DB_A1E868_ingresoCTPEntities()) { //NUEVO Visitantes Personas = new Visitantes(); { Personas.cedula = f["cedula"]; Personas.placa = f["placa"]; Personas.nombre = f["nombre"]; Personas.apellidos = f["apellidos"]; Personas.id_departamento = id; Personas.fecha_ingreso = hora; } bd.Visitantes.Add(Personas); //if (activo == "0") //{ // TSE personasActivas = new TSE(); // { // personasActivas.Nombre = f["nombre"]; // personasActivas.Apellido1 = f["apellidos"]; // personasActivas.Cedula = f["cedula"]; // } // bd.TSE.Add(personasActivas); //} bd.SaveChanges(); } x = 1; Resultado.Estado = true; } catch (Exception ex) { x = 2; Resultado.Estado = false; Resultado.TipoMensaje = 3; } return(Json(x, JsonRequestBehavior.AllowGet)); }