public Int32 Rank(CoeusProjectContext context) { if (Objetos == null) { context = context ?? new CoeusProjectContext(); Objetos = context.Objetos.Where(o => o.IdUsuario == IdUsuario).ToList(); } if (Objetos == null || Objetos.Count == 0) { return(0); } Int32 sumObjetos = 0; Int32 sumNotas = 0; foreach (Objeto objeto in Objetos) { foreach (Avaliacao avaliacao in objeto.Avaliacoes) { sumNotas += avaliacao.NoAvaliacao; } sumObjetos++; } sumObjetos = sumObjetos == 0 ? 1 : sumObjetos; return(Convert.ToInt32(Math.Round((decimal)(sumNotas / sumObjetos), 0))); }
public Mensagem Encrypt(Int32 IdGrupo = 0, CoeusProjectContext Context = null) { if (Context == null) { Context = new CoeusProjectContext(); } if (IdGrupo > 0) { this.Grupo = Context.Grupos.Where(g => g.IdGrupo == IdGrupo).FirstOrDefault(); } if (this.Grupo == null) { this.Grupo = Context.Grupos.Where(g => g.IdGrupo == this.IdGrupo).Include(g => g.Salt).FirstOrDefault(); } if (this.Grupo.Salt == null) { this.Grupo.Salt = Context.Salt.Where(s => s.IdSalt == this.Grupo.IdSalt).FirstOrDefault(); } this.TxMensagem = SecurityFacade.Encrypt(this.TxMensagem, this.Grupo.Salt.BtSalt); return(this); }
public static Int32 GetSequence(String NmSequence, CoeusProjectContext Context = null) { if (Context == null) { Context = new CoeusProjectContext(); } Sequence sequence = Context.Sequence.Where(s => s.NmSequence == NmSequence).FirstOrDefault(); if (sequence == null) { sequence = new Sequence(); sequence.NmSequence = NmSequence; sequence.VlSequence = 1; Context.Sequence.Add(sequence); } else { sequence.VlSequence = sequence.VlSequence + 1; Context.Entry(sequence).State = EntityState.Modified; } Context.SaveChanges(); return(sequence.VlSequence); }
public Grupo Decrypt(CoeusProjectContext Context = null) { if (this.Salt == null) { if (Context == null) { Context = new CoeusProjectContext(); } this.Salt = Context.Salt.Where(s => s.IdSalt == this.IdSalt).FirstOrDefault(); } this.NmGrupo = SecurityFacade.Decrypt(this.NmGrupo, this.Salt.BtSalt); return(this); }
public Objeto Encrypt(CoeusProjectContext Context = null) { if (this.Salt == null) { if (Context == null) { Context = new CoeusProjectContext(); } this.Salt = Context.Salt.Where(s => s.IdSalt == this.IdSalt).FirstOrDefault(); } this.NmObjeto = SecurityFacade.Encrypt(this.NmObjeto, this.Salt.BtSalt); this.TxDescricao = SecurityFacade.Encrypt(this.TxDescricao, this.Salt.BtSalt); return(this); }
public Usuario Decrypt(CoeusProjectContext Context = null) { if (this.Salt == null) { if (Context == null) { Context = new CoeusProjectContext(); } this.Salt = Context.Salt.Where(s => s.IdSalt == this.IdSalt).FirstOrDefault(); } this.TxEmail = SecurityFacade.Decrypt(TxEmail.Replace("*****@*****.**", ""), this.Salt.BtSalt); this.NmPessoa = SecurityFacade.Decrypt(NmPessoa, this.Salt.BtSalt); this.SnPessoa = SecurityFacade.Decrypt(SnPessoa, this.Salt.BtSalt); return(this); }
public Mensagem Decrypt(Int32 IdGrupo = 0, Usuario usuario = null, CoeusProjectContext Context = null) { if (IdGrupo > 0) { if (Context == null) { Context = new CoeusProjectContext(); } this.Grupo = Context.Grupos.Where(g => g.IdGrupo == IdGrupo).FirstOrDefault(); } if (this.Grupo == null) { if (Context == null) { Context = new CoeusProjectContext(); } this.Grupo = Context.Grupos.Where(g => g.IdGrupo == this.IdGrupo).Include(g => g.Salt).FirstOrDefault(); } if (this.Grupo.Salt == null) { if (Context == null) { Context = new CoeusProjectContext(); } this.Grupo.Salt = Context.Salt.Where(s => s.IdSalt == this.Grupo.IdSalt).FirstOrDefault(); } this.TxMensagem = SecurityFacade.Decrypt(this.TxMensagem, this.Grupo.Salt.BtSalt); if (usuario != null) { this.Usuario = usuario; } else if (this.Usuario != null) { this.Usuario.Decrypt(); } return(this); }
public Artigo Decrypt(CoeusProjectContext Context = null) { if (Context == null) { Context = new CoeusProjectContext(); } if (this.Objeto == null) { this.Objeto = Context.Objetos.Where(o => o.IdObjeto == this.IdObjeto).Include(o => o.Salt).FirstOrDefault(); } if (this.Objeto.Salt == null) { this.Objeto.Salt = Context.Salt.Where(s => s.IdSalt == this.Objeto.IdSalt).FirstOrDefault(); } this.Objeto.Decrypt(Context); this.TxArtigo = SecurityFacade.Decrypt(this.TxArtigo, this.Objeto.Salt.BtSalt); return(this); }
/// <summary> /// 0 = Create new Salt /// > 0 = Get Salt By Id /// </summary> public static Salt GetSalt(Int32 IdSalt = 0, CoeusProjectContext Context = null) { Salt salt = null; Boolean hasContext = true; if (Context == null) { hasContext = false; Context = new CoeusProjectContext(); } if (IdSalt == 0) { byte[] saltArray = new byte[16]; Random rand = new Random(); salt = new Salt(); for (int i = 0; i < 16; i++) { saltArray[i] = (byte)rand.Next(0, 254); } salt.TxSalt = GetString(saltArray); Context.Salt.Add(salt); if (!hasContext) { Context.SaveChanges(); } } else { salt = Context.Salt.Where(s => s.IdSalt == IdSalt).FirstOrDefault(); } return(salt); }