Esempio n. 1
0
 public object GetById(int id)
 {
     using (GaneshaAdriContext db = new GaneshaAdriContext())
     {
         Contenido          contenido          = db.Contenido.Where(x => x.IdContenido == id).ToList().FirstOrDefault();
         ContenidoViewModel contenidoViewModel = new ContenidoViewModel
         {
             Id      = contenido.IdContenido,
             Content = contenido.Html == null ? string.Empty : Encoding.ASCII.GetString(contenido.Html),
             Title   = contenido.Titulo
         };
         return(contenidoViewModel);
     }
 }
Esempio n. 2
0
 public object Get()
 {
     using (
         GaneshaAdriContext db = new GaneshaAdriContext())
     {
         List <ContenidoViewModel> lstContenidoViewModel = new List <ContenidoViewModel>();
         foreach (var item in db.Contenido.ToList())
         {
             ContenidoViewModel contenidoViewModel = new ContenidoViewModel
             {
                 Id      = item.IdContenido,
                 Content = item.Html == null ? string.Empty : Encoding.ASCII.GetString(item.Html),
                 Title   = item.Titulo
             };
             lstContenidoViewModel.Add(contenidoViewModel);
         }
         return(lstContenidoViewModel.ToList());
     }
 }
Esempio n. 3
0
        public UserResponse Auth(AuthViewModel model)
        {
            UserResponse userResponse = new UserResponse();

            using (var db = new GaneshaAdriContext())
            {
                string spassword = Encrypt.GetSHA256(model.Password);

                var usuario = db.Usuario.Where(d => d.Email == model.Email && d.Password == spassword).FirstOrDefault();
                if (usuario == null)
                {
                    return(null);
                }
                userResponse.Email = usuario.Email;
                userResponse.Token = GetToken(usuario);
            }

            return(userResponse);
        }
Esempio n. 4
0
 public object Delete(int Id)
 {
     try
     {
         using (GaneshaAdriContext db = new GaneshaAdriContext())
         {
             Contenido contenido = db.Contenido.Find(Id);
             db.Remove(contenido);
             db.SaveChanges();
             return(new Response {
                 Status = StatusResponse.Success, Message = "Succesfully Deleted"
             });
         }
     }
     catch (Exception)
     {
         return(new Response {
             Status = StatusResponse.Error, Message = "Invalid Data."
         });
     }
 }
Esempio n. 5
0
 public object Update(ContenidoViewModel model)
 {
     try
     {
         using (GaneshaAdriContext db = new GaneshaAdriContext())
         {
             Contenido contenido = db.Contenido.Find(model.Id);
             contenido.Titulo          = model.Title;
             contenido.Html            = Encoding.ASCII.GetBytes(model.Content);
             db.Entry(contenido).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
             db.SaveChanges();
             return(new Response {
                 Status = StatusResponse.Success, Message = "Succesfully Updated"
             });
         }
     }
     catch (Exception)
     {
         return(new Response {
             Status = StatusResponse.Error, Message = "Invalid Data."
         });
     }
 }
Esempio n. 6
0
 public object Add(ContenidoViewModel model)
 {
     try
     {
         using (GaneshaAdriContext db = new GaneshaAdriContext())
         {
             Contenido contenido = new Contenido();
             contenido.Html   = Encoding.ASCII.GetBytes(model.Content);
             contenido.Titulo = model.Title;
             db.Contenido.Add(contenido);
             db.SaveChanges();
             return(new Response {
                 Status = StatusResponse.Success, Message = "Succesfully Saved"
             });
         }
     }
     catch (Exception)
     {
         return(new Response {
             Status = StatusResponse.Error, Message = "Invalid Data."
         });
     }
 }