public ResponseMessage Create(ReporterFile entity) { ResponseMessage response = new ResponseMessage(); _repository.Create(entity); return(response); }
public ResponseMessage Edit(ReporterFile entity) { throw new NotImplementedException(); }
public void Create(ReporterFile entity) { _db.ReporterFiles.Add(entity); _db.SaveChanges(); }
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)); } }