/// <summary>Add roles to policy list based on access level</summary>
        public void CreatePolicy()
        {
            var roles = MH.GetListOfObjects(null, null, null, null, null, null, "RolesDB", "Roles").Result;

            if (roles != null)
            {
                foreach (var role in roles)
                {
                    var data = BsonSerializer.Deserialize <Roles>(role).LevelOfAccess;
                    foreach (var access in data)
                    {
                        if (access == "Level1Access")
                        {
                            level1RoleList.Add((BsonSerializer.Deserialize <Roles>(role).RoleName));
                        }
                        else if (access == "Level2Access")
                        {
                            level2RoleList.Add((BsonSerializer.Deserialize <Roles>(role).RoleName));
                        }
                        else if (access == "Level3Access")
                        {
                            level3RoleList.Add((BsonSerializer.Deserialize <Roles>(role).RoleName));
                        }
                    }
                }
            }
        }
예제 #2
0
 public ActionResult GetRolesByLevelOfAccess(string levelofaccess)
 {
     try
     {
         var getRoles = MH.GetListOfObjects(null, null, null, null, null, null, "RolesDB", "Roles").Result;
         if (getRoles != null)
         {
             List <Roles> rolesList = new List <Roles>();
             foreach (var role in getRoles)
             {
                 var    roleInfo    = BsonSerializer.Deserialize <Roles>(role);
                 string accessLevel = "Level" + levelofaccess + "Access";
                 if (roleInfo.LevelOfAccess.Contains(accessLevel))
                 {
                     rolesList.Add(roleInfo);
                 }
             }
             return(Ok(new ResponseData
             {
                 Code = "200",
                 Message = "Success",
                 Data = rolesList
             }));
         }
         else
         {
             return(BadRequest(new ResponseData
             {
                 Code = "404",
                 Message = "No roles found",
                 Data = null
             }));
         }
     }
     catch (Exception ex)
     {
         LoggerDataAccess.CreateLog("AdminContoller", "GetRolesByLevelOfAccess", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }
 public ActionResult GetOrdersOfUser(string username)
 {
     try
     {
         var orderList = MH.GetListOfObjects("UserName", username, null, null, null, null, "OrderDB", "OrderInfo").Result;
         if (orderList != null)
         {
             List <OrderInfo> orders = new List <OrderInfo>();
             foreach (var order in orderList)
             {
                 orders.Add(BsonSerializer.Deserialize <OrderInfo>(order));
             }
             return(Ok(new ResponseData
             {
                 Code = "200",
                 Message = "Success",
                 Data = orders
             }));
         }
         else
         {
             return(BadRequest(new ResponseData
             {
                 Code = "404",
                 Message = "No orders found",
                 Data = null
             }));
         }
     }
     catch (Exception ex)
     {
         LoggerDataAccess.CreateLog("OrderController", "GetOrdersOfUser", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }
예제 #4
0
 public ActionResult GetAllUsers()
 {
     try
     {
         var getlist = MH.GetListOfObjects(null, null, null, null, null, null, "Authentication", "Authentication").Result;
         if (getlist != null)
         {
             List <UserInfomation> userList = new List <UserInfomation>();
             foreach (var user in getlist)
             {
                 var     userInfo           = BsonSerializer.Deserialize <RegisterModel>(user);
                 var     billingAddressData = MH.GetSingleObject(Builders <BsonDocument> .Filter.Eq("UserName", userInfo.UserName) & Builders <BsonDocument> .Filter.Eq("BillingAddress", true), "UserInfo", "UserInfo").Result;
                 Address billingAddress     = new Address();
                 if (billingAddressData != null)
                 {
                     billingAddress = BsonSerializer.Deserialize <Address>(billingAddressData);
                 }
                 else
                 {
                     billingAddress = null;
                 }
                 var     shippingAddressData = MH.GetSingleObject(Builders <BsonDocument> .Filter.Eq("UserName", userInfo.UserName) & Builders <BsonDocument> .Filter.Eq("ShippingAddress", true), "UserInfo", "UserInfo").Result;
                 Address shippingAddress     = new Address();
                 if (shippingAddressData != null)
                 {
                     shippingAddress = BsonSerializer.Deserialize <Address>(shippingAddressData);
                 }
                 else
                 {
                     shippingAddress = null;
                 }
                 UserInfomation userInfomation = new UserInfomation
                 {
                     FullName        = userInfo.FullName,
                     PhoneNumber     = userInfo.PhoneNumber,
                     Email           = userInfo.Email,
                     BillingAddress  = billingAddress,
                     ShippingAddress = shippingAddress
                 };
                 userList.Add(userInfomation);
             }
             return(Ok(new ResponseData
             {
                 Code = "200",
                 Message = "Success",
                 Data = userList
             }));
         }
         else
         {
             return(BadRequest(new ResponseData
             {
                 Code = "404",
                 Message = "No users found",
                 Data = null
             }));
         }
     }
     catch (Exception ex)
     {
         LoggerDataAccess.CreateLog("AdminContoller", "GetAllUsers", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }