public User AddUser(string name, string email, string password, string token, string phone) { string hashPassword = HashPassword(password, password); var roleLogic = new RoleLogic(); var newUser = new User(); var newTeam = new Team(); var currencyLogic = new CurrencyLogic(); var newUserTeamLink = new UserTeamLink(); byte[] time = BitConverter.GetBytes(DateTime.UtcNow.ToBinary()); byte[] key = Guid.NewGuid().ToByteArray(); string newToken = Convert.ToBase64String(time.Concat(key).ToArray()); var defaultUserRole = roleLogic.GetRole(Roles.User); var defautCurrency = currencyLogic.GetCurrencyByCode("HUF"); using (var db = new TimeTrackerModelContainer()) { var userInDb = db.User.FirstOrDefault(x => x.Email == email); if (userInDb != null) { throw new Exception("Ez az Email cím már regisztrált"); } newUser.Name = name; newUser.Email = email; newUser.Password = hashPassword; newUser.Phone = phone; newUser.Token = newToken; newUser.Role = defaultUserRole; db.Role.Attach(newUser.Role); db.User.Add(newUser); newTeam.Name = newUser.Name; db.Team.Add(newTeam); newUserTeamLink.User = newUser; newUserTeamLink.Currency = defautCurrency; newUserTeamLink.PrivatePrice = "0"; newUserTeamLink.PublicPrice = "0"; newUserTeamLink.Team = newTeam; db.Currency.Attach(newUserTeamLink.Currency); db.UserTeamLink.Add(newUserTeamLink); db.SaveChanges(); } return(newUser); }
public CurrencyDto GetCurrencyByCode(CurrencyRequest request) { try { return(_currencyLogic.GetCurrencyByCode(request.Code).Map()); } catch (Exception e) { throw new FaultException("A kért Currency nem található!"); } }