/* Crea un Usuario */ public bool Post(M.User usuario) { bool R; try { O.User newUser = new O.User { Username = usuario.Username, Password = SHA256Encrypt(usuario.Password), Name = usuario.Name, Email = usuario.Email, Address = usuario.Address, CountProfiles = 0, JoinDate = System.DateTime.Now.ToString("g"), JoinHourZone = System.TimeZoneInfo.Local.ToString() }; BD.Users.Add(newUser); BD.SaveChanges(); R = true; } catch { R = false; } return(R); }
/* Obtiene el Consolidado de Usuarios Creados */ public M.User Get(string username, string password) { var query = from U in BD.Users where (U.Username.Equals(username)) select new { U.Id, U.Username, U.Password, U.Name }; M.User temp = new M.User(); try { var lista = query.ToArray()[0]; string hashPassword = SHA256Encrypt(password); if (lista.Password.Equals(hashPassword)) { temp.Id = lista.Id; temp.Username = lista.Username; temp.Name = lista.Name; } } catch {} return(temp); }
/* Verifica que al crear un Usuario, NO exista el Username */ /* Obtiene el Consolidado de Usuarios Creados */ public M.User[] Get() { /* * S = Database Source * Q = Query to S * U = Each User/Result in Q * UT = Temp User * AU = Array version of U * I = Item */ var S = BD.Users; var Q = from U in S where (true) select new { U.Id, U.Username, U.Name, U.Email, U.Address, U.CountProfiles, U.JoinDate, U.JoinHourZone }; int SC = S.Count(); M.User[] AU = new M.User[SC]; M.User UT; int c = 0; foreach (var I in Q) { UT = new M.User { Id = I.Id, Username = I.Username, // Name = I.Name, // Email = I.Email, // Address = I.Address, // CountProfiles = I.CountProfiles, JoinDate = I.JoinDate, // JoinHourZone = I.JoinHourZone }; AU[c] = UT; c++; } return(AU); }