예제 #1
0
        public static bool Update(Approval approval)
        {
            bool result = false;
            var conn = OracleDL.connect();
            OracleTransaction txn = conn.BeginTransaction(IsolationLevel.ReadCommitted);
            try
            {
                OracleCommand cmd = conn.CreateCommand();
                cmd.CommandText = @"UPDATE SYSTEMAPPROVALS SET
                                    APPROVEDBY = :approvedby, APPROVEDON = :approvedon, STATUS = :status
                                    WHERE ID = :id";
                cmd.Parameters.Add(":approvedby", OracleDbType.Varchar2, approval.ApprovedBy, ParameterDirection.Input);
                cmd.Parameters.Add(":approvedon", OracleDbType.Date, approval.ApprovedOn, ParameterDirection.Input);
                cmd.Parameters.Add(":status", OracleDbType.Varchar2, approval.Status, ParameterDirection.Input);
                cmd.Parameters.Add(":id", OracleDbType.Int32, approval.Id, ParameterDirection.Input);

                int rowsUpdated = cmd.ExecuteNonQuery();
                if (rowsUpdated > 0)
                {
                        result = true;
                        txn.Commit();
                }

                OracleDL.close(conn);

                return result;
            }
            catch (Exception ex)
            {
                txn.Rollback();
                throw ex;
            }
        }
예제 #2
0
        public static bool Save(Approval approval)
        {
            bool result = false;
            var conn = OracleDL.connect();
            OracleTransaction txn = conn.BeginTransaction(IsolationLevel.ReadCommitted);
            try
            {
                OracleCommand cmd = conn.CreateCommand();
                cmd.CommandText = "INSERT INTO SYSTEMAPPROVALS(TYPE, DETAILS, OBJ, REQUESTEDBY, REQUESTEDON, STATUS) VALUES(:type, :details, :obj, :requestedby, :requestedon, :status)";
                cmd.Parameters.Add(":type", OracleDbType.Varchar2, approval.Type, ParameterDirection.Input);
                cmd.Parameters.Add(":details", OracleDbType.Varchar2, approval.Details, ParameterDirection.Input);
                cmd.Parameters.Add(":obj", OracleDbType.Varchar2, approval.Obj, ParameterDirection.Input);
                cmd.Parameters.Add(":requestedby", OracleDbType.Varchar2, approval.RequestedBy, ParameterDirection.Input);
                cmd.Parameters.Add(":requestedon", OracleDbType.Date, approval.RequestedOn, ParameterDirection.Input);
                cmd.Parameters.Add(":status", OracleDbType.Varchar2, approval.Status, ParameterDirection.Input);

                int rowsInserted = cmd.ExecuteNonQuery();
                if (rowsInserted > 0)
                {
                    result = true;
                    txn.Commit();
                }

                OracleDL.close(conn);

                return result;
            }
            catch (Exception ex)
            {
                txn.Rollback();
                throw ex;
            }
        }
