예제 #1
0
        public User Parse(XDocument doc)
        {
            User user = new User();

            user.ID = (int)doc.Element("user").Attribute("id");
            user.Name = doc.Element("user").Attribute("name").Value;
            user.TermsOfUse = doc.Element("user").Attribute("termsofuse").Value;
            user.FirstName = doc.Element("user").Element("firstname").Attribute("value").Value;
            user.LastName = doc.Element("user").Element("lastname").Attribute("value").Value;
            user.AvatarLink = doc.Element("user").Element("avatarlink").Attribute("value").Value;
            user.YearRegistered = (int)doc.Element("user").Element("yearregistered").Attribute("value");
            user.LastLogin = DateTime.Parse(doc.Element("user").Element("lastlogin").Attribute("value").Value,
                                            System.Globalization.CultureInfo.CurrentCulture,
                                            System.Globalization.DateTimeStyles.AdjustToUniversal);
            user.StateOrProvince = doc.Element("user").Element("stateorprovince").Attribute("value").Value;
            user.Country = doc.Element("user").Element("country").Attribute("value").Value;
            user.WebAddress = doc.Element("user").Element("webaddress").Attribute("value").Value;
            user.XboxAccount = doc.Element("user").Element("xboxaccount").Attribute("value").Value;
            user.WiiAccount = doc.Element("user").Element("wiiaccount").Attribute("value").Value;
            user.PsnAccount = doc.Element("user").Element("psnaccount").Attribute("value").Value;
            user.BattleNetAccount = doc.Element("user").Element("battlenetaccount").Attribute("value").Value;
            user.SteamAccount = doc.Element("user").Element("steamaccount").Attribute("value").Value;
            user.TradeRating = (int)doc.Element("user").Element("traderating").Attribute("value");

            return user;
        }
예제 #2
0
        private User CreateOrUpdateUser(User user)
        {
            var existingUser = Db.Users.Where(u => u.Name == user.Name)
                                       .FirstOrDefault();

            if (existingUser.IsNull())
            {
                Db.Users.Add(user);
                Db.SaveChanges();
                return user;
            }

            return UpdateUser(existingUser, user);
        }
예제 #3
0
        private IOutcome<User> GetUser(XDocument doc)
        {
            User result = new User();

            try
            {
                result = Parser.Parse(doc);
            }
            catch(Exception ex)
            {
                return Outcomes.Failure<User>()
                               .WithMessage("Error parsing XDoc")
                               .FromException(ex);
            }

            return Outcomes.Success<User>()
                           .WithValue(result);
        }
예제 #4
0
        private User UpdateUser(User existingUser, User updatedUser)
        {
            existingUser.Name = updatedUser.Name;
            existingUser.FirstName = updatedUser.FirstName;
            existingUser.LastName = updatedUser.LastName;
            existingUser.AvatarLink = updatedUser.AvatarLink;
            existingUser.LastLogin = updatedUser.LastLogin;
            existingUser.StateOrProvince = updatedUser.StateOrProvince;
            existingUser.Country = updatedUser.Country;
            existingUser.WebAddress = updatedUser.WebAddress;
            existingUser.XboxAccount = updatedUser.XboxAccount;
            existingUser.WiiAccount = updatedUser.WiiAccount;
            existingUser.PsnAccount = updatedUser.PsnAccount;
            existingUser.BattleNetAccount = updatedUser.BattleNetAccount;
            existingUser.SteamAccount = updatedUser.SteamAccount;
            existingUser.TradeRating = updatedUser.TradeRating;

            Db.SaveChanges();

            return existingUser;
        }