public async Task <ActionResult> UploadPost <T>(IUpload uploadViewModel) { // Get EXCEL File var fileBase = Request.Files.Get(0); if (fileBase != null && fileBase.ContentLength > 0) { // Check file type if (ExcelHelper.CheckIsExcel(fileBase)) { // Save to TABLE GenerateUploadRecord await DbManager.Add(GenerateUploadRecord(uploadViewModel)); var entity = GetEntityListFromExcel(fileBase.InputStream, uploadViewModel); // Save to database if (entity.Any()) { DbManager.AddRange(entity as List <T>); } await DbManager.GetContext().SaveChangesAsync().ConfigureAwait(continueOnCapturedContext: false); return(new HttpStatusCodeResult(HttpStatusCode.Accepted)); } } return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); }
public async Task <IActionResult> Create(Employee emp) { Employee getemp = await _context1.GetDataWithId(emp.Id); var depname = _context1.GetDepartmentName(getemp); _context1.Add(emp); _context1.Save(); ViewBag.success = "Success"; ViewBag.depname = depname; return(View(emp)); }
public async Task <ActionResult> CreatePost <T>(ICreate createViewModel) where T : class { if (ModelState.IsValid) { var entity = await ConvertCreateViewModelToEntity(createViewModel); await DbManager.Add((T)entity); await DbManager.SaveChangesAsync(); return(new HttpStatusCodeResult(HttpStatusCode.Accepted)); } return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); }
public async Task <IActionResult> Create([Bind("Name,Dob,Phone,Email,Address,State,City,Zip,JoiningDate,DepartmentName")] EmployeeModel employee) { //gets deptID corresponds to DepartmentName I am recieving int getId = _context.GetDepartmentId(employee.DepartmentName); if (employee != null) { Employee emp = new Employee(); ViewData["deptId"] = new SelectList(_context.Dept(), "DepartmentId", "DepartmentId", emp.deptId); emp.Name = employee.Name; emp.Dob = employee.Dob; emp.Email = employee.Email; emp.Address = employee.Address; emp.Phone = employee.Phone; emp.deptId = getId; emp.State = employee.State; emp.City = employee.City; emp.Zip = employee.Zip; emp.JoiningDate = employee.JoiningDate; _context.Add(emp); await _context.Save(); } return(RedirectToAction(nameof(Index))); }
public T Create(T p) { DbManager.Add(p); DbManager.SaveChanges(); return(p); }