Beispiel #1
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);
                }
            }
        }
Beispiel #2
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);
 }
Beispiel #3
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);
        }
Beispiel #4
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);
         }
     }
 }
Beispiel #5
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);
        }
Beispiel #6
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);
         }
     }
 }
Beispiel #7
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);
         }
     }
 }
Beispiel #8
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);
 }
 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);
         }
     }
 }
Beispiel #10
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);
        }
Beispiel #11
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);
         }
     }
 }