Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- EF Inserts already existing item
- protected void Application_BeginRequest(Object sender, EventArgs e)
- {
- //-- Create an instance of EntityContext
- HttpContext.Current.Items[Constants.ENTITYCONTEXT] = new EntityContext();
- }
- protected void Application_EndRequest(Object sender, EventArgs e)
- {
- //-- Clean up the entitycontext
- var entityContext = HttpContext.Current.Items[Constants.ENTITYCONTEXT] as EntityContext;
- if (entityContext != null)
- entityContext.Dispose();
- }
- //-- EntityContext
- private EntityContext CurrentContext
- {
- get { return HttpContext.Current.Items[Constants.ENTITYCONTEXT] as EntityContext; }
- }
- private Domain.Model.Club LoadClubByIdentifier(Guid identifier)
- {
- return this.CurrentContext.Clubs.SingleOrDefault(c => c.Identifier == identifier);
- }
- Domain.Model.User user = Mapper.Map<Web.Content.Code.Models.User.CreatePlayer, Domain.Model.User>(model);
- user.Identifier = new Guid().NewSequentialGuid();
- //-- Get current club
- user.Clubs.Add(base.CurrentClub);
- //-- Get all teams and add them to user
- foreach (string teamIdentifier in model.Team)
- {
- Domain.Model.Team team = new Domain.Services.TeamServices().LoadByIdentifier(
- Domain.Helper.CryptationHelper.DecryptIdentifier(teamIdentifier));
- user.Teams.Add(new TeamUser() { Team = team, User = user, UserTeamRelation = UserTeamRelationEnum.Player });
- }
- //-- Create this user
- new Domain.Services.UserServices().CreatePlayer(user);
- public void CreatePlayer(Domain.Model.User user)
- {
- Password password = Password.GenerateRandomPassword();
- user.Password = password;
- //-- Save the user to storage
- _userRepository.SaveUser(user);
- }
- //-- Methods
- private void SaveUser(Domain.Model.User user)
- {
- this.CurrentContext.Users.Add(user);
- this.CurrentContext.SaveChanges();
- }
Add Comment
Please, Sign In to add comment