예제 #1
0
        public Responser CreateTokenAuth(string userId = "")
        {
            try
            {
                bool isValid = false;

                if (!string.IsNullOrWhiteSpace(userId))
                {
                    //Generate a Token
                    AM_User userLogged  = new AM_User();
                    Guid    tokenLogged = Guid.NewGuid();
                    userLogged.Token  = tokenLogged.ToString();
                    userLogged.UserID = int.Parse(userId);

                    Employees_Tab empTab = PayRollDB.Employees_Tab.Where(item => item.EmployeeID == userLogged.UserID).ToList().FirstOrDefault();

                    if (empTab != null)
                    {
                        //Record Token in OAuth's Table
                        TokenAuth tokenRecords = new TokenAuth();
                        tokenRecords.Token         = tokenLogged;
                        tokenRecords.CreationDate  = DateTime.Now;
                        tokenRecords.TokenStatusID = PayRollDB.TokenStatus.Where(item => item.Name == "Active").ToList().FirstOrDefault().TokenStatusID;
                        PayRollDB.TokenAuth.Add(tokenRecords);
                        PayRollDB.SaveChanges();

                        //Set token to user
                        empTab.Token = tokenLogged;
                        PayRollDB.SaveChanges();

                        isValid         = true;
                        responser_.Data = tokenLogged.ToString();
                    }
                    else
                    {
                        isValid         = false;
                        responser_.Data = string.Empty;
                    }
                }
                else
                {
                    isValid         = false;
                    responser_.Data = string.Empty;
                }

                responser_.Status        = (isValid ? 1 : 0);
                responser_.StatusMessage = (isValid ? "Token Auth generated successfully" : "Error at generating Token Auth");
                return(responser_);
            }
            catch (Exception e)
            {
                responser_.Status        = -1;
                responser_.StatusMessage = e.Message.ToString();
                responser_.Data          = null;

                return(responser_);
            }
        }
예제 #2
0
        /// <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_);
            }
        }
예제 #3
0
        /// <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_);
            }
        }
예제 #4
0
        /// <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_);
            }
        }
예제 #5
0
        /// <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_);
            }
        }