public ActionResult Register(RegisterViewModel model) { if (!ModelState.IsValid) { model.errMessage = "Please enter valid information."; return(View(model)); } // Validate whether account already exists. Account existingAccount = AccountDB.CheckAccountAvailability(model.username, model.email); // If no match, then create a new account. if (existingAccount == null) { Account myAccount = new Account { Username = model.username, Name = model.name, Email = model.email, PasswordHash = model.psw, PhoneNumber = model.phoneNbr, Carrier = model.carrier }; if (model.isEmailNotiType) { myAccount.NotificationType |= NotificationType.Email; } if (model.isTextNotiType) { myAccount.NotificationType |= NotificationType.SMS; } if (model.isSYLocation) { myAccount.Location |= Location.Sylvania; } if (model.isRCLocation) { myAccount.Location |= Location.RockCreek; } if (model.isCASLocation) { myAccount.Location |= Location.Cascade; } if (model.isSELocation) { myAccount.Location |= Location.Southeast; } myAccount.Code = Guid.NewGuid().ToString(); AccountDB.CreateAccount(myAccount); string subject = "Please confirm your email."; string url = "http://*****:*****@" <p><a href='" + url + @"'>" + url + @"<a/></p> hANNGry "; EmailNotifier.SendHtmlEmail(myAccount.Email, subject, body); model.message = "Register successfully"; } // Validate for an existing email. else if (model.email == existingAccount.Email) { model.errMessage = "Email already exists. Please enter a new one."; } // Validate for an existing username. else if (model.username == existingAccount.Username) { model.errMessage = "Username already exists. Please enter a new one."; } // Validate for an existing phone number. else if (model.phoneNbr == existingAccount.PhoneNumber) { model.errMessage = "Phone number already exists. Please enter a new one."; } return(View(model)); }