public void RegisterUser(UserProfileDto profileDto) { Profile profile = new Profile(); profile.Name = profileDto.Name; profile.PhoneNumber = profileDto.PhoneNumber; BillingSystemContext context = new BillingSystemContext(); context.Profiles.Add(profile); context.SaveChanges(); Users user = new Users(); user.UserName = profileDto.UserName; user.Email = profileDto.Email; user.Password = SecurePasswordHasher.Hash(profileDto.Password); user.ConfirmPassword = SecurePasswordHasher.Hash(profileDto.ConfirmPassword); user.ProfileID = profile.IDNumber; context.Users.Add(user); context.SaveChanges(); }
public Payment RegisterPayment(int ClientId, decimal Amount) { try { using (BillingSystemContext context = new BillingSystemContext()) { DateTime validity = context.Clients.FirstOrDefault(c => c.IDNumber == ClientId).Validity; Tariff tarif = context.Clients .Include(c => c.ClientTarif) .FirstOrDefault(c => c.IDNumber == ClientId).ClientTarif; Tariff tarifa = context.Tariffs .FirstOrDefault( t => t.IDNumber == context.Clients.FirstOrDefault(c => c.TariffId == t.IDNumber).TariffId); decimal tarifPrice = tarifa.Price; decimal amount = Amount; int months = Convert.ToInt32(amount / tarifPrice); Payment payment = new Payment() { Client = ClientId, Date = DateTime.Now, Amount = Amount }; validity = validity.AddMonths(months); context.Payments.Add(payment); context.Clients.FirstOrDefault(c => c.IDNumber == payment.Client).Validity = validity; context.SaveChanges(); return(payment); } } catch (Exception) { throw; } }