public PositionViewModel ViewPositionDetails(int positionId) { var singlePositionDetail = entity.tblEmployeePositions.Where(x => x.positionId == positionId).FirstOrDefault(); PositionViewModel modelObj = new PositionViewModel() { positionId = singlePositionDetail.positionId, positionName = singlePositionDetail.positionName, positionDescription = singlePositionDetail.positionDescription }; return modelObj; }
public void AddNewPosition(PositionViewModel positionModel) { tblEmployeePosition newPosition = new tblEmployeePosition() { positionId=positionModel.positionId, positionDescription=positionModel.positionDescription, positionName=positionModel.positionName }; entity.tblEmployeePositions.Add(newPosition); entity.SaveChanges(); }
public void EditPosition(PositionViewModel positionModel) { tblEmployeePosition newPosition = new tblEmployeePosition() { positionId = positionModel.positionId, positionDescription = positionModel.positionDescription, positionName = positionModel.positionName }; entity.tblEmployeePositions.Add(newPosition); entity.Entry(newPosition).State = EntityState.Modified; entity.SaveChanges(); }
public ActionResult Create(FormCollection collection,PositionViewModel modelObj) { if (HttpContext.Session["UserId"] == null) { return RedirectToAction("Login", "Login"); } try { // TODO: Add insert logic here positionRepo.AddNewPosition(modelObj); return RedirectToAction("Index"); } catch { return View(); } }
public List<PositionViewModel> PositionList() { var positionList = entity.tblEmployeePositions.ToList(); List<PositionViewModel> positionModelList = new List<PositionViewModel>(); foreach(var positionItem in positionList) { PositionViewModel modelObj = new PositionViewModel() { positionId=positionItem.positionId, positionDescription=positionItem.positionDescription, positionName=positionItem.positionName }; positionModelList.Add(modelObj); } return positionModelList; }
public ActionResult Edit(int id, PositionViewModel modelObj) { if (HttpContext.Session["UserId"] == null) { return RedirectToAction("Login", "Login"); } try { // TODO: Add update logic here positionRepo.EditPosition(modelObj); return RedirectToAction("Index"); } catch { return View(); } }