public async Task <TEntity> AddByAsync(TEntity obj) { _dbContext.Add(obj); await _dbContext.SaveChangesAsync(); return(obj); }
public async Task <IActionResult> Create([Bind("studentAdmin,studentName,projectId,studentYear")] Student student) { if (ModelState.IsValid) { //var project = await _context.Projects.SingleOrDefaultAsync(m => m.projectId == student.projectId); // project.noOfStudents += 1; // _context.Update(project); // await _context.SaveChangesAsync(); var check = await _context.Student.SingleOrDefaultAsync(s => s.studentAdmin == student.studentAdmin); if (check == null) { student.dateCreated = DateTime.Now; _context.Add(student); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } else { ViewBag.error = "The student Admin already exists!"; var projectlist = _context.Projects.ToList(); var projectSelect = new SelectList(projectlist, "projectId", "projectName"); ViewBag.projectselect = projectSelect; return(View()); } } return(View(student)); }
public async Task <IActionResult> Create(VisitType visitType2) { if (ModelState.IsValid) { _context.Add(visitType2); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(visitType2)); }
public async Task <IActionResult> Create([Bind("themeId,themeName,dateCreated,backgroundColor,fontStyle")] Theme theme) { if (ModelState.IsValid) { theme.dateCreated = DateTime.Now; _context.Add(theme); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(theme)); }
public async Task <IActionResult> Create([Bind("awardId,awardName,awardLevel,noOfRecipients,awardType")] Awards awards) { if (ModelState.IsValid) { awards.dateCreated = DateTime.Now; _context.Add(awards); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(awards)); }
public async Task <IActionResult> Create([Bind("courseId,courseName,courseSubject,courseInstructor,courseVenue")] ShortCourses shortCourses) { if (ModelState.IsValid) { shortCourses.dateCreated = DateTime.Now; _context.Add(shortCourses); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(shortCourses)); }
public async Task <IActionResult> Create([Bind("projectId,projectName,projectState")] Projects projects) { if (ModelState.IsValid) { projects.noOfStudents = 0; projects.dateCreated = DateTime.Now; _context.Add(projects); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(projects)); }
public async Task addComment(Comment comment) { var user = await _userManager.GetUserAsync(Context.User); //comment.Id = Guid.NewGuid(); comment.Posted = DateTime.Now; if (user != null) { comment.UserId = user.Id; } _context.Add(comment); await _context.SaveChangesAsync(); await Clients.All.SendAsync("newComment", comment); return; }
public async Task <IActionResult> Create([Bind("visitId,companyName,companyTypeId,noOfPax,visitDate,visitTypeId,dateCreated")] Visits visits) { if (ModelState.IsValid) { if (visits.visitDate < DateTime.Now) { ViewBag.error = "The date entered is in the past. Please choose a date in the future"; var VisitTypelist1 = _context.VisitType.ToList(); var selectList1 = new SelectList(VisitTypelist1, "visitTypeId", "visitType"); ViewBag.visitTypes = selectList1; var CompanyTypelist1 = _context.CompanyType.ToList(); var companySelectList1 = new SelectList(CompanyTypelist1, "companyTypeId", "companyType"); ViewBag.CompanyType = companySelectList1; return(View(visits)); } else if (visits.visitDate.Day == DateTime.Now.Day && visits.visitDate.Month == DateTime.Now.Month) { ViewBag.error = "Visit date cannot be today"; var VisitTypelist2 = _context.VisitType.ToList(); var selectList2 = new SelectList(VisitTypelist2, "visitTypeId", "visitType"); ViewBag.visitTypes = selectList2; var CompanyTypelist2 = _context.CompanyType.ToList(); var companySelectList2 = new SelectList(CompanyTypelist2, "companyTypeId", "companyType"); ViewBag.CompanyType = companySelectList2; return(View(visits)); } visits.dateCreated = DateTime.Now; _context.Add(visits); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } //var VisitTypelist = _context.VisitType.FromSql("SELECT visitTypeId, visitType FROM VisitType").ToList(); var VisitTypelist = _context.VisitType.ToList(); var selectList = new SelectList(VisitTypelist, "visitTypeId", "visitType"); ViewBag.visitTypes = selectList; // var CompanyTypelist = _context.CompanyType.FromSql("SELECT companyTypeId, companyType FROM CompanyType").ToList(); var CompanyTypelist = _context.CompanyType.ToList(); var companySelectList = new SelectList(CompanyTypelist, "companyTypeId", "companyType"); ViewBag.CompanyType = companySelectList; return(View(visits)); }
public async Task <IActionResult> AddOrEdit([Bind("EmployeeId,FullName,EmpCode,Position,OfficeLocation")] Employee employee) { if (ModelState.IsValid) { if (employee.EmployeeId == 0) { _context.Add(employee); } else { _context.Update(employee); } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(employee)); }
public async Task <IActionResult> Create([Bind("presetId,themeId,visitId")] Preset preset) { if (ModelState.IsValid) { preset.dateCreated = DateTime.Now; _context.Add(preset); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } var list = _context.Visits.ToList(); var selectlist = new SelectList(list, "visitId", "companyName"); ViewBag.selectlist = selectlist; var themelist = _context.Theme.ToList(); var namelist = new SelectList(themelist, "themeId", "themeName"); ViewBag.namelist = namelist; return(View(preset)); }
public void Add(T entity) { _context.Add(entity); }