Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="collection"></param>
        /// <param name="filterField1"></param>
        /// <param name="filterData1"></param>
        /// <param name="filterField2"></param>
        /// <param name="filterData2"></param>
        /// <returns></returns>
        public static async Task <bool?> CheckForData(IMongoCollection <BsonDocument> collection, string filterField1, dynamic filterData1, string filterField2, dynamic filterData2)
        {
            try
            {
                if (filterField1 == null & filterField2 == null)
                {
                    filter = FilterDefinition <BsonDocument> .Empty;
                }
                else if (filterField1 != null & filterField2 == null)
                {
                    filter = Builders <BsonDocument> .Filter.Eq(filterField1, filterData1);
                }
                else if (filterField1 != null & filterField2 != null)
                {
                    filter = Builders <BsonDocument> .Filter.Eq(filterField1, filterData1) & Builders <BsonDocument> .Filter.Eq(filterField2, filterData2);
                }
                IAsyncCursor <BsonDocument> cursor = await collection.FindAsync(filter);

                if (cursor.FirstOrDefault() != null)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                SL.CreateLog("MongoHelper", "GetSingleObject", ex.Message);
                return(null);
            }
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="collection"></param>
        /// <param name="filterField1"></param>
        /// <param name="filterData1"></param>
        /// <param name="filterField2"></param>
        /// <param name="filterData2"></param>
        /// <returns></returns>
        public static async Task <List <BsonDocument> > GetListOfObjects(IMongoCollection <BsonDocument> collection, string filterField1, dynamic filterData1, string filterField2, dynamic filterData2)
        {
            try
            {
                if (filterField1 == null & filterField2 == null)
                {
                    filter = Builders <BsonDocument> .Filter.Eq("IsActive", true);
                }
                else if (filterField1 != null & filterField2 == null)
                {
                    filter = Builders <BsonDocument> .Filter.Eq(filterField1, filterData1) & Builders <BsonDocument> .Filter.Eq("IsActive", true);
                }
                else if (filterField1 != null & filterField2 != null)
                {
                    filter = Builders <BsonDocument> .Filter.Eq(filterField1, filterData1) & Builders <BsonDocument> .Filter.Eq(filterField2, filterData2) & Builders <BsonDocument> .Filter.Eq("IsActive", true);
                }
                IAsyncCursor <BsonDocument> cursor = await collection.FindAsync(filter);

                return(cursor.ToList());
            }
            catch (Exception ex)
            {
                SL.CreateLog("MongoHelper", "GetListOfObjects", ex.Message);
                return(null);
            }
        }
Exemple #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="collection"></param>
        /// <param name="filterField1"></param>
        /// <param name="filterData1"></param>
        /// <param name="filterField2"></param>
        /// <param name="filterData2"></param>
        /// <returns></returns>
        public static async Task <bool?> DeleteSingleObject(IMongoCollection <BsonDocument> collection, string filterField1, dynamic filterData1, string filterField2, dynamic filterData2)
        {
            try
            {
                if (filterField1 == null & filterField2 == null)
                {
                    filter = FilterDefinition <BsonDocument> .Empty;
                }
                else if (filterField1 != null & filterField2 == null)
                {
                    filter = Builders <BsonDocument> .Filter.Eq(filterField1, filterData1);
                }
                else if (filterField1 != null & filterField2 != null)
                {
                    filter = Builders <BsonDocument> .Filter.Eq(filterField1, filterData1) & Builders <BsonDocument> .Filter.Eq(filterField2, filterData2);
                }
                var cursor = await collection.DeleteOneAsync(filter);

                return(true);
            }
            catch (Exception ex)
            {
                SL.CreateLog("MongoHelper", "DeleteSingleObject", ex.Message);
                return(null);
            }
        }
Exemple #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="collection"></param>
 /// <param name="filterField1"></param>
 /// <param name="filterData1"></param>
 /// <param name="filterField2"></param>
 /// <param name="filterData2"></param>
 /// <param name="update"></param>
 /// <returns></returns>
 public static BsonDocument UpdateSingleObject(IMongoCollection <BsonDocument> collection, string filterField1, dynamic filterData1, string filterField2, dynamic filterData2, UpdateDefinition <BsonDocument> update)
 {
     try
     {
         if (filterField1 == null & filterField2 == null)
         {
             filter = FilterDefinition <BsonDocument> .Empty;
         }
         else if (filterField1 != null & filterField2 == null)
         {
             filter = Builders <BsonDocument> .Filter.Eq(filterField1, filterData1);
         }
         else if (filterField1 != null & filterField2 != null)
         {
             filter = Builders <BsonDocument> .Filter.Eq(filterField1, filterData1) & Builders <BsonDocument> .Filter.Eq(filterField2, filterData2);
         }
         BsonDocument cursor = collection.FindOneAndUpdate(filter, update);
         return(cursor);
     }
     catch (Exception ex)
     {
         SL.CreateLog("MongoHelper", "GetSingleObject", ex.Message);
         return(null);
     }
 }
Exemple #5
0
 public ActionResult GetInfoOfVehicle(string vehicleId)
 {
     try
     {
         var getVehicle = MH.GetSingleObject(vehicleinfo_collection, "VehicleId", vehicleId, null, null).Result;
         if (getVehicle != null)
         {
             var vehicleInfo = BsonSerializer.Deserialize <VehicleInfo>(getVehicle);
             return(Ok(new ResponseData
             {
                 Code = "200",
                 Message = "Success",
                 Data = vehicleInfo
             }));
         }
         else
         {
             return(BadRequest(new ResponseData
             {
                 Code = "404",
                 Message = "Vehicle not found"
             }));
         }
     }
     catch (Exception ex)
     {
         SL.CreateLog("VehicleController", "GetInfoOfVehicle", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }
Exemple #6
0
        public async Task <ActionResult> UpdateVehicleMaintenanceInfo([FromBody] VehicleMaintenanceInfo data, string username, string vehicleId)
        {
            try
            {
                if (data != null && username != null && vehicleId != null)
                {
                    var delete = await MH.DeleteSingleObject(vehiclemaintenanceinfo_collection, "VehicleId", vehicleId, null, null);

                    if (delete != null)
                    {
                        var insert = MH.InsertNewVehicleMaintenanceInfo(data, vehiclemaintenanceinfoCollection);

                        if (insert != null)
                        {
                            var getVehicle = MH.GetSingleObject(vehiclemaintenanceinfo_collection, "VehicleId", vehicleId, null, null).Result;
                            AL.CreateLog(username, "UpdateVehicleMaintenanceInfo", BsonSerializer.Deserialize <VehicleMaintenanceInfo>(getVehicle), data, activitylog_collection);
                            return(Ok(new ResponseData
                            {
                                Code = "200",
                                Message = "Updated"
                            }));
                        }
                        else
                        {
                            return(BadRequest(new ResponseData
                            {
                                Code = "401",
                                Message = "Update failed"
                            }));
                        }
                    }
                    else
                    {
                        return(BadRequest(new ResponseData
                        {
                            Code = "404",
                            Message = "Vehicle maintenance info not found"
                        }));
                    }
                }
                else
                {
                    return(BadRequest(new ResponseData
                    {
                        Code = "402",
                        Message = "Bad request"
                    }));
                }
            }
            catch (Exception ex)
            {
                SL.CreateLog("VehicleController", "UpdateVehicleMaintenanceInfo", ex.Message);
                return(BadRequest(new ResponseData
                {
                    Code = "400",
                    Message = "Failed",
                    Data = ex.Message
                }));
            }
        }
        public async Task <ActionResult> Register([FromBody] RegisterModel data)
        {
            try
            {
                var getUser = MH.GetSingleObject(users_collection, "UserName", data.UserName, null, null).Result;
                if (getUser == null)
                {
                    data.Password     = passwordHasher.HashPassword(data, data.Password);
                    data.UserRole     = "User";
                    data.UserVerified = false;
                    data.IsActive     = false;
                    await usersCollection.InsertOneAsync(data);

                    AL.CreateLog(null, "Register", null, data, activitylog_collection);
                    return(Ok(new ResponseData
                    {
                        Code = "200",
                        Message = "Registered"
                    }));
                }
                else
                {
                    var userDetails = BsonSerializer.Deserialize <RegisterModel>(getUser);
                    if (userDetails.IsActive == true)
                    {
                        return(BadRequest(new ResponseData
                        {
                            Code = "401",
                            Message = "User already registered"
                        }));
                    }
                    else
                    {
                        var updateDefinition = Builders <BsonDocument> .Update.Set("IsActive", true).Set("UserVerified", false);

                        var update  = MH.UpdateSingleObject(users_collection, "UserName", data.UserName, null, null, updateDefinition);
                        var details = userDetails;
                        details.IsActive     = true;
                        details.UserVerified = false;
                        AL.CreateLog(null, "Register", userDetails, details, activitylog_collection);
                        return(BadRequest(new ResponseData
                        {
                            Code = "402",
                            Message = "User already registered and is made active"
                        }));
                    }
                }
            }
            catch (Exception ex)
            {
                SL.CreateLog("AuthController", "Register", ex.Message);
                return(BadRequest(new ResponseData
                {
                    Code = "400",
                    Message = "Failed",
                    Data = ex.Message
                }));
            }
        }
        public ActionResult UpdateRole([FromBody] ExampleModel_Roles data, string username, string rolename)
        {
            try
            {
                if (data != null && username != null && rolename != null)
                {
                    var getRole = MH.GetSingleObject(roles_collection, "RoleName", rolename, null, null).Result;
                    if (getRole != null)
                    {
                        if (data.LevelOfAccess != null)
                        {
                            var updateDefinition = Builders <BsonDocument> .Update.Set("LevelOfAccess", data.LevelOfAccess);

                            var update = MH.UpdateSingleObject(roles_collection, "RoleName", rolename, null, null, updateDefinition);
                        }
                        if (data.IsActive != null)
                        {
                            var updateDefinition = Builders <BsonDocument> .Update.Set("IsActive", data.IsActive);

                            var update = MH.UpdateSingleObject(roles_collection, "RoleName", rolename, null, null, updateDefinition);
                        }
                        AL.CreateLog(username, "UpdateRole", BsonSerializer.Deserialize <Roles>(getRole), data, activitylog_collection);
                        return(Ok(new ResponseData
                        {
                            Code = "200",
                            Message = "Updated"
                        }));
                    }
                    else
                    {
                        return(BadRequest(new ResponseData
                        {
                            Code = "404",
                            Message = "Role not found"
                        }));
                    }
                }
                else
                {
                    return(BadRequest(new ResponseData
                    {
                        Code = "401",
                        Message = "Bad request"
                    }));
                }
            }
            catch (Exception ex)
            {
                SL.CreateLog("AdminController", "UpdateRole", ex.Message);
                return(BadRequest(new ResponseData
                {
                    Code = "400",
                    Message = "Failed",
                    Data = ex.Message
                }));
            }
        }
Exemple #9
0
 public ActionResult GetTripInfoWithUnPaidBalanceAmount()
 {
     try
     {
         var getTrips = MH.GetListOfObjects(tripinfo_collection, "IsActive", true, null, null).Result;
         if (getTrips != null)
         {
             List <TripInfo> infoList = new List <TripInfo>();
             foreach (var info in getTrips)
             {
                 var data = BsonSerializer.Deserialize <TripInfo>(info);
                 if (data.BalanceAmount > 0)
                 {
                     infoList.Add(data);
                 }
             }
             if (infoList != null)
             {
                 return(Ok(new ResponseData
                 {
                     Code = "200",
                     Message = "Success",
                     Data = infoList
                 }));
             }
             else
             {
                 return(BadRequest(new ResponseData
                 {
                     Code = "401",
                     Message = "No trip with balance amount unpaid is found"
                 }));
             }
         }
         else
         {
             return(BadRequest(new ResponseData
             {
                 Code = "404",
                 Message = "No trip infos found"
             }));
         }
     }
     catch (Exception ex)
     {
         SL.CreateLog("TripController", "GetTripInfoWithUnPaidBalanceAmount", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }
Exemple #10
0
        public async Task <ActionResult> UpdateTripInfo([FromBody] TripInfo data, string username, string tripId)
        {
            try
            {
                if (data != null && username != null && tripId != null)
                {
                    var getTrip = MH.GetSingleObject(tripinfo_collection, "TripId", tripId, null, null).Result;
                    if (getTrip != null)
                    {
                        var delete = await MH.DeleteSingleObject(tripinfo_collection, "TripId", tripId, null, null);

                        var tripData = BsonSerializer.Deserialize <TripInfo>(getTrip);
                        data.Id     = tripData.Id;
                        data.TripId = tripData.TripId;
                        await trip_db.GetCollection <TripInfo>("TripInfo").InsertOneAsync(data);

                        AL.CreateLog(username, "UpdateTripInfo", BsonSerializer.Deserialize <TripInfo>(getTrip), data, activitylog_collection);
                        return(Ok(new ResponseData
                        {
                            Code = "200",
                            Message = "Updated"
                        }));
                    }
                    else
                    {
                        return(BadRequest(new ResponseData
                        {
                            Code = "404",
                            Message = "Trip info not found"
                        }));
                    }
                }
                else
                {
                    return(BadRequest(new ResponseData
                    {
                        Code = "401",
                        Message = "Bad Request"
                    }));
                }
            }
            catch (Exception ex)
            {
                SL.CreateLog("TripController", "UpdateTripInfo", ex.Message);
                return(BadRequest(new ResponseData
                {
                    Code = "400",
                    Message = "Failed",
                    Data = ex.Message
                }));
            }
        }
 /// <summary>Get ip config from xml</summary>
 public static string GetIpConfig(IMongoCollection <ServerSideLoggerModel> log_collection)
 {
     try
     {
         var result = ReadXML().Elements("ipconfig").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("jt_transport");
         return(result.First().Value);
     }
     catch (Exception ex)
     {
         SL.CreateLog("GlobalHelper", "GetIpConfig", ex.Message);
         return(null);
     }
 }
Exemple #12
0
        public ActionResult MakeVehicleInfoActive(string username, string vehicleId)
        {
            try
            {
                if (username != null && vehicleId != null)
                {
                    var getVehicle = MH.GetSingleObject(vehicleinfo_collection, "VehicleId", vehicleId, null, null).Result;
                    if (getVehicle != null)
                    {
                        var updateDefinition = Builders <BsonDocument> .Update.Set("IsActive", true);

                        update = MH.UpdateSingleObject(vehicleinfo_collection, "VehicleId", vehicleId, null, null, updateDefinition);
                        var data = BsonSerializer.Deserialize <VendorInfo>(getVehicle);
                        data.IsActive = true;
                        AL.CreateLog(username, "MakeVehicleInfoActive", BsonSerializer.Deserialize <VendorInfo>(getVehicle), data, activitylog_collection);
                        return(Ok(new ResponseData
                        {
                            Code = "200",
                            Message = "Vehicle info made active"
                        }));
                    }
                    else
                    {
                        return(BadRequest(new ResponseData
                        {
                            Code = "404",
                            Message = "Vehicle info not found"
                        }));
                    }
                }
                else
                {
                    return(BadRequest(new ResponseData
                    {
                        Code = "401",
                        Message = "Bad request"
                    }));
                }
            }
            catch (Exception ex)
            {
                SL.CreateLog("VehicleController", "MakeVehicleInfoActive", ex.Message);
                return(BadRequest(new ResponseData
                {
                    Code = "400",
                    Message = "Failed",
                    Data = ex.Message
                }));
            }
        }
Exemple #13
0
        public ActionResult MakeTripInfoInActive(string username, string tripId)
        {
            try
            {
                if (tripId != null && username != null)
                {
                    var getTrip = MH.GetSingleObject(tripinfo_collection, "TripId", tripId, null, null).Result;
                    if (getTrip != null)
                    {
                        var updateDefinition = Builders <BsonDocument> .Update.Set("IsActive", false);

                        var update = MH.UpdateSingleObject(tripinfo_collection, "TripId", tripId, null, null, updateDefinition);
                        var data   = BsonSerializer.Deserialize <TripInfo>(getTrip);
                        data.IsActive = false;
                        AL.CreateLog(username, "MakeTripInfoInActive", BsonSerializer.Deserialize <TripInfo>(getTrip), data, activitylog_collection);
                        return(Ok(new ResponseData
                        {
                            Code = "200",
                            Message = "Trip info made inactive"
                        }));
                    }
                    else
                    {
                        return(BadRequest(new ResponseData
                        {
                            Code = "404",
                            Message = "Trip info not found"
                        }));
                    }
                }
                else
                {
                    return(BadRequest(new ResponseData
                    {
                        Code = "401",
                        Message = "Bad Request"
                    }));
                }
            }
            catch (Exception ex)
            {
                SL.CreateLog("TripController", "MakeTripInfoInActive", ex.Message);
                return(BadRequest(new ResponseData
                {
                    Code = "400",
                    Message = "Failed",
                    Data = ex.Message
                }));
            }
        }
 /// <summary>To read XML</summary>
 public static XElement ReadXML()
 {
     try
     {
         var dir    = GetCurrentDir();
         var xmlStr = File.ReadAllText(Path.Combine(dir, "Keys.xml"));
         return(XElement.Parse(xmlStr));
     }
     catch (Exception ex)
     {
         SL.CreateLog("GlobalHelper", "ReadXML", ex.Message);
         return(null);
     }
 }
        public ActionResult MakeRoleActive(string username, string rolename)
        {
            try
            {
                if (username != null && rolename != null)
                {
                    var getRole = MH.GetSingleObject(roles_collection, "RoleName", rolename, null, null).Result;
                    if (getRole != null)
                    {
                        var updateDefinition = Builders <BsonDocument> .Update.Set("IsActive", true);

                        update = MH.UpdateSingleObject(roles_collection, "RoleName", rolename, null, null, updateDefinition);
                        var data = BsonSerializer.Deserialize <Roles>(getRole);
                        data.IsActive = true;
                        AL.CreateLog(username, "MakeRoleActive", BsonSerializer.Deserialize <Roles>(getRole), data, activitylog_collection);
                        return(Ok(new ResponseData
                        {
                            Code = "200",
                            Message = "Role made active"
                        }));
                    }
                    else
                    {
                        return(BadRequest(new ResponseData
                        {
                            Code = "404",
                            Message = "Role not found"
                        }));
                    }
                }
                else
                {
                    return(BadRequest(new ResponseData
                    {
                        Code = "401",
                        Message = "Bad Request"
                    }));
                }
            }
            catch (Exception ex)
            {
                SL.CreateLog("AdminController", "MakeRoleActive", ex.Message);
                return(BadRequest(new ResponseData
                {
                    Code = "400",
                    Message = "Failed",
                    Data = ex.Message
                }));
            }
        }
 public ActionResult UploadImageToS3([FromForm] ImageData data)
 {
     try
     {
         if (data != null)
         {
             var objectName = data.ObjectName + ".jpg";
             var result     = AmazonHelper.UploadImageToS3(data.Image, data.BucketName, objectName);
             var Image_Url  = AmazonHelper.GetS3Object(data.BucketName, objectName);
             if (result.Result == true)
             {
                 return(Ok(new ResponseData
                 {
                     Code = "200",
                     Message = "Image uploaded",
                     Data = Image_Url
                 }));
             }
             else
             {
                 return(BadRequest(new ResponseData
                 {
                     Code = "401",
                     Message = "Image upload failed",
                     Data = null
                 }));
             }
         }
         else
         {
             return(BadRequest(new ResponseData
             {
                 Code = "404",
                 Message = "Image upload data not found",
                 Data = null
             }));
         }
     }
     catch (Exception ex)
     {
         SL.CreateLog("AdminContoller", "UploadImageToS3", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }
 public ActionResult GetInfoOfdriver(string driverId)
 {
     try
     {
         if (driverId != null)
         {
             var getDriver = MH.GetSingleObject(driverinfo_collection, "DriverId", driverId, null, null).Result;
             if (getDriver != null)
             {
                 var driverInfo = BsonSerializer.Deserialize <DriverInfo>(getDriver);
                 return(Ok(new ResponseData
                 {
                     Code = "200",
                     Message = "Success",
                     Data = driverInfo
                 }));
             }
             else
             {
                 return(BadRequest(new ResponseData
                 {
                     Code = "404",
                     Message = "Driver not found"
                 }));
             }
         }
         else
         {
             return(BadRequest(new ResponseData
             {
                 Code = "401",
                 Message = "Bad Request"
             }));
         }
     }
     catch (Exception ex)
     {
         SL.CreateLog("DriverController", "GetInfoOfDriver", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }
Exemple #18
0
 /// <summary>Get the access-token by username and password</summary>
 /// <param name="parameters"></param>
 /// <param name="_repo"></param>
 /// <param name="_settings"></param>
 /// <param name="users_collection"></param>
 public static ResponseData DoPassword(Parameters parameters, IRTokenRepository _repo, IOptions <Audience> _settings, IMongoCollection <BsonDocument> users_collection)
 {
     try
     {
         var refresh_token = Guid.NewGuid().ToString().Replace("-", "");
         var rToken        = new RToken
         {
             ClientId     = parameters.username,
             RefreshToken = refresh_token,
             Id           = Guid.NewGuid().ToString(),
             IsStop       = 0
         };
         if (_repo.AddToken(rToken).Result)
         {
             dynamic UserInfo = new System.Dynamic.ExpandoObject();
             UserInfo.FirstName = parameters.fullname;
             UserInfo.UserName  = parameters.username;
             return(new ResponseData
             {
                 Code = "999",
                 Message = "OK",
                 Content = UserInfo,
                 Data = GetJwt(parameters.username, refresh_token, _settings, BsonSerializer.Deserialize <RegisterModel>(MH.GetSingleObject(users_collection, "UserName", parameters.username, null, null).Result).UserRole)
             });
         }
         else
         {
             return(new ResponseData
             {
                 Code = "909",
                 Message = "can not add token to database",
                 Data = null
             });
         }
     }
     catch (Exception ex)
     {
         SL.CreateLog("TokenHelper", "DoPassword", ex.Message);
         return(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = null
         });
     }
 }
Exemple #19
0
 public ActionResult GetInfoOfTrip(string tripId)
 {
     try
     {
         if (tripId != null)
         {
             var getTrip = MH.GetSingleObject(tripinfo_collection, "TripId", tripId, null, null).Result;
             if (getTrip != null)
             {
                 var tripInfo = BsonSerializer.Deserialize <TripInfo>(getTrip);
                 return(Ok(new ResponseData
                 {
                     Code = "200",
                     Message = "Success",
                     Data = tripInfo
                 }));
             }
             else
             {
                 return(BadRequest(new ResponseData
                 {
                     Code = "404",
                     Message = "Trip not found"
                 }));
             }
         }
         else
         {
             return(BadRequest(new ResponseData
             {
                 Code = "401",
                 Message = "Bad Request"
             }));
         }
     }
     catch (Exception ex)
     {
         SL.CreateLog("TripController", "GetInfoOfTrip", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }
 public ActionResult GetInfoOfOffice(string officeId)
 {
     try
     {
         if (officeId != null)
         {
             var getOffice = MH.GetSingleObject(officeinfo_collection, "OfficeId", officeId, null, null).Result;
             if (getOffice != null)
             {
                 var officeInfo = BsonSerializer.Deserialize <OfficeInfo>(getOffice);
                 return(Ok(new ResponseData
                 {
                     Code = "200",
                     Message = "Success",
                     Data = officeInfo
                 }));
             }
             else
             {
                 return(BadRequest(new ResponseData
                 {
                     Code = "404",
                     Message = "Office not found"
                 }));
             }
         }
         else
         {
             return(BadRequest(new ResponseData
             {
                 Code = "401",
                 Message = "Bad Request"
             }));
         }
     }
     catch (Exception ex)
     {
         SL.CreateLog("OfficeController", "GetInfoOfOffice", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }
 public ActionResult GetRole(string rolename)
 {
     try
     {
         if (rolename != null)
         {
             var getRole = MH.GetSingleObject(roles_collection, "RoleName", rolename, null, null).Result;
             if (getRole != null)
             {
                 return(Ok(new ResponseData
                 {
                     Code = "200",
                     Message = "Success",
                     Data = BsonSerializer.Deserialize <Roles>(getRole)
                 }));
             }
             else
             {
                 return(BadRequest(new ResponseData
                 {
                     Code = "404",
                     Message = "Role not found"
                 }));
             }
         }
         else
         {
             return(BadRequest(new ResponseData
             {
                 Code = "401",
                 Message = "Bad Request"
             }));
         }
     }
     catch (Exception ex)
     {
         SL.CreateLog("AdminController", "GetRole", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }
        public ActionResult GetJWT([FromQuery] Parameters parameters)
        {
            try
            {
                if (parameters == null)
                {
                    return(Json(new ResponseData
                    {
                        Code = "901",
                        Message = "null of parameters",
                        Data = null
                    }));
                }

                if (parameters.grant_type == "password")
                {
                    return(Ok(Json(TH.DoPassword(parameters, _repo, _settings, users_collection))));
                }
                else if (parameters.grant_type == "refresh_token")
                {
                    return(Ok(Json(TH.DoRefreshToken(parameters, _repo, _settings, users_collection))));
                }
                else
                {
                    return(Json(new ResponseData
                    {
                        Code = "904",
                        Message = "bad request",
                        Data = null
                    }));
                }
            }
            catch (Exception ex)
            {
                SL.CreateLog("TokenController", "GetJWT", ex.Message);
                return(BadRequest(new ResponseData
                {
                    Code = "400",
                    Message = "Failed",
                    Data = null
                }));
            }
        }
Exemple #23
0
 /// <summary>Get Mongo Client</summary>
 public static MongoClient GetClient()
 {
     try
     {
         var ip               = GlobalHelper.ReadXML().Elements("mongo").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("ip").First().Value;
         var port             = GlobalHelper.ReadXML().Elements("mongo").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("port").First().Value;
         var user             = GlobalHelper.ReadXML().Elements("mongo").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("user").First().Value;
         var password         = GlobalHelper.ReadXML().Elements("mongo").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("password").First().Value;
         var db               = GlobalHelper.ReadXML().Elements("mongo").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("db").First().Value;
         var connectionString = "mongodb://" + user + ":" + password + "@" + ip + ":27018/" + db;
         //var connectionString = "mongodb://" + ip + ":" + port + "/" + db;
         var mongoClient = new MongoClient(connectionString);
         return(mongoClient);
     }
     catch (Exception ex)
     {
         SL.CreateLog("MongoHelper", "GetClient", ex.Message);
         return(null);
     }
 }
Exemple #24
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="data"></param>
 /// <param name="collection"></param>
 /// <returns></returns>
 public static dynamic InsertNewRole(Roles data, IMongoCollection <Roles> collection)
 {
     try
     {
         collection.Indexes.CreateOne("{ RoleId: " + data.RoleId + " }");
         collection.InsertOne(data);
         return(true);
     }
     catch (Exception ex)
     {
         if (ex.Message.Contains("duplicate key error"))
         {
             return(ex.Message);
         }
         else
         {
             SL.CreateLog("MongoHelper", "InsertNewRole", ex.Message);
             return(false);
         }
     }
 }
        public ActionResult DeactivateUser(string adminname, string username)
        {
            try
            {
                var getUser = MH.GetSingleObject(users_collection, "UserName", username, null, null).Result;
                if (getUser != null)
                {
                    var updateDefinition = Builders <BsonDocument> .Update.Set("IsActive", false);

                    var update      = MH.UpdateSingleObject(users_collection, "UserName", username, null, null, updateDefinition);
                    var userDetails = BsonSerializer.Deserialize <RegisterModel>(getUser);
                    var data        = userDetails;
                    data.IsActive = false;
                    AL.CreateLog(adminname, "DeactivateUser", userDetails, data, activitylog_collection);
                    return(Ok(new ResponseData
                    {
                        Code = "200",
                        Message = "User deactivated"
                    }));
                }
                else
                {
                    return(BadRequest(new ResponseData
                    {
                        Code = "404",
                        Message = "User not found"
                    }));
                }
            }
            catch (Exception ex)
            {
                SL.CreateLog("AuthController", "DeactivateUser", ex.Message);
                return(BadRequest(new ResponseData
                {
                    Code = "400",
                    Message = "Failed",
                    Data = ex.Message
                }));
            }
        }
Exemple #26
0
 public ActionResult GetAllTrips()
 {
     try
     {
         var getTrips = MH.GetListOfObjects(tripinfo_collection, null, null, null, null).Result;
         if (getTrips != null)
         {
             List <TripInfo> tripInfo = new List <TripInfo>();
             foreach (var trip in getTrips)
             {
                 tripInfo.Add(BsonSerializer.Deserialize <TripInfo>(trip));
             }
             var sortedList = tripInfo.OrderBy(o => o.LoadDate).ToList();
             return(Ok(new ResponseData
             {
                 Code = "200",
                 Message = "Success",
                 Data = sortedList
             }));
         }
         else
         {
             return(BadRequest(new ResponseData
             {
                 Code = "404",
                 Message = "No trips found"
             }));
         }
     }
     catch (Exception ex)
     {
         SL.CreateLog("TripController", "GetAllTrips", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }
Exemple #27
0
 public ActionResult GetAllVehicles()
 {
     try
     {
         var getVehicles = MH.GetListOfObjects(vehicleinfo_collection, null, null, null, null).Result;
         if (getVehicles != null)
         {
             List <VehicleInfo> vehicleInfo = new List <VehicleInfo>();
             foreach (var vehicle in getVehicles)
             {
                 vehicleInfo.Add(BsonSerializer.Deserialize <VehicleInfo>(vehicle));
             }
             var sortedList = vehicleInfo.OrderBy(o => o.VehicleNo).ToList();
             return(Ok(new ResponseData
             {
                 Code = "200",
                 Message = "Success",
                 Data = sortedList
             }));
         }
         else
         {
             return(BadRequest(new ResponseData
             {
                 Code = "404",
                 Message = "No vehicles found"
             }));
         }
     }
     catch (Exception ex)
     {
         SL.CreateLog("VehicleController", "GetAllVehicle", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }
 public ActionResult GetAllTyres()
 {
     try
     {
         var getTyres = MH.GetListOfObjects(tyreinfo_collection, null, null, null, null).Result;
         if (getTyres != null)
         {
             List <TyreInfo> tyreInfo = new List <TyreInfo>();
             foreach (var tyre in getTyres)
             {
                 tyreInfo.Add(BsonSerializer.Deserialize <TyreInfo>(tyre));
             }
             return(Ok(new ResponseData
             {
                 Code = "200",
                 Message = "Success",
                 Data = tyreInfo
             }));
         }
         else
         {
             return(BadRequest(new ResponseData
             {
                 Code = "404",
                 Message = "No tyres found"
             }));
         }
     }
     catch (Exception ex)
     {
         SL.CreateLog("TyreController", "GetAllTyres", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }
Exemple #29
0
 /// <summary>Get JWT</summary>
 /// <param name="username"></param>
 /// <param name="refreshToken"></param>
 /// <param name="_settings"></param>
 /// <param name="userRole"></param>
 public static string GetJwt(string username, string refreshToken, IOptions <Audience> _settings, string userRole)
 {
     try
     {
         var now    = DateTime.UtcNow;
         var claims = new Claim[]
         {
             new Claim(JwtRegisteredClaimNames.Sub, username),
             new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
             new Claim(JwtRegisteredClaimNames.Iat, now.ToUniversalTime().ToString(), ClaimValueTypes.Integer64),
             new Claim(ClaimTypes.Role, userRole)
         };
         var symmetricKeyAsBase64 = _settings.Value.Secret;
         var keyByteArray         = Encoding.ASCII.GetBytes(symmetricKeyAsBase64);
         var signingKey           = new SymmetricSecurityKey(keyByteArray);
         var jwt = new JwtSecurityToken(
             issuer: _settings.Value.Iss,
             audience: _settings.Value.Aud,
             claims: claims,
             notBefore: now,
             expires: now.Add(TimeSpan.FromMinutes(5)),
             signingCredentials: new SigningCredentials(signingKey, SecurityAlgorithms.HmacSha256));
         var encodedJwt = new JwtSecurityTokenHandler().WriteToken(jwt);
         var response   = new
         {
             accessToken  = encodedJwt,
             expiresIn    = (int)TimeSpan.FromMinutes(1).TotalSeconds,
             refreshToken = refreshToken,
         };
         return(JsonConvert.SerializeObject(response, new JsonSerializerSettings {
             Formatting = Formatting.Indented
         }));
     }
     catch (Exception ex)
     {
         SL.CreateLog("TokenHelper", "GetJwt", ex.Message);
         return(null);
     }
 }
 public ActionResult GetAllRoles()
 {
     try
     {
         var getRoles = MH.GetListOfObjects(roles_collection, null, null, null, null).Result;
         if (getRoles != null)
         {
             List <Roles> roles = new List <Roles>();
             foreach (var role in getRoles)
             {
                 roles.Add(BsonSerializer.Deserialize <Roles>(role));
             }
             return(Ok(new ResponseData
             {
                 Code = "200",
                 Message = "Success",
                 Data = roles
             }));
         }
         else
         {
             return(BadRequest(new ResponseData
             {
                 Code = "404",
                 Message = "No roles found"
             }));
         }
     }
     catch (Exception ex)
     {
         SL.CreateLog("AdminController", "GetAllRoles", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }