public WCFUser GetProfileByLogin(string login) { try { if (string.IsNullOrWhiteSpace(login)) { return(null); } using (GamePortalEntities gamePortal = new GamePortalEntities()) { User gpUser = gamePortal.Users.FirstOrDefault(p => p.Login == login); if (gpUser == null) { return(null); } WCFUser result = gpUser.ToWCFUser(gamePortal); #if DEBUG /*var xml = new PublicFileJson<WCFUser>("GetProfileByLogin.txt"); * xml.Value = result; * xml.Write();*/ #endif return(result); } } catch { return(null); } }
static public void Update(this WCFUser o, WCFUser newValue) { o.AllPower = newValue.AllPower; o.IsIgnore = newValue.IsIgnore; o.Login = newValue.Login; o.LastConnection = newValue.LastConnection; o.Power = newValue.Power; o.SpecialUsers = newValue.SpecialUsers; o.Title = newValue.Title; o.UserLikes = newValue.UserLikes; o.Version = newValue.Version; o.LastPayment = newValue.LastPayment; o.UserGames = newValue.UserGames; o.Api = newValue.Api; }
} //todo или OrderBy public WCFUser ToWCFUser(GamePortalEntities dbContext) { WCFUser result = new WCFUser { Login = this.Login, IsIgnore = this.IsIgnore, Power = this.Power, AllPower = this.AllPower, Version = this.Version }; var api = LastApiUser; result.LastConnection = api.LastConnection; //result.ClientId = api.ClientId; result.Api.Add("uid", api.uid); result.Api.Add("isFacebook", api.isFacebook.ToString()); result.Api.Add("photo", api.photo); result.Api.Add("FIO", string.Format("{0} {1}", api.first_name, api.last_name)); var time = DateTimeOffset.UtcNow - GamePortalServer.DataLiveTime; result.UserGames.AddRange(this.UserGames.Where(p => p.StartTime > time).Select(p => p.ToWCFUserGame())); result.UserLikes.AddRange(this.UserLikes.Where(p => p.Date > time).Select(p => p.ToWCFUserLike())); result.SpecialUsers.AddRange(this.SpecialUsers.Select(p => p.ToWCFSpecialUser())); result.SignerUsers = dbContext.SpecialUsers.Where(p => p.SpecialLogin == this.Login && !p.IsBlock).Select(p => p.Login).ToList(); result.Title.AddRange(this.Titles.Select(p => p.Name)); if (this.LastPayment != null && this.LastPayment.IsPublic) { result.LastPayment = new WCFPayment() { Power = this.LastPayment.Power, Time = this.LastPayment.Time, Comment = this.LastPayment.Comment?.Substring(0, this.LastPayment.Comment.Length > 200 ? 200 : this.LastPayment.Comment.Length) }; } return(result); }