Example #1
0
        public IHttpActionResult Put([FromBody] Detalle datos)
        {
            IHttpActionResult _result = null;
            Detalle           _datos;

            try
            {
                using (DatosContext ctx = new DatosContext())
                {
                    _datos = ctx.Detalles.Where(d => d.id == datos.id).FirstOrDefault();
                    if (datos != null)
                    {
                        _datos.corta    = datos.corta;
                        _datos.larga    = datos.larga;
                        _datos.largo    = datos.largo;
                        _datos.ancho    = datos.ancho;
                        _datos.ventanas = datos.ventanas;
                    }
                    _result = Ok(ctx.SaveChanges());
                }
            }
            catch (Exception ex)
            {
            }
            return(_result);
        }
Example #2
0
        public IHttpActionResult del(Guid token, int userid, int pidFoto, int pidDetalle, string pfoto)
        {
            IHttpActionResult _result = null;
            Foto foto;

            _result = Ok();
            if (validate(token.ToString(), userid))
            {
                using (DatosContext ctx = new DatosContext())
                {
                    foto = ctx.Fotos.Where(f => f.id == pidFoto).FirstOrDefault();
                    if (foto != null)
                    {
                        var filePath = System.Web.HttpContext.Current.Server.MapPath($"~/Uploads/{userid}/{pidDetalle}");
                        if (System.IO.File.Exists(System.IO.Path.Combine(filePath, pfoto)))
                        {
                            System.IO.File.Delete(System.IO.Path.Combine(filePath, pfoto));
                        }
                        ctx.Fotos.Remove(foto);
                        _result = Ok(ctx.SaveChanges());
                    }
                }
            }
            return(_result);
        }
Example #3
0
        public string Post()
        {
            //IHttpActionResult _result = null;
            string _result     = string.Empty;
            Foto   _dataResult = new Foto();
            var    req         = Request;
            var    headers     = req.Headers;
            int    userid      = int.Parse(headers.GetValues("userid").FirstOrDefault());
            int    iddetalle   = int.Parse(headers.GetValues("iddetalle").FirstOrDefault());

            if (validate(headers.GetValues("token").FirstOrDefault(), userid))
            {
                try
                {
                    var httpRequest = System.Web.HttpContext.Current.Request;
                    if (httpRequest.Files.Count > 0)
                    {
                        var docfiles = new List <string>();
                        foreach (string file in httpRequest.Files)
                        {
                            var postedFile = httpRequest.Files[file];

                            var filePath = System.Web.HttpContext.Current.Server.MapPath($"~/Uploads/{userid}/{iddetalle}");
                            if (!System.IO.Directory.Exists(filePath))
                            {
                                System.IO.Directory.CreateDirectory(filePath);
                            }
                            postedFile.SaveAs(System.IO.Path.Combine(filePath, postedFile.FileName));
                            docfiles.Add(System.IO.Path.Combine(filePath, postedFile.FileName));
                            using (DatosContext ctx = new DatosContext())
                            {
                                _dataResult           = new Foto();
                                _dataResult.iddetalle = iddetalle;
                                _dataResult.foto      = headers.GetValues("filename").FirstOrDefault();
                                _dataResult           = ctx.Fotos.Add(_dataResult);
                                ctx.SaveChanges();
                                _result = Ok(_dataResult).ToString();
                            }
                        }
                        _result = Ok(Request.CreateResponse(HttpStatusCode.Created, docfiles)).ToString();
                    }
                    else
                    {
                        _result = Ok(Request.CreateResponse(HttpStatusCode.BadRequest)).ToString();
                    }
                }
                catch (Exception ex)
                {
                    tracklogging(userid.ToString(), ex.Message);
                    _result = Ok(Request.CreateResponse(ex.Message)).ToString();
                }
            }
            return(_result);
        }
Example #4
0
        public List <pesso> insert(string id, string voltage, string temperature)
        {
            IQueryable <pesso> query = db.pesso.Take(1);

            if (db.pesso.Any())
            {
                DateTime date1 = DateTime.Now;

                db.pesso.Add(new pesso {
                    Id = 0, Name = id, voltage = voltage, lastUpdated = date1, temperature = temperature
                });

                db.SaveChanges();
            }
            return(query.ToList());
        }
Example #5
0
 public void tracklogging(string userid, string message)
 {
     try
     {
         using (DatosContext ctx = new DatosContext())
         {
             Models.Logtrack _log = new Models.Logtrack();
             _log.Message = message;
             _log.Moment  = DateTime.Now;
             ctx.Logtracks.Add(_log);
             ctx.SaveChanges();
         }
     }
     catch (Exception ex)
     {
     }
 }
Example #6
0
        public IHttpActionResult Post([FromBody] Detalle datos)
        {
            IHttpActionResult _result = null;

            try
            {
                using (DatosContext ctx = new DatosContext())
                {
                    var _dataResult = ctx.Detalles.Add(datos);
                    ctx.SaveChanges();
                    _result = Ok(_dataResult);
                }
            }
            catch (Exception ex)
            {
            }
            return(_result);
        }
