public Responser GetInfoByID([FromBody] AM_PayRollInfo payRollInfo) { try { PayRollDB = new PayRollDB_(); responser_ = this.ValidateAuthorization(payRollInfo.Token.ToString()); if (responser_.Data.Get <bool>()) { responser_.Data = PayRollDB.PayRollInfo_Tab.ToList().MapTo <PayRollInfo_Tab, AM_PayRollInfo>().Where(item => item.EmployeeID.ToString() == payRollInfo.PayRollInfoID.ToString()).ToList().FirstOrDefault(); responser_.Status = 0; responser_.StatusMessage = "Operation Get successfully"; } return(responser_); } catch (Exception e) { responser_.Data = null; responser_.Status = -1; responser_.StatusMessage = e.Message.ToString(); return(responser_); } }
public Responser GetAll([FromBody] AM_Employee employee) { try { PayRollDB = new PayRollDB_(); responser_ = this.ValidateAuthorization(employee.Token.ToString()); if (responser_.Data.Get <bool>()) { responser_.Data = PayRollDB.Employees_Tab.ToList().MapTo <Employees_Tab, AM_Employee>().ToList(); responser_.Status = 0; responser_.StatusMessage = "Operation Get successfully"; } return(responser_); } catch (Exception e) { responser_.Data = null; responser_.Status = -1; responser_.StatusMessage = e.Message.ToString(); return(responser_); } }
/// <summary> /// Updates an employee within Employee PayRoll /// </summary> /// <param name="employee">Employee Model</param> /// <returns></returns> public Responser Put([FromBody] AM_Employee employee) { try { PayRollDB = new PayRollDB_(); responser_ = this.ValidateAuthorization(employee.Token.ToString()); if (responser_.Data.Get <bool>()) { Employees_Tab employees = PayRollDB.Employees_Tab.Where(bt => bt.EmployeeID == employee.EmployeeID).FirstOrDefault(); if (employees != null) { employees.Name = employee.Name; employees.LastNames = employee.LastNames; employees.Email = employee.Email; employees.Password = employee.Password; employees.RoleID = employee.RoleID; employees.Active = employee.Active; employees.AdmissionDate = DateTime.Now; PayRollDB.Employees_Tab.Add(employees); PayRollDB.SaveChanges(); string lastInserted = PayRollDB.Employees_Tab.OrderByDescending(bt => bt.EmployeeID).Take(1).Select(bt => bt.EmployeeID).FirstOrDefault().ToString(); responser_.Data = lastInserted; responser_.StatusMessage = "Operation Put for Employee successfully."; } } else { responser_.Data = employee.EmployeeID; responser_.StatusMessage = "Employee ID not found: Operation Put for Employee successfully."; } responser_.Status = 0; return(responser_); } catch (Exception e) { responser_.Data = null; responser_.Status = -1; responser_.StatusMessage = e.Message.ToString(); return(responser_); } }
/// <summary> /// Updates a PayRollInfo for an employee within Employee PayRoll /// </summary> /// <param name="payRollInfo_">PayRollInfo to add to current Employee</param> /// <returns></returns> public Responser Put([FromBody] AM_PayRollInfo payRollInfo_) { try { PayRollDB = new PayRollDB_(); responser_ = this.ValidateAuthorization(payRollInfo_.Token.ToString()); if (responser_.Data.Get <bool>()) { PayRollInfo_Tab payRollInfo = PayRollDB.PayRollInfo_Tab.Where(bt => bt.EmployeeID == payRollInfo_.EmployeeID).FirstOrDefault(); if (payRollInfo != null) { payRollInfo.BaseSalary = payRollInfo_.BaseSalary; payRollInfo.BreakfastDeduction = payRollInfo_.BreakfastDeduction; payRollInfo.SavingDeduction = payRollInfo_.SavingDeduction; PayRollDB.SaveChanges(); responser_.StatusMessage = "Operation Put for PayRollInfo successfully."; responser_.Data = payRollInfo_.PayRollInfoID; } else { responser_.StatusMessage = "PayRollInfo not found: Operation Put for PayRollInfo Failed."; responser_.Data = payRollInfo_.PayRollInfoID; } responser_.Status = 0; } return(responser_); } catch (Exception e) { responser_.Data = null; responser_.Status = -1; responser_.StatusMessage = e.Message.ToString(); return(responser_); } }
/// <summary> /// Deletes an employee within Employee PayRoll /// </summary> /// <param name="employee">Employee Model</param> /// <returns></returns> public Responser Delete([FromBody] AM_Employee employee) { try { PayRollDB = new PayRollDB_(); responser_ = this.ValidateAuthorization(employee.Token.ToString()); if (responser_.Data.Get <bool>()) { Employees_Tab employees = PayRollDB.Employees_Tab.Where(bt => bt.EmployeeID == employee.EmployeeID).FirstOrDefault(); if (employees != null) { PayRollDB.Employees_Tab.Remove(employees); PayRollDB.SaveChanges(); responser_.Data = employee.EmployeeID; responser_.StatusMessage = "Operation Delete for Employee successfully."; } } else { responser_.Data = employee.EmployeeID; responser_.StatusMessage = "Employee ID not found: Operation Delete for Employee successfully."; } responser_.Status = 0; return(responser_); } catch (Exception e) { responser_.Data = null; responser_.Status = -1; responser_.StatusMessage = e.Message.ToString(); return(responser_); } }
/// <summary> /// Adds a PayRollInfo for an employee within Employee PayRoll /// </summary> /// <param name="payRollInfo_">PayRollInfo to add to current Employee</param> /// <returns></returns> public Responser Post([FromBody] AM_PayRollInfo payRollInfo_) { try { PayRollDB = new PayRollDB_(); responser_ = this.ValidateAuthorization(payRollInfo_.Token.ToString()); if (responser_.Data.Get <bool>()) { PayRollInfo_Tab payRollInfo = new PayRollInfo_Tab(); payRollInfo.EmployeeID = payRollInfo_.EmployeeID; payRollInfo.BaseSalary = payRollInfo_.BaseSalary; payRollInfo.BreakfastDeduction = payRollInfo_.BreakfastDeduction; payRollInfo.SavingDeduction = payRollInfo_.SavingDeduction; payRollInfo.CreationDate = DateTime.Now; payRollInfo.Active = payRollInfo_.Active; PayRollDB.PayRollInfo_Tab.Add(payRollInfo); PayRollDB.SaveChanges(); string lastInserted = PayRollDB.PayRollInfo_Tab.OrderByDescending(bt => bt.PayRollInfoID).Take(1).Select(bt => bt.PayRollInfoID).FirstOrDefault().ToString(); responser_.Data = lastInserted; responser_.Status = 0; responser_.StatusMessage = "Operation Post for PayRollInfo successfully."; } return(responser_); } catch (Exception e) { responser_.Data = null; responser_.Status = -1; responser_.StatusMessage = e.Message.ToString(); return(responser_); } }