public User Create(User user)
        {
            using (var context = _rfContextFactory.Create())
            {
                if (user.Username.Length < 5)
                {
                    throw new AccountCreationException("Username is too short.");
                }
                var taken = context.Users.Any(u => u.Username == user.Username);
                if (taken)
                {
                    throw new AccountCreationException("Username already taken.");
                }
                var existing = context.Users.FirstOrDefault(u => u.Id == user.Id);

                if (existing != null)
                {
                    user = Update(user);
                    return(user);
                }
                context.Users.Add(user);
                SaveChanges(context);

                return(user);
            }
        }
        public AccountRequest Create(AccountRequest request)
        {
            using (var context = _rfContextFactory.Create())
            {
                if (request.MemberType == "member")
                {
                    var user = context.Users.FirstOrDefault(u => u.Id == request.PlayerId);
                    if (user != null)
                    {
                        var regions = new List <string>();
                        if (!string.IsNullOrEmpty(user.ContentRegions))
                        {
                            regions = JsonConvert.DeserializeObject <List <string> >(user.ContentRegions);
                        }
                        if (!regions.Contains(request.Region))
                        {
                            regions.Add(request.Region);
                        }

                        user.ContentRegions = JsonConvert.SerializeObject(regions);

                        SaveChanges(context);
                        return(request);
                    }
                    throw new Exception($"Unable to find player for id {request.PlayerId} from request with id {request.Id}");
                }
                else
                {
                    var existing = context.AccountRequests.FirstOrDefault(r => r.PlayerId == request.PlayerId && r.Region == request.Region);

                    if (existing != null)
                    {
                        request = Update(existing);
                        return(request);
                    }
                    context.AccountRequests.Add(request);
                    SaveChanges(context);

                    return(request);
                }
            }
        }
Example #3
0
 public List <Scenario> Get()
 {
     using (var context = _rfContextFactory.Create())
     {
         var scenario = context.Scenarios.ToList();
         return(scenario);
     }
 }