public ActionResult EditEmpDetails(int id, EmpModel obj) { try { EmpRepository EmpRepo = new EmpRepository(); EmpRepo.UpdateEmployee(obj); return(RedirectToAction("GetAllEmpDetails")); } catch { return(View()); } }
public async Task <IActionResult> EditLeaveAllocation(EmpModel empModel) { ViewBag.Rcount = _leaveRepository.leaveRecomCount(); ViewBag.Acount = _leaveRepository.leaveAppCount(); bool success = await _empRepository.UpdateEmpLeave(empModel); if (success == true) { return(RedirectToAction(nameof(SeeLeaveAllocation), new { id = empModel.EmpId, isUpdate = true })); } return(View()); }
public ActionResult EditEmployeeDetails(EmpModel emp) { try { Emprepository Emprepo = new Emprepository(); Emprepo.UpdateEmployee(emp); return(RedirectToAction("GetAllEmpDetails")); } catch (Exception) { return(View()); } }
public bool InsertCardNo(EmpModel Emp, string NewCardNo) { DataTable ChkDt = DbAccess.ExecuteDataTable("SELECT Count(*) AS TOTAL FROM tbCard WHERE CardNo = @CardNo AND Status = '1' ", new DbParameter[] { DataAccess.CreateParameter("CardNo", DbType.String, NewCardNo) } ); if (ChkDt.Rows[0]["TOTAL"].ToString() != "0") { throw new Exception("重覆卡號!"); } DbTransaction objTrans = DbAccess.CreateDbTransaction(); try { //檢查CardNo是否有重覆&使用中 DbAccess.ExecuteNonQuery("INSERT INTO tbCard(EmployeeNo,CardNo,Status,UpdateDate,EffectiveDate,ExpiryDate) VALUES(@EmployeeNo,@CardNo,@Status,@UpdateDate,@EffectiveDate,@ExpiryDate)", objTrans, new DbParameter[] { DataAccess.CreateParameter("EmployeeNo", DbType.String, Emp.EmployeeNo.ToString()), DataAccess.CreateParameter("CardNo", DbType.String, NewCardNo), DataAccess.CreateParameter("Status", DbType.String, "1"), DataAccess.CreateParameter("EffectiveDate", DbType.String, DateTime.Now.ToString("yyyyMMdd")), DataAccess.CreateParameter("ExpiryDate", DbType.String, "99991231"), DataAccess.CreateParameter("UpdateDate", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")), }); objTrans.Commit(); return(true); } catch { objTrans.Rollback(); return(false); } finally { if (objTrans != null) { objTrans.Dispose(); } } }
public ActionResult getedit(int id) { EmpModel emp = _dbcomp.GetEmp(id); MapperConfiguration config = new MapperConfiguration(m => m.CreateMap <EmpModel, EmpView>()); var mapper = config.CreateMapper(); EmpView empv = new EmpView(); mapper.Map(emp, empv); ViewBag.genderlist = new SelectList(empv.genderList, "id", "type", 2); return(View("Empedit", empv)); }
public ActionResult Update(EmpModel employee) { if (ModelState.IsValid) { Employee emp = _repository.GetEmployeeById(employee.Id); emp.Name = employee.Name; _repository.UpdateEmployee(emp); return(RedirectToAction("Index")); } return(View(employee)); }
//To Update Employee details public void UpdateEmployee(EmpModel objUpdate) { try { Connection(); _con.Open(); _con.Execute("UpdateEmpDetails", objUpdate, commandType: CommandType.StoredProcedure); _con.Close(); } catch (Exception) { throw; } }
/// <summary> /// 編輯Emp資料 /// </summary> /// <param name="Program">ProgramModel</param> /// <returns></returns> public bool TempEmpEdit(EmpModel Emp) { DbTransaction objTrans = DbAccess.CreateDbTransaction(); try { DbAccess.ExecuteNonQuery("UPDATE tbTempEmployee SET EmployeeName=@EmployeeName,DepartMentNo=@DepartMentNo,EmployeeEName=@EmployeeEName,Company=@Company WHERE EmployeeNo = @EditPK ", objTrans, new DbParameter[] { DataAccess.CreateParameter("EditPK", DbType.String, Emp.EditPK.ToString()), DataAccess.CreateParameter("EmployeeName", DbType.String, Emp.EmployeeName.ToString()), DataAccess.CreateParameter("DepartMentNo", DbType.String, Emp.DepartMentNo.ToString()), DataAccess.CreateParameter("EmployeeEName", DbType.String, Emp.EmployeeEName.ToString()), DataAccess.CreateParameter("Company", DbType.String, Emp.Company.ToString()), }); //當此員工有卡號時 就得更新..卡號有效日 if (Emp.CardStatus == "1") { DbAccess.ExecuteNonQuery("UPDATE tbCard SET EffectiveDate=@EffectiveDate,ExpiryDate=@ExpiryDate WHERE EmployeeNo = @EditPK AND CardNo = @CardNo AND Status = '1' ", objTrans, new DbParameter[] { DataAccess.CreateParameter("EditPK", DbType.String, Emp.EditPK.ToString()), DataAccess.CreateParameter("CardNo", DbType.String, Emp.CardNo.ToString()), DataAccess.CreateParameter("EffectiveDate", DbType.String, Emp.CardEffectiveDate.ToString()), DataAccess.CreateParameter("ExpiryDate", DbType.String, Emp.CardExpiryDate.ToString()), }); } objTrans.Commit(); return(true); } catch { objTrans.Rollback(); return(false); } finally { if (objTrans != null) { objTrans.Dispose(); } } }
//To Add Employee details public void AddEmployee(EmpModel objEmp) { //Additing the employess try { Connection(); _con.Open(); _con.Execute("AddNewEmpDetails", objEmp, commandType: CommandType.StoredProcedure); _con.Close(); } catch (Exception ex) { throw ex; } }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } EmpRepository EmpRepo = new EmpRepository(); EmpModel employee = EmpRepo.GetAllEmployees().Find(emp => emp.Empid == id); if (employee == null) { return(HttpNotFound()); } return(View(employee)); }
public ActionResult Salary(long id = 0) { //ViewBag.hobbyList = GetHobbyList(null); if (id == 0) { var data = _context.GetSalaries(); return(View(data)); } else { EmpModel empModel = _context.GetEmployee(id); empModel.hbList = GetHobbyList(empModel?.hobby?.Split(',').ToList() ?? null); return(PartialView("P_Form", empModel)); } }
public JsonResult TempEmpFormAdd(string EmpJson) { EmpModel Emp = null; try { Emp = JsonConvert.DeserializeObject <EmpModel>(EmpJson); if (Emp.CardNo != null && Emp.CardNo != "") { //檢查日期格式 正不正確 if (!GeneralObj.CheckDate(Emp.CardEffectiveDate)) { throw new Exception("卡號生效日格式有誤!"); } if (!GeneralObj.CheckDate(Emp.CardExpiryDate)) { throw new Exception("卡號失效日格式有誤!"); } Emp.CardEffectiveDate = Emp.CardEffectiveDate.Replace("-", ""); Emp.CardExpiryDate = Emp.CardExpiryDate.Replace("-", ""); } if (ModelFactory.TempEmpAdd(Emp)) { return(Json("1"));//代表已經處裡完 } else { return(Json(""));//失敗 } } catch (Exception ex) { return(Json(ex.Message)); } catch { return(Json("系統發生錯誤")); } }
public bool AddEmpDetails(EmpModel emp) { var json = File.ReadAllText(filepath); var list = JsonConvert.DeserializeObject <List <EmpModel> >(json); EmpModel em = new EmpModel(); em.Id = emp.Id; em.EmployeeName = emp.EmployeeName; em.PhoneNumber = emp.PhoneNumber; em.EmailAddress = emp.EmailAddress; list.Add(em); string jsontooutput = JsonConvert.SerializeObject(list); File.WriteAllText(filepath, jsontooutput); return(true); }
public ActionResult Create(EmpModel employee) { if (ModelState.IsValid) { EmpRepository EmpRepo = new EmpRepository(); if (EmpRepo.AddEmployee(employee)) { ModelState.Clear(); ViewBag.Message = "Employee details added successfully"; } return(RedirectToAction("Index")); } return(View(employee)); }
public ActionResult AddEmployee(EmpModel emp) { try { Emprepository Emprepo = new Emprepository(); if (Emprepo.AddEmployee(emp)) { ViewBag.message = "Almacenado correctamente"; } return(RedirectToAction("GetAllEmpDetails")); } catch (Exception) { return(View()); } }
public async Task <bool> UpdateEmpLeave(EmpModel empModel) { var emp = await _context.Employees.FindAsync(empModel.EmpId); emp.CasualAllocated = empModel.CasualAllocated; emp.AnnualAllocated = empModel.AnnualAllocated; emp.MedicalAllocated = empModel.MedicalAllocated; emp.ShortLeaveAllocated = empModel.ShortLeaveAllocated; emp.HalfLeaveAllocated = empModel.HalfLeaveAllocated; emp.FromDate = empModel.FromDate; emp.Todate = empModel.Todate; _context.Entry(emp).State = EntityState.Modified; await _context.SaveChangesAsync(); return(true); }
public ActionResult AddEmployee(EmpModel Emp) { try { if (ModelState.IsValid) { EmpRepository EmpRepo = new EmpRepository(); EmpRepo.AddEmployee(Emp); ViewBag.Message = "Records added successfully."; } return(View()); } catch { return(View()); } }
public int AddNewRecord(EmpModel empModel) { int i = 0; using (var DBConn = DBConnectionSQL) { SqlCommand com = new SqlCommand("InsertData", DBConn); com.CommandType = CommandType.StoredProcedure; com.Parameters.AddWithValue("@FName", empModel.FName); com.Parameters.AddWithValue("@MName", empModel.MName); com.Parameters.AddWithValue("@LName", empModel.LName); com.Parameters.AddWithValue("@EmailId", empModel.EmailId); DBConn.Open(); i = com.ExecuteNonQuery(); } return(i); }
public ActionResult Index() { List <EmpModel> lstRecord = new List <EmpModel>(); var lst = ur.GetAllUser(); foreach (var item in lst) { EmpModel usr = new EmpModel(); usr.empId = item.empId; usr.FName = item.FName; usr.LName = item.LName; usr.Email = item.Email; usr.Designation = item.Designation; lstRecord.Add(usr); } return(View(lstRecord)); }
public ActionResult Create(EmpModel model) { if (ModelState.IsValid) { //below line add in edmx model cs file in top namespace //using SqlProviderServices = System.Data.Entity.SqlServer.SqlProviderServices; int id = repository.AddEmp(model); if (id > 0) { ModelState.Clear(); ViewBag.Issuccess = "Data Added"; return(RedirectToAction("GetAll")); } } return(View()); }
public bool UpdateEmployee(EmpModel obj) { HttpClient client = new HttpClient(); string endPoint = @"https://azurepocfunctionapp.azurewebsites.net/api/UpdateEmployeeFunction?code=OkjvVX0bWA7Xj2xYpmAmU7oMpsOrDQhEJ7FDSngHYgQNQawKnThecQ=="; string myJson = "{'Id': '" + obj.Empid + "','FirstName':'" + obj.FirstName + "','LastName':'" + obj.LastName + "','Age':'" + obj.Age + "','DateofBirth':'" + obj.DateofBirth + "' ,'Address':'" + obj.Address + "','IsActive':'" + obj.IsActive + "'}"; HttpResponseMessage response = client.PostAsync(endPoint, new StringContent(myJson, Encoding.UTF8, "application/json")).Result; string result = (response != null && response.StatusCode.ToString() == "OK" ? response.Content.ReadAsStringAsync().Result : null); if (!string.IsNullOrWhiteSpace(result)) { return(true); } else { return(false); } }
public ActionResult Edit(EmpModel emp) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:57510/api/"); //HTTP POST var putTask = client.PutAsJsonAsync <EmpModel>("employee", emp); putTask.Wait(); var result = putTask.Result; if (result.IsSuccessStatusCode) { return(RedirectToAction("Index")); } } return(View(emp)); }
///<summary> ///Action method which ///insert the data into database by capturing ///Model values which comes from user as input ///</summary> public ActionResult AddNewEmployee(EmpModel Emp) { //To Prevent firing validation error on first page Load if (ModelState.IsValid) { string constr = ConfigurationManager.ConnectionStrings["getconn"].ToString(); EmployeeDAC employeeDAC = new EmployeeDAC(constr); int i = employeeDAC.AddNewRecord(Emp); if (i >= 1) { ViewBag.Message = "New Employee Added Successfully"; } } ModelState.Clear(); return(View()); }
// PUT: api/Employee/5 public void Put(int id, [FromBody] Employee value) { using (EmpModel db = new EmpModel()) { Employee y = db.Employees.Where(x => x.Id == id).FirstOrDefault(); if (y != null) { y.FirstName = value.FirstName; y.LastName = value.LastName; y.Salary = value.Salary; y.Email = value.Email; y.StartDate = value.StartDate; y.EndDate = value.EndDate; y.Title = value.Title; db.SaveChanges(); } } }
public bool UpdateEmp(int id, EmpModel model) { using (var context = new AniketEntities()) { var emp = new tblEmp(); //context.tblEmp.FirstOrDefault(x => x.Id == id); emp.Id = model.Id; emp.FirstName = model.FirstName; emp.LastName = model.LastName; emp.Email = model.Email; emp.Code = model.Code; emp.AddressId = model.AddressId; context.Entry(emp).State = System.Data.Entity.EntityState.Modified; //most imp line context.SaveChanges(); return(true); }; }
public void AddEmp(EmpModel emp) { bool isexistingrec = false; foreach (EmpModel rec in _emplist) { if (rec.id == emp.id) { rec.salary = emp.salary; isexistingrec = true; } } if (isexistingrec == false) { _emplist.Add(emp); } }
public void Put(Guid id, [FromBody] EmpModel empModel) { logger.LogInformation("PUT api/emp/{0}", id); logger.LogTrace("Adding model {0}", empModel); // TODO: Authentication, authorization. // TODO: Validation. empModel.Id = id; var emp = mapper.Map <Emp>(empModel); var result = empRepository.Put(emp); logger.LogInformation("PUT api/emp/{0} result {1}", id, result); HttpContext.Response.StatusCode = (result == PutResult.Created) ? StatusCodes.Status201Created : StatusCodes.Status200OK; }
public List <EmpModel> getEmpHistusersToBeDeleted(UserModel users, DateTime effectivedate, DateTime enddate) { List <EmpModel> userlist = new List <EmpModel>(); string sql = ""; DataTable dtEmp = new DataTable(); DataTable dtOverLap = new DataTable(); DataTable dtGetEmpRowID = new DataTable(); sql = "select * from [dbo].[View_EmployeePrimaryTeam] where EmpName ='" + users.employee + "'"; dtEmp = getData(sql); if (dtEmp.Rows.Count > 0) { foreach (DataRow row in dtEmp.Rows) { EmpModel user = new EmpModel(); if (users.userid > 0) { sql = "SELECT userid FROM [cred].[EmplServiceDeliveryHistorical] " + " WHERE employee = '" + users.employee + "' and svc_delivery_amount ='" + users.svc_delivery_amount + "' and " + " convert(date, svc_del_effectivedate) = '" + effectivedate + "' and convert(date, svc_del_enddate) ='" + enddate + "' and program_desc ='" + row["Program"].ToString() + "'"; dtGetEmpRowID = getData(sql); if (dtGetEmpRowID.Rows.Count > 0) { user.userid = Convert.ToInt32(dtGetEmpRowID.Rows[0]["userid"].ToString()); } else { user.userid = 0; } } user.EmpName = row["EmpName"].ToString(); user.EmpExtID = Convert.ToInt32(row["EmpExtID"].ToString()); user.Amount = users.svc_delivery_amount.ToString(); user.Effectivedate = effectivedate.ToString(); user.Enddate = enddate.ToString(); user.Program = row["Program"].ToString(); user.ServiceLine = row["ServiceLine"].ToString(); user.EmpStatus = row["EmpStatus"].ToString(); userlist.Add(user); users.errorStr = ""; } } return(userlist); }
public static EmpModel GetEmployee(int?id) { EmpModel model = new EmpModel(); using (MySqlConnection con = new MySqlConnection(conString)) { con.Open(); using (MySqlCommand cmd = new MySqlCommand()) { cmd.Connection = con; cmd.CommandType = CommandType.Text; cmd.CommandText = "Select * from employee where EmpId = " + id + ""; MySqlDataReader rdr = cmd.ExecuteReader(); model = (EmpModel)rdr.GetEnumerator().Current; } con.Close(); } return(model); }
public static int UpdateEmployee(EmpModel model) { int i; using (MySqlConnection con = new MySqlConnection(conString)) { con.Open(); using (MySqlCommand cmd = new MySqlCommand()) { cmd.Connection = con; cmd.CommandType = CommandType.Text; cmd.CommandText = "Update employee set Name = " + model.Name + ",City = " + model.City + ",Salary = " + model.Salary + " where EmpId = " + model.EmpId + ""; //returns no of rows affected i = cmd.ExecuteNonQuery(); } } return(i); }