public IHttpActionResult AddGallery([FromUri] GalleryViewModel model) { string foldercrate = HttpContext.Current.Server.MapPath("~/images/"); if (!Directory.Exists(foldercrate)) { Directory.CreateDirectory(foldercrate); } if (HttpContext.Current.Request.Files.AllKeys.Any()) { var fileupload = HttpContext.Current.Request.Files["Imgpathsave"]; if (fileupload != null) { var saveimages = Path.Combine(HttpContext.Current.Server.MapPath("~/images/"), fileupload.FileName); fileupload.SaveAs(saveimages); cursomvcapiEntities cm = new cursomvcapiEntities(); cm.Storage.Add(new Storage { foto = saveimages.ToString(), foto_name = fileupload.FileName.ToString(), id_identificador = model.id }); cm.SaveChanges(); } } return(Ok()); }
public Reply ListarFacturas([FromBody] SecurityViewModel model) { Reply oR = new Reply(); oR.result = 0; if (!Verify(model.token)) { oR.mensaje = "no esta autorizado"; oR.result = 0; return(oR); } try { using (cursomvcapiEntities db = new cursomvcapiEntities()) { List <ListFacturaViewModel> lstFact = (from d in db.facturas select new ListFacturaViewModel { Id = d.id, NumFactura = d.numfactura, Monto = (decimal)d.monto, Fecha = (DateTime)d.fecha }).ToList(); oR.data = lstFact; oR.result = 1; } } catch (Exception ex) { oR.mensaje = "No se pueden listar las faturass"; } return(oR); }
public Reply GetGallery([FromUri] GalleryViewModel model) { Reply oR = new Reply(); oR.result = 0; try { using (cursomvcapiEntities db = new cursomvcapiEntities()) { List <ListGalleryViewModel> lst = (from a in db.Storage where a.id_identificador == model.id select new ListGalleryViewModel { id = a.id_galeria, foto = a.foto, name = a.foto_name }).ToList(); oR.data = lst; oR.result = 1; } } catch (Exception exp) { oR.message = "ocurrio un error en el servidor"; } return(oR); }
public Reply ADMusers([FromBody] AccessViewModel model) { Reply oR = new Reply(); oR.result = 0; if (!Verify(model.token)) { oR.message = "no autorizado"; return(oR); } try { using (cursomvcapiEntities db = new cursomvcapiEntities()) { List <ListAdminUserViewModel> lst = List(db); oR.data = lst; oR.result = 1; oR.message = "listado de Referentes panel admin"; } } catch (Exception exp) { oR.message = "ocurrio un error en el servidor"; } return(oR); }
public Reply IsAdmin([FromUri] string token) { Reply oR = new Reply(); oR.result = 0; using (cursomvcapiEntities db = new cursomvcapiEntities()) { var lst = from a in db.User where a.token.Contains(token) where a.rol == 2 select a; if (lst.Count() > 0) { oR.data = true; oR.message = "Administrador Master"; } else { oR.data = false; oR.message = "Acceso Restringido"; } } return(oR); }
public Reply Logout([FromBody] AccessViewModel model) { Reply oR = new Reply(); oR.result = 0; try { using (cursomvcapiEntities db = new cursomvcapiEntities()) { var lst = from a in db.User where a.token.Contains(model.token) select a; if (lst.Count() > 0) { User oUser = lst.First(); oUser.token = null; db.Entry(oUser).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); oR.result = 1; oR.message = "sesion cerrada con exito"; } else { oR.message = "Datos erroneos"; } } } catch (Exception ex) { oR.message = "a ocurrido un error"; } return(oR); }
public Reply ListarAnimales([FromBody] SecurityViewModel model) { Reply oR = new Reply(); oR.result = 0; //Verificamos el token if (!Verify(model.token)) { oR.mensaje = "no esta autorizado"; oR.result = 0; return(oR); } try { using (cursomvcapiEntities db = new cursomvcapiEntities()) { List <ListAnimalViewModel> lst = (from d in db.animal where d.idState == 1 select new ListAnimalViewModel { Nombre = d.name, Patas = d.patas }).ToList(); oR.data = lst; oR.result = 1; } } catch (Exception ex) { oR.mensaje = "Error en el servidor "; } return(oR); }
public Reply Login([FromBody] AccessViewModel model) { Reply oR = new Reply(); oR.result = 0; try { using (cursomvcapiEntities db = new cursomvcapiEntities()) { var lst = db.User.Where(d => d.email == model.email && d.password == model.password); if (lst.Count() > 0) { oR.result = 1; oR.data = Guid.NewGuid().ToString(); User oUser = lst.First(); oUser.token = (string)oR.data; db.Entry(oUser).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } else { oR.message = "Datos erroneos"; } } } catch (Exception ex) { oR.message = "a ocurrido un error"; } return(oR); }
public IHttpActionResult AddImg([FromUri] GalleryViewModel model) { string foldercrate = HttpContext.Current.Server.MapPath("~/images/"); if (!Directory.Exists(foldercrate)) { Directory.CreateDirectory(foldercrate); } if (HttpContext.Current.Request.Files.AllKeys.Any()) { var fileupload = HttpContext.Current.Request.Files["Imgpathsave"]; if (fileupload != null) { var saveimages = Path.Combine(HttpContext.Current.Server.MapPath("~/images/"), fileupload.FileName); fileupload.SaveAs(saveimages); cursomvcapiEntities cm = new cursomvcapiEntities(); var query = (from a in cm.Contenido where a.id == model.id select a).FirstOrDefault(); query.picture = saveimages.ToString(); query.name_picture = fileupload.FileName.ToString(); cm.SaveChanges(); } } return(Ok()); }
public bool Verify(string token) { using (cursomvcapiEntities db = new cursomvcapiEntities()) { if (db.user.Where(d => d.token == token && d.idEstatus == 1).Count() > 0) { return(true); } } return(false); }
private List <ListGalleryViewModel> Lista(cursomvcapiEntities db) { List <ListGalleryViewModel> lst = (from a in db.Storage select new ListGalleryViewModel { id = a.id_galeria, foto = a.foto }).ToList(); return(lst); }
private List <ListAnimalViewModel> List(cursomvcapiEntities db) { List <ListAnimalViewModel> lst = (from d in db.animal where d.idState == 1 select new ListAnimalViewModel { Nombre = d.name, Patas = d.patas }).ToList(); return(lst); }
public bool Verify(string token) { using (cursomvcapiEntities db = new cursomvcapiEntities()) { if (db.User.Where(d => d.token == token).Count() > 0) { return(true); } else { return(false); } } }
public Reply Eliminar([FromBody] DeleteViewAccesModel model) { Reply oR = new Reply(); oR.result = 0; if (!Verify(model.token)) { oR.message = "no autorizado"; return(oR); } try { using (cursomvcapiEntities db = new cursomvcapiEntities()) { var lst = from a in db.User where a.token.Contains(model.token) where a.rol == 1 select a; if (lst.Count() > 0) { var delete = (from a in db.User where a.id == model.id select a).FirstOrDefault(); db.User.Remove(delete); db.SaveChanges(); oR.result = 1; oR.message = "usuario eliminado"; string nombre = delete.foto.ToString(); var fullPath = System.Web.Hosting.HostingEnvironment.MapPath("~/referentes/" + nombre); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } } else { oR.result = 0; oR.message = "no tienes el permiso para eliminar personas"; } } } catch (Exception ex) { oR.message = "a ocurrido un error"; } return(oR); }
//muestra la lista publica de referentes private List <ListAdminUserViewModel> Lista(cursomvcapiEntities db) { List <ListAdminUserViewModel> lst = (from d in db.User select new ListAdminUserViewModel { nombre = d.nombre, apellido = d.apellido, ubicacion = d.ubicacion, email = d.email, foto = d.foto, name = d.name_foto }).ToList(); return(lst); }
public Reply Add([FromBody] AnimalViewModel model) { Reply oR = new Reply(); oR.result = 0; if (!Verify(model.token)) { oR.message = "no autorizado"; return(oR); } //validaciones if (!Validate(model)) { oR.message = error; return(oR); } try { using (cursomvcapiEntities db = new cursomvcapiEntities()) { Contenido oContent = new Contenido(); oContent.titulo = model.titulo; oContent.subtitulo = model.subtitulo; oContent.detalle = model.detalle; oContent.categoria = model.categoria; oContent.tags = model.tags; oContent.picture = null; db.Contenido.Add(oContent); db.SaveChanges(); //List<ListAnimalsViewModels> lst = List(db); oR.result = 1; oR.data = oContent.id; oR.message = "contenido cargado"; } } catch (Exception exp) { oR.message = "ocurrio un error en el servidor"; } return(oR); }
public Reply Edit([FromBody] AnimalViewModel model) { Reply oR = new Reply(); oR.result = 0; if (!Verify(model.token)) { oR.message = "No Autorizado"; return(oR); } //Validaciones if (!Validate(model)) { oR.message = error; return(oR); } try { using (cursomvcapiEntities db = new cursomvcapiEntities()) { animal oAnimal = db.animal.Find(model.Id); oAnimal.idState = 1; oAnimal.name = model.Name; oAnimal.patas = model.Patas; db.Entry(oAnimal).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); List <LstAnimalesViewModel> lst = List(db); oR.data = lst; oR.result = 1; } } catch (Exception ex) { oR.message = "Ocurrio un error en el servidor, intentelo mas tarde"; } return(oR); }
public Reply Add([FromBody] AnimalViewModel model) { Reply oR = new Reply(); oR.result = 0; //Verificamos el token if (!Verify(model.token)) { oR.mensaje = "no esta autorizado"; oR.result = 0; return(oR); } //Validaciones if (!Validate(model)) { oR.mensaje = error; return(oR); } try { using (cursomvcapiEntities db = new cursomvcapiEntities()) { animal oAnimal = new animal(); oAnimal.idState = 1; oAnimal.name = model.Nombre; oAnimal.patas = model.Patas; db.animal.Add(oAnimal); db.SaveChanges(); // retorno la lista de animales con el nuevo agregadoo // retorno la lista de animales con el nuevo agregadoo List <ListAnimalViewModel> lst = List(db); oR.data = lst; oR.result = 1; } } catch (Exception ex) { oR.mensaje = "HA ocurrido un error"; } return(oR); }
public Reply Edit([FromBody] AnimalViewModel model) { Reply oR = new Reply(); oR.result = 0; if (!Verify(model.token)) { oR.message = "no autorizado"; return(oR); } try { using (cursomvcapiEntities db = new cursomvcapiEntities()) { Contenido oContent = db.Contenido.Find(model.id); oContent.titulo = model.titulo; oContent.subtitulo = model.subtitulo; oContent.detalle = model.detalle; oContent.categoria = model.categoria; oContent.tags = model.tags; db.Entry(oContent).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); List <ListAnimalsViewModels> lst = List(db); oR.result = 1; oR.data = lst; oR.message = "Contenido modificado"; } } catch (Exception exp) { oR.message = "ocurrio un error en el servidor"; } return(oR); }
public Reply DeleteFromGallery([FromUri] GalleryViewModel model) { Reply oR = new Reply(); oR.result = 0; try { using (cursomvcapiEntities db = new cursomvcapiEntities()) { var delete = (from a in db.Storage where a.id_galeria == model.id select a).FirstOrDefault(); db.Storage.Remove(delete); db.SaveChanges(); string nombre = delete.foto_name.ToString(); var fullPath = System.Web.Hosting.HostingEnvironment.MapPath("~/images/" + nombre); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } List <ListGalleryViewModel> lst = Lista(db); oR.result = 1; oR.data = lst; oR.message = "Imagen eliminada con exito"; } } catch (Exception) { oR.message = "ocurrio un error en el servidor"; } return(oR); }
public Reply GetAll() { Reply oR = new Reply(); oR.result = 0; try { using (cursomvcapiEntities db = new cursomvcapiEntities()) { List <ListAnimalsViewModels> lst = List(db); oR.data = lst; oR.result = 1; } } catch (Exception exp) { oR.message = "ocurrio un error en el servidor"; } return(oR); }
public Reply Show([FromBody] DetalleFacturaViewModel model) { Reply oResp = new Reply(); oResp.result = 0; if (!Verify(model.token)) { oResp.mensaje = "no esta autorizado"; return(oResp); } try { using (cursomvcapiEntities db = new cursomvcapiEntities()) { List <DetalleFacturaViewModel> oDetalle = (from d in db.detallefactura where d.numfactura == model.NumFactura select new DetalleFacturaViewModel { Id = d.id, NumFactura = d.numfactura, CodArticulo = d.codarticulo, Cantidad = d.cantidad, PrecioUnitario = d.preciounitario, Total = d.total }).ToList(); oResp.data = oDetalle; oResp.result = 1; } } catch (Exception ex) { oResp.mensaje = "problemas en el show"; } return(oResp); }
public Reply GetReferentes() { Reply oR = new Reply(); oR.result = 0; try { using (cursomvcapiEntities db = new cursomvcapiEntities()) { List <ListAdminUserViewModel> lst = Lista(db); oR.data = lst; oR.result = 1; oR.message = "listado de Referentes Publico"; } } catch (Exception exp) { oR.message = "ocurrio un error en el servidor"; } return(oR); }
public Reply Delete([FromBody] AnimalViewModel model) { Reply oR = new Reply(); oR.result = 0; //Verificamos el token if (!Verify(model.token)) { oR.mensaje = "no esta autorizado"; oR.result = 0; return(oR); } try { using (cursomvcapiEntities db = new cursomvcapiEntities()) { animal oAnimal = db.animal.Find(model.Id); oAnimal.idState = 2; db.Entry(oAnimal).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); // retorno la lista de animales con el nuevo agregadoo List <ListAnimalViewModel> lst = List(db); oR.data = lst; oR.result = 1; } } catch (Exception ex) { oR.mensaje = "HA ocurrido un error"; } return(oR); }
public Reply Login(AccessViewModel model) { Reply Or = new Reply(); Or.result = 0; try { //Contexto, Todo lo que esta creado aqui se destruye aqui (Es un ambito, universo) using (cursomvcapiEntities db = new cursomvcapiEntities()) { var lst = db.user.Where(d => d.email == model.email && d.password == model.password && d.idEstatus == 1); if (lst.Count() > 0) { Or.result = 1; //Crear y enviar el toque 32 caracteres no se repiten Or.data = Guid.NewGuid().ToString(); user oUser = lst.First(); oUser.token = (string)Or.data; db.Entry(oUser).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } else { Or.message = "Datos Incorrectos"; } } } catch (Exception ex) { Or.message = "Ocurrio un error, estamos corrigiendo"; } return(Or); }
public Reply GetByid([FromUri] int id) { Reply oR = new Reply(); oR.result = 0; try { using (cursomvcapiEntities db = new cursomvcapiEntities()) { List <ListAnimalsViewModels> lst = (from a in db.Contenido where a.id == id select new ListAnimalsViewModels { id = a.id, titulo = a.titulo, subtitulo = a.subtitulo, detalle = a.detalle, categoria = a.categoria, tags = a.tags, picture = a.picture, name_foto = a.name_picture }).ToList(); oR.data = lst; oR.result = 1; } } catch (Exception exp) { oR.message = "ocurrio un error en el servidor"; } return(oR); }
public Reply Get(SecurityViewModel model) { Reply oR = new Reply(); oR.result = 0; try { using (cursomvcapiEntities db = new cursomvcapiEntities()) { List <LstAnimalesViewModel> lst = List(db); oR.data = lst; oR.result = 1; } }catch (Exception ex) { oR.message = "Ocurrio un error en el servidor, intentelo mas tarde"; } return(oR); }
private List <ListAnimalsViewModels> List(cursomvcapiEntities db) { List <ListAnimalsViewModels> lst = (from d in db.Contenido select new ListAnimalsViewModels { id = d.id, titulo = d.titulo, subtitulo = d.subtitulo, detalle = d.detalle, categoria = d.categoria, tags = d.tags, picture = d.picture, name_foto = d.name_picture }).ToList(); //List<ListAnimalsViewModels> lst = (from a in db.Contenido // join c in db.StorageImg // on a.id equals c.id_identificador // select new ListAnimalsViewModels // { // id = a.id, // titulo = a.titulo, // subtitulo = a.subtitulo, // detalle = a.detalle, // categoria = a.categoria, // tags = a.tags, // picture = a.picture, // foto = c.foto // }).ToList(); return(lst); }
public Reply Register([FromBody] AccesNewUserModel model) { Reply oR = new Reply(); oR.result = 0; if (!Verify(model.token)) { oR.message = "no autorizado"; return(oR); } //validaciones if (!Validate(model)) { oR.message = error; return(oR); } try { using (cursomvcapiEntities db = new cursomvcapiEntities()) { var lst = from a in db.User where a.token.Contains(model.token) where a.rol == 1 select a; if (lst.Count() > 0) { //valida que el Email no este ya registrado var customer = db.User.FirstOrDefault(x => x.email == model.email); if (customer == null) { User NewUser = new User(); NewUser.nombre = model.nombre; NewUser.apellido = model.apellido; NewUser.ubicacion = model.ubicacion; NewUser.email = model.email; NewUser.password = model.password; NewUser.foto = null; NewUser.rol = 2; db.User.Add(NewUser); db.SaveChanges(); oR.result = 1; oR.data = NewUser.id; oR.message = "usuario registrado"; //body en Html para los correo de Registro string HtmlString = string.Format(@" <html> <body> <div> <img src ='https://images.pexels.com/photos/34950/pexels-photo.jpg?auto=compress&cs=tinysrgb&dpr=1&w=500' alt ='#'> <h2> Bienvenido {0} </h2> <br><br> <h4> ahora formas parte del Grupo de Referentes de <strong> Educacion Ambiental Chaco </strong> </h4> <p> ahora podes ingresar con tus datos en la plataforma digial <br> <br> cuenta de Usuario: <strong> {1} </strong> <br><br> contraseña: <strong> {2} </strong> </p> </div> </body> </html> ", model.nombre.ToString(), model.email.ToString(), model.password.ToString()); SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); MailMessage mail = new MailMessage(); mail.From = new MailAddress("*****@*****.**"); mail.To.Add(model.email.ToString()); mail.Subject = "Bienvenido Nuevo Referente Ambiental"; mail.Body = HtmlString; SmtpServer.Port = 587; SmtpServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "informatorio"); mail.IsBodyHtml = true; mail.Priority = MailPriority.Normal; SmtpServer.EnableSsl = true; SmtpServer.Send(mail); mail.Dispose(); } else { oR.result = 0; oR.message = "el Email ya ha sido Registrado"; } } else { oR.result = 0; oR.message = "no tienes el permiso para registrar personas"; } } } catch (Exception ex) { oR.message = "a ocurrido un error"; } return(oR); }
public Reply Delete([FromBody] GalleryViewModel model) { Reply oR = new Reply(); oR.result = 0; if (!Verify(model.token)) { oR.message = "no autorizado"; return(oR); } try { using (cursomvcapiEntities db = new cursomvcapiEntities()) { var delete = (from a in db.Contenido where a.id == model.id select a).FirstOrDefault(); db.Contenido.Remove(delete); db.SaveChanges(); string nombre2 = delete.name_picture.ToString(); var fullPath2 = System.Web.Hosting.HostingEnvironment.MapPath("~/images/" + nombre2); if (System.IO.File.Exists(fullPath2)) { System.IO.File.Delete(fullPath2); } /* * Animal oAnimal = db.Animal.Find(model.id); * oAnimal.titulo = model.titulo; * oAnimal.subtitulo = model.subtitulo; * oAnimal.detalle = model.detalle; * oAnimal.categoria = model.categoria; * oAnimal.tags = model.tags; * * db.Entry(oAnimal).State = System.Data.Entity.EntityState.Modified; * db.SaveChanges(); */ var deleteg = (from a in db.Storage where a.id_identificador == model.id select a).Take(10).ToList(); foreach (var item in deleteg) { db.Storage.Remove(item); db.SaveChanges(); string nombre = item.foto_name.ToString(); var fullPath = System.Web.Hosting.HostingEnvironment.MapPath("~/images/" + nombre); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } } List <ListAnimalsViewModels> lst = List(db); oR.result = 1; oR.data = lst; oR.message = "eliminado con exito"; } } catch (Exception exp) { oR.message = "ocurrio un error en el servidor"; } return(oR); }