public async Task <Guid> AddRecord(DateOnly date, string recordName, string recordText) { if (string.IsNullOrWhiteSpace(recordText)) { throw new ArgumentException("Text should be passed for creating new record"); } var placeholder = _appSettingsService.GetHostAndPortPlaceholder(); var currentHostAndPort = await _appSettingsService.GetHostAndPort(); var record = new DiaryRecord { Id = Guid.NewGuid(), CreateDate = DateTime.UtcNow, ModifyDate = DateTime.UtcNow, Date = date, Name = (recordName ?? "").Replace(currentHostAndPort, placeholder, StringComparison.OrdinalIgnoreCase), Text = recordText.Replace(currentHostAndPort, placeholder, StringComparison.OrdinalIgnoreCase) }; await _context.Records.AddAsync(record).ConfigureAwait(false); await _context.SaveChangesAsync().ConfigureAwait(false); return(record.Id); }
public ActionResult DeleteConfirmed(int id) { DiaryRecord diaryRecord = db.DiaryRecords.Find(id); db.DiaryRecords.Remove(diaryRecord); db.SaveChanges(); return(RedirectToAction("Index")); }
private ActionResult Edit(DiaryRecord diaryRecord) { if (ModelState.IsValid) { db.Entry(diaryRecord).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View("Edit", diaryRecord)); }
private ActionResult Create(DiaryRecord diaryRecord) { if (ModelState.IsValid) { db.DiaryRecords.Add(diaryRecord); db.SaveChanges(); return(RedirectToAction("Index")); } return(View("Create", diaryRecord)); }
// GET: DiaryRecord/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DiaryRecord diaryRecord = db.DiaryRecords.Find(id); if (diaryRecord == null) { return(HttpNotFound()); } ViewBag.type = diaryRecord.DiaryRecordType.ToString(); return(View(diaryRecord)); }