public EntityAction SaveChanges() { if (db.SaveChanges() > 0) { return(EntityAction.Success); } return(EntityAction.Exception); }
public List <Author> EditComplite(Author author) { using (var context = new AuthorDbContext()) { context.Entry(author).State = EntityState.Modified; context.SaveChanges(); return(context.Authors.ToList()); } }
public List <Author> Create(Author author) { using (var context = new AuthorDbContext()) { context.Authors.Add(author); context.SaveChanges(); return(context.Authors.ToList()); } }
public List <Book> Create(Book book) { using (var context = new AuthorDbContext()) { context.Books.Add(book); context.SaveChanges(); return(context.Books.ToList()); } }
public List <Author> DeleteConfirmed(int id) { using (var context = new AuthorDbContext()) { Author author = context.Authors.Find(id); context.Authors.Remove(author); context.SaveChanges(); return(context.Authors.ToList()); } }
//<-------------------------Account Management ------------------------> public async Task <AuthorTestUser> RegisterResearcher(ResearcherRegisterViewModel Input) { var User = new AuthorTestUser { UserName = Input.Email, Email = Input.Email, }; var CheckExists = await FindUserByEmail(User.Email); if (CheckExists == null) { //add the user to our database var result = await userManager.CreateAsync(User, Input.Password); //make sure researcher role exists if it doesn't create it. if (await roleManager.RoleExistsAsync("Researcher") != true) { var researcher = new IdentityRole { Name = "Researcher" }; await roleManager.CreateAsync(researcher); } await userManager.AddToRoleAsync(User, "Researcher"); var ResearcherInformation = await authorDbContext.ResearcherInfo.FirstOrDefaultAsync(v => v.AuthorTestUserId == User.Id); ResearcherInformation.ResearcherRole = "Pending Review"; ResearcherInformation.ResearchOrganization = Input.ResearchOrganization; ResearcherInformation.ResearchOrganizationAddress = Input.ResearchOrganizationAddress; ResearcherInformation.ResearchOrganizationEmail = Input.ResearchOrganizationEmail; authorDbContext.SaveChanges(); if (result.Succeeded) { // if user is added succesfully sign them in, using a non persistant cookie return(User); } } return(null); }
public IActionResult AddBookAuthor(BookAuthorModel newAuth) { if (ModelState.IsValid) { _context.authors.Add(newAuth); _context.SaveChanges(); return(RedirectToAction("ListBookAuthors", "BookAuthor")); } else { List <string> errors = GetErrorListFromModelState(ModelState); string displayErr = ""; errors.ForEach(err => displayErr += err); ViewData["errors"] = displayErr; return(View("NewBookAuthor", newAuth)); } }