public async Task <ActionResult <MContactUs> > PostMContactUs([FromBody] MContactUs mContactUs) { if (mContactUs.CName == null) { return(BadRequest()); } else if (mContactUs.CEmailId == null) { return(BadRequest()); } else if (mContactUs.CSubject == null) { return(BadRequest()); } else if (mContactUs.CMessage == null) { return(BadRequest()); } _context.MContactUs.Add(mContactUs); await _context.SaveChangesAsync(); //SendMail(mContactUs.CEmailId, mContactUs.CSubject, mContactUs.CMessage, mContactUs.CName); return(CreatedAtAction("GetMContactUs", new { id = mContactUs.IID }, mContactUs)); }
public IActionResult SaveContactUs(MContactUs form) { string token = GetCpatchaToken(); string validationMessage = ValidateContactUsForm(form, token); if (validationMessage != null) { ViewBag.Message = validationMessage; } else { IBusinessOperationManipulate <MContactUs> operation = GetSaveContactUsOperation(); form.IP = RemoteUtils.GetRemoteIPAddress(ControllerContext); form.Name = StringUtils.StripTagsRegex(form.Name); form.Subject = StringUtils.StripTagsRegex(form.Subject); form.Email = StringUtils.StripTagsRegex(form.Email); form.Message = StringUtils.StripTagsRegex(form.Message); operation.Apply(form); bool sendResult = SendEmail(form, token); if (sendResult) { ViewBag.Message = "Your message has been received and we will contact you soon."; } else { ViewBag.Message = "Unable to send the message, internal server error."; } } return(View("Contact")); }
public async Task <IActionResult> PutMContactUs(int id, MContactUs mContactUs) { if (id != mContactUs.IID) { return(BadRequest()); } _context.Entry(mContactUs).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MContactUsExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public string ValidateContactUsForm(MContactUs form, string token) { string validationMessage = null; if (String.IsNullOrEmpty(form.Name)) { validationMessage = "Name cannot be empty."; } else if (String.IsNullOrEmpty(form.Subject)) { validationMessage = "Subject cannot be empty."; } else if (String.IsNullOrEmpty(form.Message)) { validationMessage = "Message cannot be empty."; } else if (String.IsNullOrEmpty(form.Email)) { validationMessage = "Email cannot be empty."; } else if (String.IsNullOrEmpty(token)) { validationMessage = "Please click reCaptcha checkbox to make sure you are not robot."; } return(validationMessage); }
public async Task <IActionResult> Edit(int id, [Bind("IID,CName,CEmailId,CSubject,CMessage,DCreateDate")] MContactUs mContactUs) { if (id != mContactUs.IID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(mContactUs); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MContactUsExists(mContactUs.IID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(mContactUs)); }
public async Task <IActionResult> Index([Bind("IID,CName,CEmailId,CSubject,CMessage,DCreateDate")] MContactUs mContactUs) { if (ModelState.IsValid) { _context.Add(mContactUs); await _context.SaveChangesAsync().ConfigureAwait(true); return(RedirectToAction(nameof(Index))); } return(View(mContactUs)); }
public void ValidateContactUsFormTest(String name, String subject, String email, String message, string expected) { MContactUs model = new MContactUs(); model.Name = name; model.Subject = subject; model.Email = email; model.Message = message; string result = controller.ValidateContactUsForm(model, "This is fake"); Assert.AreEqual(expected, result); }
public void SaveContactTestEmpty(String name, String subject, String email, String message) { MContactUs model = new MContactUs(); model.Name = name; model.Subject = subject; model.Email = email; model.Message = message; ViewResult result = (ViewResult)controller.SaveContactUs(model); Assert.AreEqual(null, model.IP); Assert.AreEqual("Contact", result.ViewName); Assert.AreEqual("Name cannot be empty.", result.ViewData["Message"]); }
public void SendEmailNoEnvironment() { string nullString = null; var mockController = new Mock <ContactUsController>() { CallBase = true }; mockController.Setup(foo => foo.GetEmailTo()).Returns(nullString); MContactUs contactUs = new MContactUs(); bool result = mockController.Object.SendEmail(contactUs, "ThisIsCaptchaToken"); Assert.IsFalse(result); }
public void SaveContactFail(String name, String subject, String email, String message) { MContactUs model = new MContactUs(); model.Name = name; model.Subject = subject; model.Email = email; model.Message = message; mockController.Setup(foo => foo.SendEmail(It.IsAny <MContactUs>(), It.IsAny <string>())).Returns(false); ViewResult result = (ViewResult)controller.SaveContactUs(model); Assert.AreEqual("127.0.0.1", model.IP); Assert.AreEqual("Contact", result.ViewName); Assert.AreEqual("Unable to send the message, internal server error.", result.ViewData["Message"]); }
public IActionResult ContactUs(MContactUs ObjmContactUs) { if (!ModelState.IsValid) { return(View(ObjmContactUs)); } _context.MContactUs.Add(ObjmContactUs); _context.SaveChanges(); SendMail(ObjmContactUs.CEmailId, ObjmContactUs.CSubject, ObjmContactUs.CMessage, ObjmContactUs.CName); return(RedirectToAction("ContactUsThanks", new { Name = ObjmContactUs.CName, Email = ObjmContactUs.CEmailId })); }
public void SaveContactTest(String name, String subject, String email, String message) { mockController.Setup(foo => foo.GetEmailTo()).Returns("*****@*****.**"); MContactUs model = new MContactUs(); model.Name = name; model.Subject = subject; model.Email = email; model.Message = message; ViewResult result = (ViewResult)controller.SaveContactUs(model); Assert.AreEqual("127.0.0.1", model.IP); Assert.AreEqual("Contact", result.ViewName); Assert.AreEqual("Your message has been received and we will contact you soon.", result.ViewData["Message"]); }
public void SaveTest() { INoSqlContext ctx = new Mock <INoSqlContext>().Object; FactoryBusinessOperation.SetNoSqlContext(ctx); var opt = (IBusinessOperationManipulate <MContactUs>)FactoryBusinessOperation.CreateBusinessOperationObject("SaveContactUs"); MContactUs dat = new MContactUs(); try { int result = opt.Apply(dat); Assert.AreEqual(result, 0); } catch (Exception) { //Do nothing } }
public virtual bool SendEmail(MContactUs form, string captchaToken) { bool result = false; string emailTo = GetEmailTo(); if (emailTo != null) { Mail m = new Mail(); m.From = "*****@*****.**"; m.FromName = form.Name; m.To = emailTo; m.Subject = form.Subject; m.IsHtmlContent = true; m.Body = form.Email + ", " + form.Message; m.BCC = ""; m.CC = ""; ISmtpContext smtpContext = GetSmtpContext(); smtpContext.Send(m); Log.Logger.Information("Email sent to [{0}]", emailTo); result = true; string shortToken = captchaToken.Substring(0, 10); LineNotification line = new LineNotification(); string token = Environment.GetEnvironmentVariable("MAGNUM_LINE_TOKEN"); line.SetNotificationToken(token); string lineMsg = String.Format( "\nMagnumWeb ContactUs\nFrom:{0}\nSubject:{1}\nMessage:{2}\nCaptcha:{3}", form.Email, form.Subject, form.Message, shortToken); line.Send(lineMsg); } else { Log.Logger.Information("Env variable MAGNUM_EMAIL_TO not set!!!"); } return(result); }
public IActionResult ContactUs() { MContactUs ObjmContactUs = new MContactUs(); return(View(ObjmContactUs)); }