public ActionResult Create(ReportViewModel model) { if (model.Origin.Equals(Constant.ReportOrigin.EMAIL) && string.IsNullOrEmpty(model.Email)) { ModelState.AddModelError("Email", "The Email field is required."); PrepareSelectList(); return(View(model)); } try { Report report = new Report() { Name = model.Name, Address = model.Address, PhoneNumber = model.PhoneNumber, Description = model.Description, Origin = model.Origin }; var response = _reportLogic.Create(report); if (response.IsError == true) { foreach (var item in response.ErrorCodes) { ModelState.AddModelError(string.Empty, item); } PrepareSelectList(); return(View(model)); } return(RedirectToAction("Index")); } catch { return(RedirectToAction("Index")); } }
public void ReportLogic() { Mock <IUnitOfWork> uow = new Mock <IUnitOfWork>(); Mock <IReportRepository> repo = new Mock <IReportRepository>(); Mock <IActivityRepository> activityRepo = new Mock <IActivityRepository>(); Mock <IAccountRepository> accountRepo = new Mock <IAccountRepository>(); ReportLogic logic = new ReportLogic(uow.Object, repo.Object, activityRepo.Object, accountRepo.Object); var report = new Report(); var sequence = new MockSequence(); repo.InSequence(sequence).Setup(r => r.Create(report)); repo.InSequence(sequence).Setup(r => r.Update(report)); repo.InSequence(sequence).Setup(r => r.Get(report.Id)); repo.InSequence(sequence).Setup(r => r.Delete(report.Id)); logic.Create(); logic.Update(report); logic.Get(report.Id); logic.Delete(report.Id); }
public ActionResult Index(HttpPostedFileBase file, HomeViewModel model) { string userResponse = HttpContext.Request.Params["g-recaptcha-response"]; bool validCaptcha = ReCaptcha.ValidateCaptcha(userResponse); if (validCaptcha) { try { Report report = new Report() { Name = model.Name, Address = model.Address, PhoneNumber = model.PhoneNumber, Description = model.Description, Origin = Constant.ReportOrigin.WEBSITE }; var response = _reportLogic.Create(report); if (response.IsError == true) { foreach (var item in response.ErrorCodes) { ModelState.AddModelError(string.Empty, item); } return(View(model)); } else { // if (file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var filePath = response.CreatedId.ToString() + "_" + fileName; var path = Path.Combine(Server.MapPath("~/Content/UploadReporter"), filePath); file.SaveAs(path); ReporterFile reporterFile = new ReporterFile(); reporterFile.FileName = fileName; reporterFile.ReportId = response.CreatedId; _reporterFileLogic.Create(reporterFile); } try { var msg = new MailMessage(); msg.To.Add(new MailAddress(ConfigurationManager.AppSettings["AdminEmail"])); msg.Subject = "LAPOR-BRANTAS New Report"; msg.Body = "Dari: " + model.PhoneNumber + ", Isi: " + model.Description; msg.From = new MailAddress("*****@*****.**"); using (var client = new SmtpClient() { Host = "relay-hosting.secureserver.net", Port = 25, EnableSsl = false, UseDefaultCredentials = false }) { client.Send(msg); } } catch (Exception ex) { } } return(RedirectToAction("SubmitLandingPage", new { id = response.CreatedId, name = model.Name })); } catch { return(RedirectToAction("Index")); } } else { ModelState.AddModelError(string.Empty, "Invalid Captcha"); HomeViewModel homeView = new HomeViewModel(); homeView.ReportList = new List <ReportViewModel>(); var reports = _reportLogic.GetAll(); foreach (var item in reports) { ReportViewModel report = new ReportViewModel() { Address = item.Address, Description = item.Description, Name = item.Name, Origin = item.Origin, CreatedDate = item.CreatedDate.ToString("dd-MMM-yyyy hh:mm"), Status = item.Status, Id = item.Id }; homeView.ReportList.Add(report); } return(View(homeView)); } }