예제 #3
0
        public static Response Save(User user, string username, bool overrideApproval)
        {
            try
            {
                if (UserDL.UserExists(user.Username))
                {
                    return new Response
                    {
                        SuccessMsg = string.Empty,
                        ErrorMsg = string.Format("User with username {0} already exists.", user.Username)
                    };
                }
                else
                {
                    if (!overrideApproval)
                    {
                        bool logForApproval = ApprovalConfigurationDL.RetrieveByType(StatusUtil.GetDescription(StatusUtil.ApprovalType.CreateUser)).Approve;

                        if (logForApproval)
                        {
                            Approval approvalObj = new Approval();
                            approvalObj.Type = StatusUtil.GetDescription(StatusUtil.ApprovalType.CreateUser);
                            approvalObj.Details = JsonConvert.SerializeObject(user);
                            approvalObj.Obj = JsonConvert.SerializeObject(user);
                            approvalObj.RequestedBy = username;
                            approvalObj.RequestedOn = System.DateTime.Now;
                            approvalObj.Status = StatusUtil.ApprovalStatus.Pending.ToString();

                            if (ApprovalDL.Save(approvalObj))
                            {
                                return new Response
                                {
                                    SuccessMsg = "User successfully logged for approval",
                                    ErrorMsg = string.Empty
                                };
                            }
                            else
                            {
                                return new Response
                                {
                                    SuccessMsg = string.Empty,
                                    ErrorMsg = "Operation failed"
                                };
                            }
                        }
                        else
                        {
                            if (UserDL.Save(user))
                            {
                                AuditTrail obj = new AuditTrail();
                                obj.Type = StatusUtil.GetDescription(StatusUtil.ApprovalType.CreateUser);
                                obj.Details = JsonConvert.SerializeObject(user);
                                obj.RequestedBy = username;
                                obj.RequestedOn = System.DateTime.Now;
                                obj.ApprovedBy = username;
                                obj.ApprovedOn = System.DateTime.Now;
                                AuditTrailDL.Save(obj);

                                return new Response
                                {
                                    SuccessMsg = "User added successfully",
                                    ErrorMsg = string.Empty
                                };
                            }
                            else
                            {
                                return new Response
                                {
                                    SuccessMsg = string.Empty,
                                    ErrorMsg = "Operation failed"
                                };
                            }
                        }
                    }
                    else
                    {
                        if (UserDL.Save(user))
                        {
                            return new Response
                            {
                                SuccessMsg = "User added successfully",
                                ErrorMsg = string.Empty
                            };
                        }
                        else
                        {
                            return new Response
                            {
                                SuccessMsg = string.Empty,
                                ErrorMsg = "Operation failed"
                            };
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorHandler.WriteError(ex);
                return new Response
                {
                    SuccessMsg = string.Empty,
                    ErrorMsg = ex.Message
                };
            }
        }
예제 #4
0
        public static Response Update(Function function, string username, bool overrideApproval)
        {
            try
            {
                if (!overrideApproval)
                {
                    bool logForApproval = ApprovalConfigurationDL.RetrieveByType(StatusUtil.GetDescription(StatusUtil.ApprovalType.UpdateFunction)).Approve;

                    if (logForApproval)
                    {
                        Approval approvalObj = new Approval();
                        approvalObj.Type = StatusUtil.GetDescription(StatusUtil.ApprovalType.UpdateFunction);
                        approvalObj.Details = JsonConvert.SerializeObject(function);
                        approvalObj.Obj = JsonConvert.SerializeObject(function);
                        approvalObj.RequestedBy = username;
                        approvalObj.RequestedOn = System.DateTime.Now;
                        approvalObj.Status = StatusUtil.ApprovalStatus.Pending.ToString();

                        if (ApprovalDL.Save(approvalObj))
                        {
                            return new Response
                            {
                                SuccessMsg = "Function successfully logged for approval",
                                ErrorMsg = string.Empty
                            };
                        }
                        else
                        {
                            return new Response
                            {
                                SuccessMsg = string.Empty,
                                ErrorMsg = "Operation failed"
                            };
                        }
                    }
                    else
                    {
                        if (FunctionDL.Update(function))
                        {
                            AuditTrail obj = new AuditTrail();
                            obj.Type = StatusUtil.GetDescription(StatusUtil.ApprovalType.UpdateFunction);
                            obj.Details = JsonConvert.SerializeObject(function);
                            obj.RequestedBy = username;
                            obj.RequestedOn = System.DateTime.Now;
                            obj.ApprovedBy = username;
                            obj.ApprovedOn = System.DateTime.Now;
                            AuditTrailDL.Save(obj);

                            return new Response
                            {
                                SuccessMsg = "Function updated successfully",
                                ErrorMsg = string.Empty
                            };
                        }
                        else
                        {
                            return new Response
                            {
                                SuccessMsg = string.Empty,
                                ErrorMsg = "Operation failed"
                            };
                        }
                    }
                }
                else
                {
                    if (FunctionDL.Update(function))
                    {
                        return new Response
                        {
                            SuccessMsg = "Function updated successfully",
                            ErrorMsg = string.Empty
                        };
                    }
                    else
                    {
                        return new Response
                        {
                            SuccessMsg = string.Empty,
                            ErrorMsg = "Operation failed"
                        };
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorHandler.WriteError(ex);
                return new Response
                {
                    SuccessMsg = string.Empty,
                    ErrorMsg = ex.Message
                };
            }
        }
예제 #5
0
        private static Response UpdateObject(Approval app)
        {
            var approval = ApprovalDL.RetrieveById(app.Id);

            var response = new Response();

            if (approval.Type.Equals(StatusUtil.GetDescription(StatusUtil.ApprovalType.CreateFunction)))
            {
                var obj = JsonConvert.DeserializeObject<Function>(approval.Obj);
                response = FunctionPL.Save(obj, string.Empty, true);
            }
            else if (approval.Type.Equals(StatusUtil.GetDescription(StatusUtil.ApprovalType.UpdateFunction)))
            {
                var obj = JsonConvert.DeserializeObject<Function>(approval.Obj);
                response = FunctionPL.Update(obj, string.Empty, true);
            }
            else if (approval.Type.Equals(StatusUtil.GetDescription(StatusUtil.ApprovalType.CreateRole)))
            {
                var obj = JsonConvert.DeserializeObject<Role>(approval.Obj);
                response = RolePL.Save(obj, string.Empty, true);
            }
            else if (approval.Type.Equals(StatusUtil.GetDescription(StatusUtil.ApprovalType.UpdateRole)))
            {
                var obj = JsonConvert.DeserializeObject<Role>(approval.Obj);
                response = RolePL.Update(obj, string.Empty, true);
            }
            else if (approval.Type.Equals(StatusUtil.GetDescription(StatusUtil.ApprovalType.CreateUser)))
            {
                var obj = JsonConvert.DeserializeObject<User>(approval.Obj);
                response = UserPL.Save(obj, string.Empty, true);
            }
            else if (approval.Type.Equals(StatusUtil.GetDescription(StatusUtil.ApprovalType.UpdateUser)))
            {
                var obj = JsonConvert.DeserializeObject<User>(approval.Obj);
                response = UserPL.Update(obj, string.Empty, true);
            }
            else if (approval.Type.Equals(StatusUtil.GetDescription(StatusUtil.ApprovalType.ResetCardPrintStatus)))
            {
                var obj = JsonConvert.DeserializeObject<Card>(approval.Obj);
                response = CardPL.Update(obj, string.Empty, true);
            }

            AuditTrail audit = new AuditTrail();
            audit.Type = approval.Type;
            audit.Details = approval.Details;
            audit.RequestedBy = approval.RequestedBy;
            audit.RequestedOn = approval.RequestedOn;
            audit.ApprovedBy = approval.ApprovedBy;
            audit.ApprovedOn = System.DateTime.Now;
            AuditTrailDL.Save(audit);

            return response;
        }
예제 #6
0
        public static Response Update(Approval approval)
        {
            try
            {
                if (ApprovalDL.Update(approval))
                {
                    if (approval.Status == StatusUtil.ApprovalStatus.Approved.ToString())
                    {
                        var operation = new Response();

                        operation = UpdateObject(approval);

                        return operation;
                    }
                    else
                    {
                        return new Response
                        {
                            SuccessMsg = "Request declined successfully",
                            ErrorMsg = string.Empty
                        };
                    }
                }
                else
                {
                    return new Response
                    {
                        SuccessMsg = string.Empty,
                        ErrorMsg = "Operation failed"
                    };
                }
            }
            catch (Exception ex)
            {
                ErrorHandler.WriteError(ex);
                return new Response
                {
                    SuccessMsg = string.Empty,
                    ErrorMsg = ex.Message
                };
            }
        }