public ActionResult SendMessage(EmailResponseModel model) { SendEmail sendEmail = new SendEmail(); string senderEmailAddress = "*****@*****.**"; string receiverSMTP = "smtp-mail.outlook.com"; int receiverPort = 587; string toEmailAddress = "*****@*****.**"; string subject = "New Message Received from umutdogankoc.com"; string emailBody = model.Name + " " + model.Email + " " + model.Message; string cc = "*****@*****.**"; try { sendEmail.Send(senderEmailAddress, senderPassword, receiverSMTP, receiverPort, toEmailAddress, subject, emailBody, cc); model.State = true; model.SuccessMessage = "Your message has been sent."; } catch (Exception ex) { model.State = false; model.ErrorMessage = ex.Message; } return(Json(model)); }
public void EmailResponse_WithMessages_Constructor() { // Arrange var model = new EmailResponseModel() { TransactionId = Guid.NewGuid(), Messages = new List <MessageResponseModel>() { new MessageResponseModel() { MessageId = Guid.NewGuid(), Tag = "tag" } } }; // Act var response = new EmailResponse(model); // Assert response.TransactionId.Should().Be(model.TransactionId); response.Messages.Count().Should().Be(1); response.Messages.First().MessageId.Should().Be(model.Messages.First().MessageId); response.Messages.First().Tag.Should().Be(model.Messages.First().Tag); }
public void EmailResponse_Constructor() { // Arrange var model = new EmailResponseModel() { TransactionId = Guid.NewGuid() }; // Act var response = new EmailResponse(model); // Assert response.TransactionId.Should().Be(model.TransactionId); response.Messages.Should().BeEmpty(); }
public async Task <EmailResponseModel> SendEmailConfirmationCode(EmailConfirmationRequestModel requestModel) { var company = requestModel.IsQueryAsTracking ? _repository.GetById(requestModel.Id) : _repository.AsNoTracking().SingleOrDefault(x => x.Id == requestModel.Id); if (company == null) { return(null); } EmailResponseModel response = new EmailResponseModel(); if (string.IsNullOrWhiteSpace(company.EmailConfirmationCode) || requestModel.IsResend) { company.EmailConfirmationCode = EmailHelper.GenerateVerificationCode(); company.EmailConfirmationCodeExpireTime = DateTime.Now.AddMinutes(30); if (company.IsChangeEmail) { await _emailService.SendConfirmationEmailToUser(company.AwaitingConfirmEmail, company.Name, company.EmailConfirmationCode, company.EmailConfirmationCodeExpireTime); } else if (!company.IsEmailConfirmed) { await _emailService.SendConfirmationEmailToUser(company.Email, company.Name, company.EmailConfirmationCode, company.EmailConfirmationCodeExpireTime); } if (requestModel.IsQueryAsTracking) { _repository.EditAsTenant(company); response.IsSuccess = await _repository.CommitAsync(); } else { response.ConfirmationCode = company.EmailConfirmationCode; response.ExpireTime = company.EmailConfirmationCodeExpireTime; } } return(response); }
public async Task <EmailResponseModel> ConfirmEmail(EmailConfirmationRequestModel model) { EmailResponseModel response = new EmailResponseModel(); if (!string.IsNullOrWhiteSpace(model.ConfirmationCode) && !string.IsNullOrWhiteSpace(model.Id)) { var user = await _userManager.FindByIdAsync(model.Id); if (user.EmailConfirmationCodeExpireTime.HasValue && user.EmailConfirmationCodeExpireTime.GetValueOrDefault() < DateTime.Now) { response.IsSuccess = false; response.Message = "Your confirmation code has been expired."; } if (!string.IsNullOrWhiteSpace(user.EmailConfirmationCode) && string.Equals(model.ConfirmationCode?.ToLower(), user.EmailConfirmationCode?.ToLower())) { user.Email = user.AwaitingConfirmEmail; if (!user.UserName.IsReservedUsername()) { user.UserName = user.Email; } user.IsChangeEmail = false; user.AwaitingConfirmEmail = null; user.EmailConfirmationCode = null; user.EmailConfirmationCodeExpireTime = null; await _userManager.UpdateAsync(user); } else { response.IsSuccess = false; response.Message = "Your confirmation code is not valid"; } } return(response); }
public async Task <EmailResponseModel> ConfirmEmail(EmailConfirmationRequestModel requestModel) { var company = _repository.GetById(requestModel.Id); EmailResponseModel response = new EmailResponseModel(); if (company.EmailConfirmationCodeExpireTime.HasValue && company.EmailConfirmationCodeExpireTime.GetValueOrDefault() < DateTime.Now) { response.IsSuccess = false; response.Message = "Your confirmation code has been expired."; } else if (string.Equals(company.EmailConfirmationCode, requestModel.ConfirmationCode)) { company.IsEmailConfirmed = true; company.EmailConfirmationCode = null; if (!string.IsNullOrWhiteSpace(company.AwaitingConfirmEmail)) { company.Email = company.AwaitingConfirmEmail; } company.IsChangeEmail = false; company.EmailConfirmationCodeExpireTime = null; company.AwaitingConfirmEmail = null; _repository.EditAsTenant(company); await _repository.CommitAsync(); } else { response.IsSuccess = false; response.Message = "Your confirmation code is not valid"; } return(response); }