public int Update(SetupEmployeeTypeModel model) { using (EHMSEntities ent = new EHMSEntities()) { var item = ent.SetupEmployeeTypes.Where(x => x.SetupEmployeeTypeName == model.SetupEmployeeTypeName && x.SetupEmployeeTypeID != model.SetupEmployeeTypeID); if (item.Count() == 0) { var objToUpdate = ent.SetupEmployeeTypes.Where(x => x.SetupEmployeeTypeID == model.SetupEmployeeTypeID).FirstOrDefault(); model.CreatedBy = objToUpdate.CreatedBy; model.CreatedDate = objToUpdate.CreatedDate; AutoMapper.Mapper.Map(model, objToUpdate); ent.Entry(objToUpdate).State = System.Data.EntityState.Modified; int i = ent.SaveChanges(); return(i); } else { return(0); } } }
public ActionResult Edit(SetupEmployeeTypeModel model) { try { if (ModelState.IsValid) { int i = pro.Update(model); if (i != 0) { TempData["success"] = UtilityMessage.edit; } else { TempData["success"] = UtilityMessage.editfailed; } return(RedirectToAction("Index")); } return(View()); } catch { TempData["success"] = "Error occur"; return(RedirectToAction("Index")); } }
// // GET: /SetupEmployeeType/ public ActionResult Index() { SetupEmployeeTypeModel model = new SetupEmployeeTypeModel(); model.SetupEmployeeTypeList = pro.GetList(); return(View(model)); }
public int Insert(SetupEmployeeTypeModel model) { using (EHMSEntities ent = new EHMSEntities()) { var item = ent.SetupEmployeeTypes.Where(x => x.SetupEmployeeTypeName == model.SetupEmployeeTypeName); if (item.Count() == 0) { var objToSave = AutoMapper.Mapper.Map <SetupEmployeeTypeModel, SetupEmployeeType>(model); objToSave.CreatedBy = 0; objToSave.CreatedDate = DateTime.Now; ent.SetupEmployeeTypes.Add(objToSave); int i = ent.SaveChanges(); return(i); } else { return(0); } } }
//Get: /SetupEmployeeType/Edit/ public ActionResult Edit(int id) { SetupEmployeeTypeModel model = pro.GetList().Where(x => x.SetupEmployeeTypeID == id).FirstOrDefault(); return(View(model)); }