public IHttpActionResult PostEmployeeDet(EmployeeDet employeedet) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.EmployeeDets.Add(employeedet); try { db.SaveChanges(); } catch (DbUpdateException) { if (EmployeeDetExists(employeedet.Id)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = employeedet.Id }, employeedet)); }
public IHttpActionResult PutEmployeeDet(int id, EmployeeDet employeedet) { EmployeeDet employeedet1 = db.EmployeeDets.Find(id); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != employeedet1.Id) { return(BadRequest()); } db.Entry(employeedet1).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!EmployeeDetExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GetEmployeeDet(int id) { EmployeeDet employeedet = db.EmployeeDets.Find(id); if (employeedet == null) { return(NotFound()); } return(Ok(employeedet)); }
public IHttpActionResult DeleteEmployeeDet(int id) { EmployeeDet employeedet = db.EmployeeDets.Find(id); if (employeedet == null) { return(NotFound()); } db.EmployeeDets.Remove(employeedet); db.SaveChanges(); return(Ok(employeedet)); }
public async Task <IActionResult> Create(EmployeeCreateViewModel model) { if (ModelState.IsValid) { var employee = new EmployeeDet { Id = model.Id, EmpId = model.EmpId, FirstName = model.FirstName, LastName = model.LastName, Fullname = model.Fullname, Gender = model.Gender, Email = model.Email, DOB = model.DOB, DOJ = model.DOJ, Designation = model.Designation, TFN = model.TFN, paymentMethod = model.paymentMethod, studentLoan = model.studentLoan, Address = model.Address, Phone = model.Phone, City = model.City, POcode = model.POcode }; if (model.ImageUrl != null && model.ImageUrl.Length > 0) { var uploadDir = @"images/employee"; var fileName = Path.GetFileNameWithoutExtension(model.ImageUrl.FileName); var extension = Path.GetExtension(model.ImageUrl.FileName); var webRootPath = _hostingEnvironment.WebRootPath; fileName = DateTime.UtcNow.ToString("yymmssfff") + fileName + extension; var path = Path.Combine(webRootPath, uploadDir, fileName); await model.ImageUrl.CopyToAsync(new FileStream(path, FileMode.Create)); employee.ImageUrl = "/" + uploadDir + "/" + fileName; } await _employeeService.CreateAsync(employee); return(RedirectToAction(nameof(Index))); } return(View()); }
public async Task UpdateAsync(EmployeeDet employeeDet) { _context.Update(employeeDet); await _context.SaveChangesAsync(); }
public async Task CreateAsync(EmployeeDet newEmployee) { await _context.EmployeeDets.AddAsync(newEmployee); await _context.SaveChangesAsync(); }
public JsonResult AddEmployee(EmployeeDet emp) { return(Json(emp, JsonRequestBehavior.AllowGet)); }