Example #1
0
        public List <Company> getAllCompanies()
        {
            if (SafeUser != null && SafeUser.isLoggedIn())
            {
                try
                {
                    SqlHelper   helper = new SqlHelper();
                    SecurityDAL sdal   = new SecurityDAL(helper);
                    if (sdal.hasPermission(SafeUser.SignIN.UID, "SELECT"))
                    {
                        helper.Close();
                        helper = new SqlHelper();
                        CompanyDAL dal       = new CompanyDAL(helper);
                        var        companies = dal.getAllcompanies();
                        helper.Close();
                        return(companies);
                    }
                }catch (Exception ex)
                {
                    log(ex);
                }
            }

            return(null);
        }
Example #2
0
 public void updateUser(String uid, String login, String password,
                        String firstName, String lastName,
                        String rsa, bool active = true,
                        String role             = null, String company = null)
 {
     if (isLoggedIn())
     {
         try
         {
             SqlHelper   helper = new SqlHelper();
             SecurityDAL sdal   = new SecurityDAL(helper);
             if (sdal.hasPermission(signIn.UID, "USER"))
             {
                 UserDAL dal = new UserDAL(helper);
                 dal.updateUser(uid, login, password, firstName, lastName,
                                rsa, active, role, company);
                 log(200, "Update is successfull");
             }
             else
             {
                 log(600, "(PW)Permission denied");
             }
         }
         catch (Exception ex)
         {
             log(ex);
         }
     }
 }
Example #3
0
        public User getUser(String uid)
        {
            if (isLoggedIn())
            {
                try
                {
                    SqlHelper   helper = new SqlHelper();
                    SecurityDAL sdal   = new SecurityDAL(helper);
                    if (sdal.hasPermission(SignIN.UID, "SELECT"))
                    {
                        helper.Close();
                        helper = new SqlHelper();
                        UserDAL dal  = new UserDAL(helper);
                        User    user = dal.getUser(uid);
                        helper.Close();
                        return(user);
                    }
                }catch (Exception ex)
                {
                    log(ex);
                }
            }

            return(null);
        }
Example #4
0
 public Role getUserRole(String uid)
 {
     if (SafeUser != null && SafeUser.isLoggedIn())
     {
         try
         {
             SqlHelper   helper = new SqlHelper();
             SecurityDAL sdal   = new SecurityDAL(helper);
             if (sdal.hasPermission(SafeUser.SignIN.UID, "USER"))
             {
                 RoleDAL dal = new RoleDAL(helper);
                 log(200, "A role is successfully got");
                 return(dal.getUserRole(uid));
             }
             else
             {
                 log(600, "Permission denied");
             }
         }catch (Exception ex)
         {
             log(ex);
         }
     }
     return(null);
 }
Example #5
0
        public void createInvoice(Record document)
        {
            if (SafeUser != null && SafeUser.isLoggedIn())
            {
                try
                {
                    SqlHelper   helper = new SqlHelper();
                    SecurityDAL sdal   = new SecurityDAL(helper);
                    if (sdal.hasPermission(SafeUser.SignIN.UID, "UPDATE") &&
                        sdal.hasPermission(SafeUser.SignIN.UID, "DELETE"))
                    {
                        ProductInventoryDAL       piDAL = new ProductInventoryDAL(helper);
                        ProductDocumentDAL        pdDAL = new ProductDocumentDAL(helper);
                        ProductTypeDAL            ptDAL = new ProductTypeDAL(helper);
                        InventoryDocumentationDAL idDAL = new InventoryDocumentationDAL(helper);
                        ProductType type = ptDAL.getProductType(document.ProductType);
                        if (type == null)
                        {
                            ptDAL.addProductType(document.ProductType);
                            type = ptDAL.getProductType(document.ProductType);
                        }

                        ProductInventory product = piDAL.getProduct(document.ProductName, type.TID);
                        if (product != null && product.TotalQuantity - document.ProductQuantity >= 0)
                        {
                            product.TotalQuantity += document.ProductQuantity;
                            piDAL.updateProduct(product);
                        }
                        else
                        {
                            log(404, "No such product");
                            return;
                        }

                        ProductDocument delivery = new ProductDocument();
                        delivery.Name        = document.DocumentName;
                        delivery.PrID        = product.PrID;
                        delivery.Description = document.Description;
                        delivery.Quantity    = document.ProductQuantity;
                        pdDAL.addDocument(delivery);

                        delivery = pdDAL.getDocument(document.DocumentName, product.PrID,
                                                     document.ProductQuantity, document.Description);
                        idDAL.assignDocument(SafeUser.SignIN.UID, delivery.DocumentID);
                    }
                }catch (Exception ex)
                {
                    log(ex);
                }
            }
        }
Example #6
0
        public List <Permiso> GetAllPermisosByIdUsuario(int idUsuario)
        {
            string         keyCache = KEY_PERIMISOS_BY_USUARIO_ID + idUsuario;
            List <Permiso> permisos = CacheLayer.Get <List <Permiso> >(keyCache);

            if (permisos == null)
            {
                permisos = SecurityDAL.GetAllPermisos(idUsuario);
                if (permisos != null)
                {
                    CacheLayer.Add(permisos, keyCache);
                }
            }

            return(permisos);
        }
Example #7
0
 /// <summary>Gets the list of roles.</summary>
 /// <returns>List of AdminRole.</returns>
 public List <SecurityRole> GetRoles()
 {
     Logging.LogDebugMessage("Method: GetRoles, MethodType: Get, Layer: SecurityBL, Parameters: No Input Parameters");
     using (SecurityDAL roles = new SecurityDAL())
     {
         try
         {
             return(roles.GetRoles());
         }
         catch (SqlException sqlEx)
         {
             Logging.LogErrorMessage("Method: GetRoles, Layer: SecurityBL, Stack Trace: " + sqlEx.ToString());
             throw;
         }
         catch (Exception ex)
         {
             Logging.LogErrorMessage("Method: GetRoles, Layer: SecurityBL, Stack Trace: " + ex.ToString());
             throw;
         }
     }
 }
Example #8
0
 /// <summary>Gets the list of all role privileges.</summary>
 /// <param name="roleId">The RoleID Object.</param>
 /// <returns>List of SecurityRole.</returns>
 public List <SecurityRole> GetAllRolePrivileges(RoleID roleId)
 {
     Logging.LogDebugMessage("Method: GetAllRolePrivileges, MethodType: Post, Layer: SecurityBL, Parameters: roleId = " + JsonConvert.SerializeObject(roleId));
     using (SecurityDAL rolePrivileges = new SecurityDAL())
     {
         try
         {
             return(rolePrivileges.GetAllRolePrivileges(roleId));
         }
         catch (SqlException sqlEx)
         {
             Logging.LogErrorMessage("Method: GetAllRolePrivileges, Layer: SecurityBL, Stack Trace: " + sqlEx.ToString());
             throw;
         }
         catch (Exception ex)
         {
             Logging.LogErrorMessage("Method: GetAllRolePrivileges, Layer: SecurityBL, Stack Trace: " + ex.ToString());
             throw;
         }
     }
 }
Example #9
0
 /// <summary>Gets the list of all role privileges by role identifier.</summary>
 /// <param name="roleId">The Integer Object.</param>
 /// <returns>List of SecurityRole.</returns>
 public List <SecurityRole> GetAllRolePrivilegesByRoleID(int roleId)
 {
     Logging.LogDebugMessage("Method: GetAllRolePrivilegesByRoleID, MethodType: Get, Layer: SecurityBL, Parameters: roleId = " + roleId);
     using (SecurityDAL rolePrivilegesById = new SecurityDAL())
     {
         try
         {
             return(rolePrivilegesById.GetAllRolePrivilegesByRoleID(roleId));
         }
         catch (SqlException sqlEx)
         {
             Logging.LogErrorMessage("Method: GetAllRolePrivilegesByRoleID, Layer: SecurityBL, Stack Trace: " + sqlEx.ToString());
             throw;
         }
         catch (Exception ex)
         {
             Logging.LogErrorMessage("Method: GetAllRolePrivilegesByRoleID, Layer: SecurityBL, Stack Trace: " + ex.ToString());
             throw;
         }
     }
 }
Example #10
0
 /// <summary>Gets the list of user roles by UserId.</summary>
 /// <param name="userId">The Long object.</param>
 /// <returns>List of UserRoles.</returns>
 public List <UserRoles> GetUserRoles(Int64 userId)
 {
     Logging.LogDebugMessage("Method: GetUserRoles, MethodType: Get, Layer: SecurityBL, Parameters: userId = " + userId.ToString());
     using (SecurityDAL userRoles = new SecurityDAL())
     {
         try
         {
             return(userRoles.GetUserRoles(userId));
         }
         catch (SqlException sqlEx)
         {
             Logging.LogErrorMessage("Method: GetUserRoles, Layer: SecurityBL, Stack Trace: " + sqlEx.ToString());
             throw;
         }
         catch (Exception ex)
         {
             Logging.LogErrorMessage("Method: GetUserRoles, Layer: SecurityBL, Stack Trace: " + ex.ToString());
             throw;
         }
     }
 }
Example #11
0
 /// <summary>Insert the UserRole in bulk.</summary>
 /// <param name="privilegeList">The List of InsertRoleUser Objects.</param>
 /// <param name="createdByUserID">The Integer Object for CreatedByUserId.</param>
 /// <param name="updatedByUserID">The Integer Object for UpdatedByUserId.</param>
 /// <returns>Boolean Object.</returns>
 public bool UserRoleInsertBulk(List <InsertRoleUser> privilegeList, int createdByUserID, int updatedByUserID)
 {
     Logging.LogDebugMessage("Method: UserRoleInsertBulk, MethodType: Post, Layer: SecurityBL, Parameters: privilegeList = " + JsonConvert.SerializeObject(privilegeList) + ",createdByUserID = " + createdByUserID.ToString() + ",updatedByUserID = " + updatedByUserID.ToString());
     using (SecurityDAL userRoleInsert = new SecurityDAL())
     {
         try
         {
             return(userRoleInsert.UserRoleInsertBulk(privilegeList, createdByUserID, updatedByUserID));
         }
         catch (SqlException sqlEx)
         {
             Logging.LogErrorMessage("Method: UserRoleInsertBulk, Layer: SecurityBL, Stack Trace: " + sqlEx.ToString());
             throw;
         }
         catch (Exception ex)
         {
             Logging.LogErrorMessage("Method: UserRoleInsertBulk, Layer: SecurityBL, Stack Trace: " + ex.ToString());
             throw;
         }
     }
 }
Example #12
0
 /// <summary>Insert or Update UserRole.</summary>
 /// <param name="privilegeList">The List of AddRoleUser Object.</param>
 /// <param name="rolePrivilege">The RoleUserlist Object.</param>
 /// <returns>Boolean Object.</returns>
 public bool UserRoleUpsert(List <AddRoleUser> privilegeList, RoleUserlist rolePrivilege)
 {
     Logging.LogDebugMessage("Method: UserRoleUpsert, MethodType: Post, Layer: SecurityBL, Parameters: privilegelist = " + JsonConvert.SerializeObject(privilegeList) + ",rolePrivilege = " + JsonConvert.SerializeObject(rolePrivilege));
     using (SecurityDAL useRoleUpsert = new SecurityDAL())
     {
         try
         {
             return(useRoleUpsert.UserRoleUpsert(privilegeList, rolePrivilege));
         }
         catch (SqlException sqlEx)
         {
             Logging.LogErrorMessage("Method: UserRoleUpsert, Layer: SecurityBL, Stack Trace: " + sqlEx.ToString());
             throw;
         }
         catch (Exception ex)
         {
             Logging.LogErrorMessage("Method: UserRoleUpsert, Layer: SecurityBL, Stack Trace: " + ex.ToString());
             throw;
         }
     }
 }
