public async Task <ActionResult> OnPostSave() { Result result; try { var stream = new MemoryStream(); await Request.Body.CopyToAsync(stream); stream.Position = 0; using var reader = new StreamReader(stream); string requestBody = await reader.ReadToEndAsync(); if (requestBody.Length <= 0) { throw new IndexOutOfRangeException("requestBody is empty."); } var obj = JsonConvert.DeserializeObject <EditModel>(requestBody); if (obj == null) { throw new NullReferenceException("Model could not be derived from JSON object."); } RepositoryData = Session.Json.GetObject <DataModel>(HttpContext.Session, Session.Key.TestimonialDataModel); RepositoryData.Name = obj.Author; RepositoryData.EmailAddress = obj.EmailAddress; RepositoryData.Portrait ??= await Image.DefaultTestimonial(SiteSettings.Site); LocalizedDataModel entry = RepositoryData.Entries.FirstOrDefault(x => x.Lcid == SiteSettings.Lcid); if (entry == null) { return(NotFound()); } RepositoryData.Entries.Remove(entry); entry.Html = "<p>" + obj.Text.Replace(Environment.NewLine, string.Empty) + "</p>"; RepositoryData.Entries.Add(entry); result = await Testimonial.Save(SiteSettings.Site, RepositoryData); if (result.Status == ResultStatus.Succeeded) { result.Messages = new List <string> { "Testimonial saved." }; } Session.Set <Guid>(HttpContext.Session, Session.Key.InquiryResult, result.ReturnId); } catch (Exception ex) { result = new Result(ResultStatus.Failed, ex.Message, Guid.Empty); } return(new JsonResult(result)); }
public static void Add(int userId, string body, string signature) { Testimonial testimonial = new Testimonial(); testimonial.UserId = userId; testimonial.Body = body; testimonial.Signature = signature; testimonial.Status = TestimonialStatus.Paused; testimonial.Save(); }
public ActionResult SampleData() { var t = new Testimonial() { Author = "Jeremy", AuthorRole = "director,beweb", Comments = "This was great" }; t.Save(); t = new Testimonial() { Author = "Mike", AuthorRole = "director,beweb", Comments = "also, i thought it was great" }; t.Save(); return(Index()); }