Example #7
0
        public IHttpActionResult Post([FromBody] User datos)
        {
            IHttpActionResult _result = null;
            User _userResult          = new User();

            try
            {
                using (DatosContext ctx = new DatosContext())
                {
                    _userResult = ctx.Users.Add(datos);
                    ctx.SaveChanges();
                    _result = Ok(_userResult);
                }
            }
            catch (Exception ex)
            {
            }
            return(_result);
        }
Example #8
0
        public IHttpActionResult put([FromBody] Foto datos, string token, int userid)
        {
            IHttpActionResult _result = null;
            Foto foto;

            _result = Ok();
            if (validate(token, userid))
            {
                using (DatosContext ctx = new DatosContext())
                {
                    foto = ctx.Fotos.Where(f => f.id == datos.id).FirstOrDefault();
                    if (foto != null)
                    {
                        foto.posicion = datos.posicion;
                        _result       = Ok(ctx.SaveChanges());
                    }
                }
            }
            return(_result);
        }
Example #9
0
        public IHttpActionResult Post([FromBody] User datos)
        {
            IHttpActionResult _result = null;
            User _userResult          = new User();

            try
            {
                using (DatosContext ctx = new DatosContext())
                {
                    _userResult       = ctx.Users.Where(u => u.username == datos.username).FirstOrDefault();
                    _userResult.Token = Guid.NewGuid().ToString();
                    ctx.SaveChanges();
                    _result = Ok(_userResult);
                }
            }
            catch (Exception ex)
            {
            }
            return(_result);
        }
Example #10
0
        public IHttpActionResult Put([FromBody] Modelo datos, Guid token, int userid)
        {
            IHttpActionResult _result     = null;
            Modelo            _dataResult = new Modelo();

            if (validate(token.ToString(), userid))
            {
                try
                {
                    using (DatosContext ctx = new DatosContext())
                    {
                        _dataResult = ctx.Modelos.Where(m => m.id == datos.id).FirstOrDefault();
                        if (_dataResult != null)
                        {
                            _dataResult.banos      = datos.banos;
                            _dataResult.construido = datos.construido;
                            _dataResult.corta      = datos.corta;
                            _dataResult.cservicio  = datos.cservicio;
                            _dataResult.dias       = datos.dias;
                            _dataResult.horas      = datos.horas;
                            _dataResult.larga      = datos.larga;
                            _dataResult.lavado     = datos.lavado;
                            _dataResult.medios     = datos.medios;
                            _dataResult.metros     = datos.metros;
                            _dataResult.pisos      = datos.pisos;
                            _dataResult.posicion   = datos.posicion;
                            _dataResult.precio     = datos.precio;
                            _dataResult.recamaras  = datos.recamaras;
                            _dataResult.terreno    = datos.terreno;
                            _dataResult.vecindario = datos.vecindario;
                            ctx.SaveChanges();
                            _result = Ok(_dataResult);
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            }
            return(_result);
        }
Example #11
0
        public LoginController(DatosContext context, IOptions <AppSetting> appSettings)
        {
            _context = context;
            var admin = _context.Users.Find("admin");

            if (admin == null)
            {
                _context.Users.Add(new User()
                {
                    UserName       = "******",
                    Password       = "******",
                    Estado         = "AC",
                    NombreCompleto = "Adminitrador",
                    Telefono       = "318000",
                    Email          = "*****@*****.**"
                });
                var registrosGuardados = _context.SaveChanges();
            }
            _userService = new UserService(context);
            _jwtService  = new JwtService(appSettings);
        }
Example #12
0
        public IHttpActionResult Post([FromBody] Subdominio datos, Guid token, int userid)
        {
            IHttpActionResult _result = null;
            User _userResult          = new User();

            try
            {
                using (DatosContext ctx = new DatosContext())
                {
                    _userResult             = ctx.Users.Where(u => u.id == userid && u.Token == token.ToString()).FirstOrDefault();
                    _userResult.subdominioa = datos.subdominioa;
                    _userResult.subdominiov = datos.subdominiov;
                    ctx.SaveChanges();
                    _result = Ok(_userResult);
                }
            }
            catch (Exception ex)
            {
            }
            return(_result);
        }
Example #13
0
        public IHttpActionResult Post([FromBody] Modelo datos, Guid token, int userid)
        {
            IHttpActionResult _result     = null;
            Modelo            _dataResult = new Modelo();

            if (validate(token.ToString(), userid))
            {
                try
                {
                    using (DatosContext ctx = new DatosContext())
                    {
                        _dataResult = ctx.Modelos.Add(datos);
                        ctx.SaveChanges();
                        _result = Ok(_dataResult);
                    }
                }
                catch (Exception ex)
                {
                }
            }
            return(_result);
        }
Example #14
0
 public void SaveChanges()
 {
     contexto.SaveChanges();
 }