public IHttpActionResult Post([FromBody] Rebuttal rebuttal) { try { if (rebuttal == null) { return(BadRequest()); } rebuttal.CreatedDate = DateTime.Now.Date; var result = _repository.Insert(rebuttal); if (result.Status == RepositoryActionStatus.Created) { // map to dto return(Created <Rebuttal>(Request.RequestUri + "/" + rebuttal.Id.ToString(), rebuttal)); } return(BadRequest()); } catch (Exception) { return(InternalServerError()); } }
public RepositoryActionResult <Rebuttal> Update(Rebuttal t) { try { var existingData = _ctx.RipOffLawyers.FirstOrDefault(exp => exp.Id == t.Id); if (existingData == null) { return(new RepositoryActionResult <Rebuttal>(t, RepositoryActionStatus.NotFound)); } _ctx.Entry(existingData).State = EntityState.Detached; _ctx.Rebuttals.Attach(t); _ctx.Entry(t).State = EntityState.Modified; var result = _ctx.SaveChanges(); if (result > 0) { return(new RepositoryActionResult <Rebuttal>(t, RepositoryActionStatus.Updated)); } else { return(new RepositoryActionResult <Rebuttal>(t, RepositoryActionStatus.NothingModified, null)); } } catch (Exception ex) { return(new RepositoryActionResult <Rebuttal>(null, RepositoryActionStatus.Error, ex)); } }
public RepositoryActionResult <Rebuttal> Insert(Rebuttal t) { try { _ctx.Rebuttals.Add(t); var result = _ctx.SaveChanges(); if (result > 0) { return(new RepositoryActionResult <Rebuttal>(t, RepositoryActionStatus.Created)); } else { return(new RepositoryActionResult <Rebuttal>(t, RepositoryActionStatus.NothingModified, null)); } } catch (Exception ex) { return(new RepositoryActionResult <Rebuttal>(null, RepositoryActionStatus.Error, ex)); } }
public async Task <ActionResult> CreateRebuttal([Bind(Include = "RebuttalId,ReportId,UserId,Title,RebuttalText,Address,CityId,StateId,DateCreated")] RebuttalForReportViewModel rebuttal) { HtmlToText convert = new HtmlToText(); ManageMessageId?message; var reportById = _applicationDbContext.Reports.Where(m => m.ReportId == rebuttal.ReportId).SingleOrDefault(); string RandomId = Guid.NewGuid().ToString(); string PageTitle = reportById.CompanyorIndividual + " : " + convert.Convert(reportById.ReportText).Substring(0, 50); string sm_PageTitle = Regex.Replace(PageTitle, "[^A-Za-z0-9]", "-"); Rebuttal reb = new Rebuttal(); if (rebuttal.RebuttalText != null && rebuttal.Title != null) { reb.ReportId = rebuttal.ReportId; reb.RebuttalText = rebuttal.RebuttalText; reb.UserId = User.Identity.GetUserId(); reb.Title = rebuttal.Title; reb.RebuttalText = rebuttal.RebuttalText; reb.Address = rebuttal.Address; reb.CityId = rebuttal.CityId; reb.StateId = rebuttal.StateId; reb.Status = false; reb.DateCreated = DateTime.UtcNow; if (ModelState.IsValid) { _applicationDbContext.Rebuttals.Add(reb); await _applicationDbContext.SaveChangesAsync(); var getReportOwnerDisplayName = UserManager.FindByIdAsync(reportById.UserId); var getRebuttalDisplayName = UserManager.FindByIdAsync(reb.UserId); string id = Guid.NewGuid().ToString(); if (UserManager.EmailService != null) { var callbackUrl = Url.Action( "ReportDetails", "Report", new { title = sm_PageTitle, page = reportById.ReportId, iD = id }, protocol: Request.Url.Scheme); string Body = "<p><h3>Rip-Off NG</h3></p>" + "<p>Hi " + getReportOwnerDisplayName.Result.Email + ",</p>" + "<p class=\"lead\">A response has been posted to your complaint by " + getRebuttalDisplayName.Result.NameExtension + "<p>----------------------------------------------------------------------------------------------------------------------------------------</p>"; await UserManager.SendEmailAsync(reportById.UserId, "Rip-Off Ng | Response to your complaint about: " + reportById.Title, Body + " <a href=\"" + callbackUrl + "\">Click here to view</a>" + "<p></p><p>Do not reply to this email.</p><p>Regards,</p><p>Rip-Off NG Team</p><p>Psst! Remember - this is not a marketing email.Since you have a Rip-Off NG Account,we want to keep you informed about operational updates or changes to our websites.</p>"); } } } else { message = ManageMessageId.Error; return(RedirectToAction("Rebuttal", new { Controller = "Report", action = "Rebuttal", title = sm_PageTitle, page = rebuttal.ReportId, id = RandomId, message })); } return(RedirectToAction("ReportDetails", new { Controller = "Report", action = "ReportDetails", title = sm_PageTitle, page = rebuttal.ReportId, id = RandomId })); }