Example #13
0
 public void deleteRole(int rid)
 {
     if (SafeUser != null && SafeUser.isLoggedIn())
     {
         try
         {
             SqlHelper   helper = new SqlHelper();
             SecurityDAL sdal   = new SecurityDAL(helper);
             if (sdal.hasPermission(SafeUser.SignIN.UID, "USER"))
             {
                 RoleDAL dal = new RoleDAL(helper);
                 dal.removeRole(rid);
                 log(200, "Role is removed successfully");
             }
             else
             {
                 log(600, "(SP) Permission denied");
             }
         }catch (Exception ex)
         {
             log(ex);
         }
     }
 }
Example #14
0
 public void createRole(String name)
 {
     if (SafeUser != null && SafeUser.isLoggedIn())
     {
         try
         {
             SqlHelper   helper = new SqlHelper();
             SecurityDAL sdal   = new SecurityDAL(helper);
             if (sdal.hasPermission(SafeUser.SignIN.UID, "USER"))
             {
                 RoleDAL dal = new RoleDAL(helper);
                 dal.createRole(name);
                 log(200, "Role is created successfully");
             }
             else
             {
                 log(600, "(SR) Permission denied");
             }
         }catch (Exception ex)
         {
             log(ex);
         }
     }
 }
Example #15
0
 public List <Role> getAllRoles()
 {
     if (SafeUser != null && SafeUser.isLoggedIn())
     {
         try
         {
             SqlHelper   helper = new SqlHelper();
             SecurityDAL sdal   = new SecurityDAL(helper);
             if (sdal.hasPermission(SafeUser.SignIN.UID, "USER"))
             {
                 RoleDAL dal = new RoleDAL(new SqlHelper());
                 return(dal.getAllRoles());
             }
             else
             {
                 log(600, "(SP) Permission denied");
             }
         }catch (Exception ex)
         {
             log(ex);
         }
     }
     return(null);
 }
Example #16
0
 public void deleteUser(String uid)
 {
     if (isLoggedIn())
     {
         try
         {
             SqlHelper   helper = new SqlHelper();
             SecurityDAL sdal   = new SecurityDAL(helper);
             if (sdal.hasPermission(SignIN.UID, "USER"))
             {
                 UserDAL dal = new UserDAL(helper);
                 dal.removeUser(uid);
             }
             else
             {
                 log(600, "(PW)Permission denied");
             }
         }
         catch (Exception ex)
         {
             log(ex);
         }
     }
 }
Example #17
0
        public List <User> getAllUsers()
        {
            if (isLoggedIn())
            {
                try
                {
                    SqlHelper   helper = new SqlHelper();
                    SecurityDAL sdal   = new SecurityDAL(helper);
                    if (sdal.hasPermission(SignIN.UID, "SELECT"))
                    {
                        UserDAL     dal   = new UserDAL(helper);
                        List <User> users = dal.getAllUsers();
                        helper.Close();
                        return(users);
                    }
                }
                catch (Exception ex)
                {
                    log(ex);
                }
            }

            return(null);
        }
Example #18
0
 public void revokePermissions(int rid, int pid)
 {
     if (SafeUser != null && SafeUser.isLoggedIn())
     {
         try
         {
             SqlHelper   helper = new SqlHelper();
             SecurityDAL sdal   = new SecurityDAL(helper);
             if (sdal.hasPermission(SafeUser.SignIN.UID, "USER"))
             {
                 RolePermissionsDAL dal = new RolePermissionsDAL(helper);
                 dal.revokePermission(rid, pid);
                 log(200, "A permission is succesfully revoked");
             }
             else
             {
                 log(600, "(SP) Permission denied");
             }
         }catch (Exception ex)
         {
             log(ex);
         }
     }
 }
Example #19
0
 public SecurityBll()
 {
     mSecurityDAL = new SecurityDAL();
 }