public async Task DeleteCountryAsync(Guid id) { var entity = await _context.Countries.FirstAsync(p => p.Id == id); _context.Remove(entity); await _context.SaveChangesAsync(); }
public async Task CreateIssueAsync(IssueCreateItem item) { var issue = new Issue { Id = Guid.NewGuid(), AssignedToId = item.AssignedToId, AreaId = item.AreaId, CreationTime = DateTime.Now, IssueDescripton = item.Descripton, Title = item.Title, IssueTypeId = item.IssueTypeId, }; if (item.Attachments != null) { foreach (var attachment in item.Attachments) { var ia = new IssueAttachment { Id = Guid.NewGuid(), IssueId = issue.Id, Content = attachment }; issue.Attachments.Add(ia); } } await _context.Issues.AddAsync(issue); await _context.SaveChangesAsync(); }
public async Task DeleteAsync(Guid id) { var dbItem = await _context.Employees.FirstAsync(p => p.Id == id); _context.Employees.Remove(dbItem); await _context.SaveChangesAsync(); }
public async Task <IActionResult> Create([Bind("EntryID,Date,Text")] Entry entry) { if (ModelState.IsValid) { _context.Add(entry); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(entry)); }
public async Task <IActionResult> Create([Bind("DiaryID,Title,CreatedDate")] Diary diary) { if (ModelState.IsValid) { _context.Add(diary); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(diary)); }
public async Task <ActionResult <Note> > Post(Note note) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _db.Notes.Add(note); await _db.SaveChangesAsync(); return(Ok(note)); }
public async Task <IActionResult> Add(Note note) { if (ModelState.IsValid) { _db.Notes.Add(note); await _db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } else { return(RedirectToAction(nameof(Add))); } }
public async Task SaveEntries(int entryId, string content) { bool saveSuccesful; using (var context = new DiaryContext()) { var entry = await context.Entries.FirstOrDefaultAsync(b => b.Id == entryId); entry.Content = content; await context.SaveChangesAsync(); saveSuccesful = entry != null; } await Clients.Caller.EntriesSaved(saveSuccesful); }
public async Task Register(string username, string password) { bool registrationSuccessful; using (var context = new DiaryContext()) { context.Users.Add(new User { Username = username, Password = password, Entries = null, }); await context.SaveChangesAsync(); var user = await context.Users.FirstOrDefaultAsync(b => b.Username == username); registrationSuccessful = user != null; } await Clients.Caller.RegistrationDone(registrationSuccessful); }