public bool CreateUser(CreateUser createUserObject, ModelStateDictionary modelState) { if (_sendesContext.User.Find(createUserObject.Username) != null) { modelState.AddModelError("Username", "That username is already taken"); } bool emailIsTaken = (from u in _sendesContext.User where u.Email == createUserObject.Email select u).Any(); if (emailIsTaken) { modelState.AddModelError("Email", "That email is already taken"); } if (modelState.ErrorCount != 0) { return(false); } PasswordResult passwordResult = PasswordHasher.HashPassword(createUserObject.Password); User user = new User { UserName = createUserObject.Username, Email = createUserObject.Email, Password = passwordResult.HashedPassword, Salt = passwordResult.SaltedText, FirstName = "", LastName = "" }; _sendesContext.User.Add(user); _sendesContext.SaveChanges(); return(true); }
public bool MakePurchase(PurchaseRequest purchaseRequest) { Device device = new Device { DeviceType = purchaseRequest.DeviceType }; _sendesContext.Device.Add(device); _sendesContext.SaveChanges(); int deviceId = device.Id; // id is created after saveChanges is called System.Console.WriteLine(deviceId); MailMessage message = new MailMessage(); message.To.Add(purchaseRequest.EmailAddress); message.Subject = "Purchase confirmation"; message.Body = $"Your device ID is {deviceId} {Environment.NewLine}If you have not done so already, please create account. After your account has been created, head over to the dashboard and use the device ID to register your new device."; _emailClient.SendEmail(message); return(true); }