public string SendRegisteredData(User user) { List <string> errors = new List <string>(); if (user.Email == null) { errors.Add("no_email"); } else if (!IsValidEmail(user.Email)) { errors.Add("invalid_email"); } else if (_userRepo.FindUser(a => a.Email == user.Email) != null) { errors.Add("existing_email"); } if (user.Password == null || user.ConfirmPassword == null) { errors.Add("no_password"); } else if (user.ConfirmPassword != user.Password) { errors.Add("password_not_match"); } if (user.CompanyName == null) { errors.Add("companyname_required"); } if (user.FirstName == null) { errors.Add("firstname_required"); } else if (user.FirstName.Any(char.IsDigit)) { errors.Add("firstname_not_letter"); } else if (user.FirstName.Length > 50) { errors.Add("firstname_max_letter"); } if (user.LastName == null) { errors.Add("lastname_required"); } else if (user.LastName.Any(char.IsDigit)) { errors.Add("lastname_not_letter"); } else if (user.LastName.Length > 50) { errors.Add("lastname_max_letter"); } if (user.Phonenumber == null) { errors.Add("phone_required"); } else if (!user.Phonenumber.Any(char.IsDigit)) { errors.Add("number_only"); } if (user.Address == null) { errors.Add("address_required"); } if (user.Image == null) { errors.Add("no_picture"); } if (errors.Count != 0) { string errorList = string.Join(",", errors); return(errorList); } if (user.Image != null) { string uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "Images"); var uniqueName = Guid.NewGuid().ToString() + "_" + user.Image.FileName; string filePath = Path.Combine(uploadsFolder, uniqueName); user.Image.CopyTo(new FileStream(filePath, FileMode.Create)); user.ImageName = uniqueName; HttpContext.Session.SetString("Image", user.ImageName); } Utilities util = new Utilities(); user.Password = util.base64Encode(user.Password); if (_userRepo.FindUser(a => a.Email == user.Email) == null) { _userRepo.Create(user); } try { EmailClass.GmailUsername = "******"; EmailClass.GmailPassword = "******"; EmailClass mailer = new EmailClass(); mailer.ToEmail = user.Email; mailer.Subject = "You are now part of Mail Expert Messengerial"; mailer.Body += "Hi " + user.FirstName + " " + user.LastName; mailer.Body += "<br> Here's your username : "******"<br> Here's your password : "******"<br> Click here to activate your account. https://localhost:44379/User/EmailActivate/" + user.UserID; mailer.IsHtml = true; mailer.Send(); } catch (Exception e) { } return(""); }