Esempio n. 1
0
        public Reply Login([FromBody] AccessViewModel model)
        {
            Reply oR = new Reply();

            try
            {
                using (mvcApiEntities1 db = new mvcApiEntities1())
                {
                    var lst = db.Table1.Where(d => d.email == model.email && d.passwordd == model.password && d.idEstatus == 1);
                    if (lst.Count() > 0)
                    {
                        oR.result = 1;
                        oR.data   = Guid.NewGuid().ToString();

                        Table1 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.result  = 1;
                oR.message = "Ocurrio un Error" + ex;
            }
            return(oR);
        }
Esempio n. 2
0
 public bool Verify(string token)
 {
     using (mvcApiEntities1 db1 = new mvcApiEntities1())
     {
         if (db1.Table1.Where(d => d.token == token && d.idEstatus == 1).Count() > 0)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Esempio n. 3
0
        public Reply Add([FromBody] AnimalViewModel model)
        {
            Reply oR = new Reply();

            oR.result = 0;

            if (!Verify(model.token))
            {
                oR.message = "No autorizado";
                return(oR);
            }
            //vALIDA

            if (!Validate(model))
            {
                oR.message = error;
                return(oR);
            }

            try
            {
                using (mvcApiEntities1 db3 = new mvcApiEntities1())
                {
                    animal oAnimal = new animal();
                    oAnimal.idState = 1;
                    oAnimal.name    = model.Name;
                    oAnimal.patas   = model.Patas;

                    db3.animal.Add(oAnimal);
                    db3.SaveChanges();

                    List <LsitAnimalsViewModel> lst = (from d in db3.animal
                                                       where d.idState == 1
                                                       select new LsitAnimalsViewModel
                    {
                        Name = d.name,
                        Patas = d.patas
                    }).ToList();
                    oR.data   = lst;
                    oR.result = 1;
                }
            }
            catch (Exception ex)
            {
                oR.message = "Ocurrio error del servidor" + ex;
            }
            return(oR);
        }
Esempio n. 4
0
        public Reply Formulario([FromBody] AccessViewModel model)
        {
            Reply oR = new Reply();

            try {
                //Hacer la peticion aca
                using (mvcApiEntities1 db = new mvcApiEntities1()) {
                }
            }
            catch (Exception ex)
            {
                oR.result  = 1;
                oR.message = "Ocurrio un error " + ex;
            }
            return(null);
        }
Esempio n. 5
0
        public Reply Get([FromBody] SecurityModel model)
        {
            if (model is null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            Reply oR = new Reply();

            oR.result = 0;
            if (!Verify(model.token))
            {
                oR.message = "No autorizado";
                return(oR);
            }
            try
            {
                using (mvcApiEntities1 db2 = new mvcApiEntities1())
                {
                    List <LsitAnimalsViewModel> lst = (from d in db2.animal
                                                       where d.idState == 1
                                                       select new LsitAnimalsViewModel
                    {
                        Name = d.name,
                        Patas = d.patas
                    }).ToList();
                    oR.data   = lst;
                    oR.result = 1;
                }
            }
            catch (Exception ex)
            {
                oR.message = "Ocurrio error del servidor" + ex;
            }

            return(oR);
        }