Esempio n. 1
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
                }));
            }
        }
Esempio n. 2
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
         }));
     }
 }
        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
                }));
            }
        }
Esempio n. 4
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
                }));
            }
        }
Esempio n. 5
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
                }));
            }
        }
Esempio n. 6
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
                }));
            }
        }
Esempio n. 7
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 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
         }));
     }
 }
        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
                }));
            }
        }
        public ActionResult VerifyUser(string adminname, string username)
        {
            try
            {
                var check = MH.CheckForData(users_collection, "UserName", username, null, null).Result;
                if (check == true)
                {
                    var updateDefinition = Builders <BsonDocument> .Update.Set("UserVerified", true).Set("IsActive", true);

                    var update = MH.UpdateSingleObject(users_collection, "UserName", username, null, null, updateDefinition);
                    AL.CreateLog(adminname, "VerifyUser", null, MH.GetSingleObject(users_collection, "UserName", username, null, null), activitylog_collection);
                    return(Ok(new ResponseData
                    {
                        Code = "200",
                        Message = "User verified"
                    }));
                }
                else
                {
                    return(BadRequest(new ResponseData
                    {
                        Code = "404",
                        Message = "User not found"
                    }));
                }
            }
            catch (Exception ex)
            {
                SL.CreateLog("AuthController", "VerifyUser", ex.Message);
                return(BadRequest(new ResponseData
                {
                    Code = "400",
                    Message = "Failed",
                    Data = ex.Message
                }));
            }
        }
Esempio n. 12
0
        public ActionResult UpdateVehicleInfo([FromBody] ExampleModel_VehicleInfo data, string username, string vehicleId)
        {
            try
            {
                if (data != null && username != null && vehicleId != null)
                {
                    var getVehicle = MH.GetSingleObject(vehicleinfo_collection, "VehicleId", vehicleId, null, null).Result;
                    if (getVehicle != null)
                    {
                        if (data.VehicleNo != null)
                        {
                            var updateDefinition = Builders <BsonDocument> .Update.Set("VehicleNo", data.VehicleNo);

                            update = MH.UpdateSingleObject(vehicleinfo_collection, "VehicleId", vehicleId, null, null, updateDefinition);
                        }
                        if (data.OwnerName != null)
                        {
                            var updateDefinition = Builders <BsonDocument> .Update.Set("OwnerName", data.OwnerName);

                            update = MH.UpdateSingleObject(vehicleinfo_collection, "VehicleId", vehicleId, null, null, updateDefinition);
                        }
                        if (data.Model != null)
                        {
                            var updateDefinition = Builders <BsonDocument> .Update.Set("Model", data.Model);

                            update = MH.UpdateSingleObject(vehicleinfo_collection, "VehicleId", vehicleId, null, null, updateDefinition);
                        }
                        if (data.ModelNo != 0)
                        {
                            var updateDefinition = Builders <BsonDocument> .Update.Set("ModelNo", data.ModelNo);

                            update = MH.UpdateSingleObject(vehicleinfo_collection, "VehicleId", vehicleId, null, null, updateDefinition);
                        }
                        if (data.VehicleType != null)
                        {
                            var updateDefinition = Builders <BsonDocument> .Update.Set("VehicleType", data.VehicleType);

                            update = MH.UpdateSingleObject(vehicleinfo_collection, "VehicleId", vehicleId, null, null, updateDefinition);
                        }
                        if (data.TypeOfBody != null)
                        {
                            var updateDefinition = Builders <BsonDocument> .Update.Set("TypeOfBody", data.TypeOfBody);

                            update = MH.UpdateSingleObject(vehicleinfo_collection, "VehicleId", vehicleId, null, null, updateDefinition);
                        }
                        if (data.NoOfWheels != 0)
                        {
                            var updateDefinition = Builders <BsonDocument> .Update.Set("NoOfWheels", data.NoOfWheels);

                            update = MH.UpdateSingleObject(vehicleinfo_collection, "VehicleId", vehicleId, null, null, updateDefinition);
                        }
                        if (data.VehicleCapacity != null)
                        {
                            var updateDefinition = Builders <BsonDocument> .Update.Set("VehicleCapacity", data.VehicleCapacity);

                            update = MH.UpdateSingleObject(vehicleinfo_collection, "VehicleId", vehicleId, null, null, updateDefinition);
                        }
                        if (data.EngineNumber != null)
                        {
                            var updateDefinition = Builders <BsonDocument> .Update.Set("EngineNumber", data.EngineNumber);

                            update = MH.UpdateSingleObject(vehicleinfo_collection, "VehicleId", vehicleId, null, null, updateDefinition);
                        }
                        if (data.ChasisNumber != null)
                        {
                            var updateDefinition = Builders <BsonDocument> .Update.Set("ChasisNumber", data.ChasisNumber);

                            update = MH.UpdateSingleObject(vehicleinfo_collection, "VehicleId", vehicleId, null, null, updateDefinition);
                        }
                        if (data.InsuranceDate != null)
                        {
                            var updateDefinition = Builders <BsonDocument> .Update.Set("InsuranceDate", data.InsuranceDate);

                            update = MH.UpdateSingleObject(vehicleinfo_collection, "VehicleId", vehicleId, null, null, updateDefinition);
                        }
                        if (data.FCDate != null)
                        {
                            var updateDefinition = Builders <BsonDocument> .Update.Set("FCDate", data.FCDate);

                            update = MH.UpdateSingleObject(vehicleinfo_collection, "VehicleId", vehicleId, null, null, updateDefinition);
                        }
                        if (data.NPTaxDate != null)
                        {
                            var updateDefinition = Builders <BsonDocument> .Update.Set("NPTaxDate", data.NPTaxDate);

                            update = MH.UpdateSingleObject(vehicleinfo_collection, "VehicleId", vehicleId, null, null, updateDefinition);
                        }
                        if (data.PermitDate != null)
                        {
                            var updateDefinition = Builders <BsonDocument> .Update.Set("PermitDate", data.PermitDate);

                            update = MH.UpdateSingleObject(vehicleinfo_collection, "VehicleId", vehicleId, null, null, updateDefinition);
                        }
                        if (data.DriverName != null)
                        {
                            var updateDefinition = Builders <BsonDocument> .Update.Set("DriverName", data.DriverName);

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

                            update = MH.UpdateSingleObject(vehicleinfo_collection, "VehicleId", vehicleId, null, null, updateDefinition);
                        }
                        if (update != null)
                        {
                            AL.CreateLog(username, "UpdateVehicleInfo", BsonSerializer.Deserialize <VehicleInfo>(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 info not found"
                        }));
                    }
                }
                else
                {
                    return(BadRequest(new ResponseData
                    {
                        Code = "402",
                        Message = "Bad request"
                    }));
                }
            }
            catch (Exception ex)
            {
                SL.CreateLog("VehicleController", "UpdateVehicleInfo", ex.Message);
                return(BadRequest(new ResponseData
                {
                    Code = "400",
                    Message = "Failed",
                    Data = ex.Message
                }));
            }
        }
 public ActionResult Login([FromBody] LoginModel data)
 {
     try
     {
         var check = MH.CheckForData(users_collection, "UserName", data.UserName, null, null).Result;
         if (check == true)
         {
             var getUser = BsonSerializer.Deserialize <RegisterModel>(MH.GetSingleObject(users_collection, "UserName", data.UserName, null, null).Result);
             if (getUser.UserVerified == true && getUser.IsActive == true)
             {
                 RegisterModel registerModel = new RegisterModel {
                     UserName = data.UserName, FullName = getUser.FullName, Password = data.Password
                 };
                 if (passwordHasher.VerifyHashedPassword(registerModel, getUser.Password, data.Password).ToString() == "Success")
                 {
                     Parameters parameters = new Parameters {
                         username = getUser.UserName, fullname = getUser.FullName
                     };
                     var result = TH.DoPassword(parameters, _repo, _settings, users_collection);
                     return(Ok(Json(result)));
                 }
                 else
                 {
                     return(BadRequest(new ResponseData
                     {
                         Code = "402",
                         Message = "Incorrect password"
                     }));
                 }
             }
             else
             {
                 if (getUser.UserVerified == false)
                 {
                     return(BadRequest(new ResponseData
                     {
                         Code = "401",
                         Message = "User not verified"
                     }));
                 }
                 else
                 {
                     return(BadRequest(new ResponseData
                     {
                         Code = "402",
                         Message = "User not active"
                     }));
                 }
             }
         }
         else
         {
             return(BadRequest(new ResponseData
             {
                 Code = "404",
                 Message = "User not found"
             }));
         }
     }
     catch (Exception ex)
     {
         SL.CreateLog("AuthController", "Login", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }
 public ActionResult InsertDriverInfo([FromBody] DriverInfo data, string username)
 {
     try
     {
         if (data != null && username != null)
         {
             var checkDriver = MH.GetSingleObject(driverinfo_collection, "DriverName", data.DriverName, "Address", data.Address).Result;
             if (checkDriver != null)
             {
                 return(BadRequest(new ResponseData
                 {
                     Code = "401",
                     Message = "Driver with same driver name and address is already added"
                 }));
             }
             else
             {
                 #region Calculate driver id
                 var getDrivers = MH.GetListOfObjects(driverinfo_collection, null, null, null, null).Result;
                 if (getDrivers.Count == 0)
                 {
                     data.DriverId = "DR-1";
                 }
                 else
                 {
                     List <long> idList = new List <long>();
                     foreach (var driver in getDrivers)
                     {
                         DriverInfo driverInfo  = BsonSerializer.Deserialize <DriverInfo>(driver);
                         long       seperatedId = Convert.ToInt64(driverInfo.DriverId.Substring(driverInfo.DriverId.LastIndexOf('-') + 1));
                         idList.Add(seperatedId);
                     }
                     var maxId = idList.Max();
                     data.DriverId = "DR-" + (maxId + 1);
                 }
                 #endregion
                 data.IsActive = true;
                 var insert = MH.InsertNewDriverInfo(data, driverinfoCollection);
                 if (insert == true)
                 {
                     AL.CreateLog(username, "InsertDriverInfo", null, data, activitylog_collection);
                     return(Ok(new ResponseData
                     {
                         Code = "200",
                         Message = "Inserted",
                         Data = data
                     }));
                 }
                 else
                 {
                     return(BadRequest(new ResponseData
                     {
                         Code = "402",
                         Message = "Driver info with same id is already added"
                     }));
                 }
             }
         }
         else
         {
             return(BadRequest(new ResponseData
             {
                 Code = "403",
                 Message = "Bad Request"
             }));
         }
     }
     catch (Exception ex)
     {
         SL.CreateLog("DriverController", "InsertDriverInfo", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }
        public ActionResult UpdateTyreInfo([FromBody] ExampleModel_TyreInfo data, string username, string tyreId)
        {
            try
            {
                if (data != null && username != null && tyreId != null)
                {
                    var tyreDetails = BsonSerializer.Deserialize <TyreInfo>(MH.GetSingleObject(tyreinfo_collection, "TyreId", tyreId, null, null).Result);
                    if (tyreDetails != null)
                    {
                        if (data.TyreStatus != null)
                        {
                            var updateDefinition = Builders <BsonDocument> .Update.Set("TyreStatus", data.TyreStatus);

                            update = MH.UpdateSingleObject(tyreinfo_collection, "TyreId", tyreId, null, null, updateDefinition);
                        }
                        if (data.PurchaseDetails != null)
                        {
                            PurchaseDetails purchaseDetails = new PurchaseDetails();
                            if (tyreDetails.PurchaseDetails != null)
                            {
                                purchaseDetails = tyreDetails.PurchaseDetails;
                            }
                            if (data.PurchaseDetails.BrandName != null)
                            {
                                purchaseDetails.BrandName = data.PurchaseDetails.BrandName;
                            }
                            if (data.PurchaseDetails.TyreModel != null)
                            {
                                purchaseDetails.TyreModel = data.PurchaseDetails.TyreModel;
                            }
                            if (data.PurchaseDetails.TyreNo != null)
                            {
                                purchaseDetails.TyreNo = data.PurchaseDetails.TyreNo;
                            }
                            if (data.PurchaseDetails.VendorName != null)
                            {
                                purchaseDetails.VendorName = data.PurchaseDetails.VendorName;
                            }
                            if (data.PurchaseDetails.PurchaseDate != null)
                            {
                                purchaseDetails.PurchaseDate = data.PurchaseDetails.PurchaseDate;
                            }
                            if (data.PurchaseDetails.BillNo != null)
                            {
                                purchaseDetails.BillNo = data.PurchaseDetails.BillNo;
                            }
                            var updateDefinition = Builders <BsonDocument> .Update.Set("PurchaseDetails", purchaseDetails);

                            update = MH.UpdateSingleObject(tyreinfo_collection, "TyreId", tyreId, null, null, updateDefinition);
                        }
                        if (data.DisposalDetails != null)
                        {
                            DisposalDetails disposalDetails = new DisposalDetails();
                            if (tyreDetails.DisposalDetails != null)
                            {
                                disposalDetails = tyreDetails.DisposalDetails;
                            }
                            if (data.DisposalDetails.VendorName != null)
                            {
                                disposalDetails.VendorName = data.DisposalDetails.VendorName;
                            }
                            if (data.DisposalDetails.DisposalDate != null)
                            {
                                disposalDetails.DisposalDate = data.DisposalDetails.DisposalDate;
                            }
                            if (data.DisposalDetails.SoldPrice != null)
                            {
                                disposalDetails.SoldPrice = data.DisposalDetails.SoldPrice;
                            }
                            var updateDefinition = Builders <BsonDocument> .Update.Set("DisposalDetails", disposalDetails);

                            update = MH.UpdateSingleObject(tyreinfo_collection, "TyreId", tyreId, null, null, updateDefinition);
                        }
                        if (data.TotalKMRunned != null)
                        {
                            var updateDefinition = Builders <BsonDocument> .Update.Set("TotalKMRunned", data.TotalKMRunned);

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

                            update = MH.UpdateSingleObject(tyreinfo_collection, "TyreId", tyreId, null, null, updateDefinition);
                        }
                        if (update != null)
                        {
                            AL.CreateLog(username, "UpdateTyreInfo", BsonSerializer.Deserialize <TyreInfo>(update), data, activitylog_collection);
                            return(Ok(new ResponseData
                            {
                                Code = "200",
                                Message = "Updated"
                            }));
                        }
                        else
                        {
                            return(BadRequest(new ResponseData
                            {
                                Code = "402",
                                Message = "Update failed"
                            }));
                        }
                    }
                    else
                    {
                        return(BadRequest(new ResponseData
                        {
                            Code = "404",
                            Message = "Tyre info not found"
                        }));
                    }
                }
                else
                {
                    return(BadRequest(new ResponseData
                    {
                        Code = "401",
                        Message = "Bad request"
                    }));
                }
            }
            catch (Exception ex)
            {
                SL.CreateLog("TyreController", "UpdateTyreInfo", ex.Message);
                return(BadRequest(new ResponseData
                {
                    Code = "400",
                    Message = "Failed",
                    Data = ex.Message
                }));
            }
        }
        public ActionResult ChangePassword([FromBody] LoginModel data, string adminname)
        {
            try
            {
                var getUser = MH.GetSingleObject(users_collection, "UserName", data.UserName, null, null).Result;
                if (getUser != null)
                {
                    var userDetails = BsonSerializer.Deserialize <RegisterModel>(getUser);
                    if (userDetails.UserVerified == false)
                    {
                        return(BadRequest(new ResponseData
                        {
                            Code = "401",
                            Message = "User not verified"
                        }));
                    }
                    else if (userDetails.IsActive == false)
                    {
                        return(BadRequest(new ResponseData
                        {
                            Code = "402",
                            Message = "User not active"
                        }));
                    }
                    else
                    {
                        RegisterModel registerModel = new RegisterModel
                        {
                            FullName     = userDetails.FullName,
                            UserRole     = userDetails.UserRole,
                            UserVerified = userDetails.UserVerified,
                            IsActive     = userDetails.IsActive,
                            UserName     = data.UserName,
                            Password     = data.Password
                        };
                        registerModel.Password = passwordHasher.HashPassword(registerModel, registerModel.Password);
                        var updateDefinition = Builders <BsonDocument> .Update.Set("Password", registerModel.Password);

                        update = MH.UpdateSingleObject(users_collection, "UserName", data.UserName, null, null, updateDefinition);
                        AL.CreateLog(adminname, "ChangePassword", userDetails, registerModel, activitylog_collection);
                        return(Ok(new ResponseData
                        {
                            Code = "200",
                            Message = "Password changed successfully"
                        }));
                    }
                }
                else
                {
                    return(BadRequest(new ResponseData
                    {
                        Code = "404",
                        Message = "User not found"
                    }));
                }
            }
            catch (Exception ex)
            {
                SL.CreateLog("AuthController", "ChangePassword", ex.Message);
                return(BadRequest(new ResponseData
                {
                    Code = "400",
                    Message = "Failed",
                    Data = ex.Message
                }));
            }
        }
        public ActionResult InsertOfficeInfo([FromBody] OfficeInfo data, string username)
        {
            try
            {
                if (data != null && username != null)
                {
                    var checkOffice = MH.GetSingleObject(officeinfo_collection, "OfficeName", data.OfficeName, "Address", data.Address).Result;
                    if (checkOffice != null)
                    {
                        var officeInfo = BsonSerializer.Deserialize <OfficeInfo>(checkOffice);
                        if (officeInfo.IsActive == true)
                        {
                            return(BadRequest(new ResponseData
                            {
                                Code = "401",
                                Message = "Office with same office name and address is already added"
                            }));
                        }
                        else
                        {
                            var updateDefinition = Builders <BsonDocument> .Update.Set("IsActive", true);

                            update = MH.UpdateSingleObject(officeinfo_collection, "OfficeName", data.OfficeName, "Address", data.Address, updateDefinition);
                            var detail = officeInfo;
                            detail.IsActive = true;
                            AL.CreateLog(username, "InsertOfficeInfo", officeInfo, detail, activitylog_collection);
                            return(BadRequest(new ResponseData
                            {
                                Code = "402",
                                Message = "Office already added and its made active"
                            }));
                        }
                    }
                    else
                    {
                        #region Calculate office id
                        var getOffices = MH.GetListOfObjects(officeinfo_collection, null, null, null, null).Result;
                        if (getOffices.Count == 0)
                        {
                            data.OfficeId = "OF-1";
                        }
                        else
                        {
                            List <long> idList = new List <long>();
                            foreach (var office in getOffices)
                            {
                                OfficeInfo officeInfo  = BsonSerializer.Deserialize <OfficeInfo>(office);
                                long       seperatedId = Convert.ToInt64(officeInfo.OfficeId.Substring(officeInfo.OfficeId.LastIndexOf('-') + 1));
                                idList.Add(seperatedId);
                            }
                            var maxId = idList.Max();
                            data.OfficeId = "OF-" + (maxId + 1);
                            #endregion
                        }
                        data.IsActive = true;
                        var insert = MH.InsertNewOfficeInfo(data, officeinfoCollection);
                        if (insert == true)
                        {
                            AL.CreateLog(username, "InsertOfficeInfo", null, data, activitylog_collection);
                            return(Ok(new ResponseData
                            {
                                Code = "200",
                                Message = "Inserted",
                                Data = data
                            }));
                        }
                        else if (insert == false)
                        {
                            return(BadRequest(new ResponseData
                            {
                                Code = "403",
                                Message = "Office info with same id is already added"
                            }));
                        }
                        else
                        {
                            return(BadRequest(new ResponseData
                            {
                                Code = "400",
                                Message = "Failed",
                                Data = insert
                            }));
                        }
                    }
                }
                else
                {
                    return(BadRequest(new ResponseData
                    {
                        Code = "405",
                        Message = "Bad Request"
                    }));
                }
            }
            catch (Exception ex)
            {
                SL.CreateLog("OfficeController", "InsertOfficeInfo", ex.Message);
                return(BadRequest(new ResponseData
                {
                    Code = "400",
                    Message = "Failed",
                    Data = ex.Message
                }));
            }
        }
Esempio n. 18
0
 /// <summary>Get the access_token by refresh_token</summary>
 /// <param name="parameters"></param>
 /// <param name="_repo"></param>
 /// <param name="_settings"></param>
 /// <param name="users_collection"></param>
 public static ResponseData DoRefreshToken(Parameters parameters, IRTokenRepository _repo, IOptions <Audience> _settings, IMongoCollection <BsonDocument> users_collection)
 {
     try
     {
         try
         {
             var token = _repo.GetToken(parameters.refresh_token, parameters.client_id).Result;
             if (token == null)
             {
                 return(new ResponseData
                 {
                     Code = "905",
                     Message = "can not refresh token",
                     Data = null
                 });
             }
             if (token.IsStop == 1)
             {
                 return(new ResponseData
                 {
                     Code = "906",
                     Message = "refresh token has expired",
                     Data = null
                 });
             }
             var refresh_token = Guid.NewGuid().ToString().Replace("-", "");
             token.IsStop = 1;
             var updateFlag = _repo.ExpireToken(token).Result;
             var addFlag    = _repo.AddToken(new RToken
             {
                 ClientId     = parameters.client_id,
                 RefreshToken = refresh_token,
                 Id           = Guid.NewGuid().ToString(),
                 IsStop       = 0
             });
             if (updateFlag && addFlag.Result)
             {
                 return(new ResponseData
                 {
                     Code = "999",
                     Message = "OK",
                     Data = GetJwt(parameters.client_id, refresh_token, _settings, BsonSerializer.Deserialize <RegisterModel>(MH.GetSingleObject(users_collection, "UserName", parameters.client_id, null, null).Result).UserRole)
                 });
             }
             else
             {
                 return(new ResponseData
                 {
                     Code = "910",
                     Message = "can not expire token or a new token",
                     Data = null
                 });
             }
         }
         catch (Exception ex)
         {
             SL.CreateLog("TokenHelper", "DoRefreshToken", ex.Message);
             return(new ResponseData
             {
                 Code = "400",
                 Message = "Failed",
                 Data = null
             });
         }
     }
     catch (Exception ex)
     {
         SL.CreateLog("TokenHelper", "DoRefreshToken", ex.Message);
         return(new ResponseData
         {
             Code = "400",
             Message = "Failed"
         });
     }
 }
Esempio n. 19
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
         });
     }
 }
Esempio n. 20
0
 public ActionResult MakePaymentForTrip([FromBody] PaymentDetails 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)
             {
                 if (data.AmountReceived != 0)
                 {
                     var tripDetails = BsonSerializer.Deserialize <TripInfo>(getTrip);
                     if (data.AmountReceived > tripDetails.BalanceAmount)
                     {
                         return(BadRequest(new ResponseData
                         {
                             Code = "403",
                             Message = "Paid amount is higher than the balance amount"
                         }));
                     }
                     else
                     {
                         List <PaymentDetails> paymentList = new List <PaymentDetails>();
                         if (tripDetails.PaymentInfo != null)
                         {
                             foreach (var payment in tripDetails.PaymentInfo)
                             {
                                 paymentList.Add(payment);
                             }
                         }
                         if (tripDetails.BalanceAmount < (data.AmountReceived + data.UnloadingCharges + data.RoundOffAmount + data.ShortageAmount + data.LoadingCharges))
                         {
                             return(BadRequest(new ResponseData
                             {
                                 Code = "403",
                                 Message = "Paid amount is higher than the balance amount"
                             }));
                         }
                         var paidAmount         = tripDetails.PaidAmount + data.AmountReceived + data.UnloadingCharges + data.RoundOffAmount + data.ShortageAmount + data.LoadingCharges;
                         var updatePaidAmount   = MH.UpdateSingleObject(tripinfo_collection, "TripId", tripId, null, null, Builders <BsonDocument> .Update.Set("PaidAmount", paidAmount));
                         var updatedTripDetails = BsonSerializer.Deserialize <TripInfo>(MH.GetSingleObject(tripinfo_collection, "TripId", tripId, null, null).Result);
                         var balanceAmount      = updatedTripDetails.VehicleAmount - updatedTripDetails.PaidAmount;
                         data.RunningBalanceAmount = balanceAmount;
                         paymentList.Add(data);
                         var updateBalanceAmount    = MH.UpdateSingleObject(tripinfo_collection, "TripId", tripId, null, null, Builders <BsonDocument> .Update.Set("BalanceAmount", balanceAmount));
                         var updateUnloadingCharges = MH.UpdateSingleObject(tripinfo_collection, "TripId", tripId, null, null, Builders <BsonDocument> .Update.Set("UnloadingCharges", data.UnloadingCharges));
                         var updateRoundOffAmount   = MH.UpdateSingleObject(tripinfo_collection, "TripId", tripId, null, null, Builders <BsonDocument> .Update.Set("RoundOffAmount", data.RoundOffAmount));
                         var updateShortageAmount   = MH.UpdateSingleObject(tripinfo_collection, "TripId", tripId, null, null, Builders <BsonDocument> .Update.Set("ShortageAmount", data.ShortageAmount));
                         var updateLoadingCharges   = MH.UpdateSingleObject(tripinfo_collection, "TripId", tripId, null, null, Builders <BsonDocument> .Update.Set("LoadingCharges", data.LoadingCharges));
                         var updatePaymentInfo      = MH.UpdateSingleObject(tripinfo_collection, "TripId", tripId, null, null, Builders <BsonDocument> .Update.Set("PaymentInfo", paymentList));
                         if (updateBalanceAmount != null && updatePaidAmount != null && updatePaymentInfo != null)
                         {
                             var updatedDetails = BsonSerializer.Deserialize <TripInfo>(MH.GetSingleObject(tripinfo_collection, "TripId", tripId, null, null).Result);
                             AL.CreateLog(username, "MakePaymentForTrip", BsonSerializer.Deserialize <TripInfo>(getTrip), updatedDetails, activitylog_collection);
                             return(Ok(new ResponseData
                             {
                                 Code = "200",
                                 Message = "Payment made successfully",
                                 Data = updatedDetails
                             }));
                         }
                         else
                         {
                             return(BadRequest(new ResponseData
                             {
                                 Code = "401",
                                 Message = "Payment update failed"
                             }));
                         }
                     }
                 }
                 else
                 {
                     return(BadRequest(new ResponseData
                     {
                         Code = "402",
                         Message = "Bad Request"
                     }));
                 }
             }
             else
             {
                 return(BadRequest(new ResponseData
                 {
                     Code = "404",
                     Message = "Trip info not found"
                 }));
             }
         }
         else
         {
             return(BadRequest(new ResponseData
             {
                 Code = "402",
                 Message = "Bad request"
             }));
         }
     }
     catch (Exception ex)
     {
         SL.CreateLog("TripController", "MakePaymentForTrip", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }
        public ActionResult UpdateOfficeInfo([FromBody] ExampleModel_OfficeInfo data, string username, string officeId)
        {
            try
            {
                if (data != null && username != null && officeId != null)
                {
                    var getOffice = MH.GetSingleObject(officeinfo_collection, "OfficeId", officeId, null, null).Result;
                    if (getOffice != null)
                    {
                        if (data.OfficeName != null)
                        {
                            var updateDefinition = Builders <BsonDocument> .Update.Set("OfficeName", data.OfficeName);

                            update = MH.UpdateSingleObject(officeinfo_collection, "OfficeId", officeId, null, null, updateDefinition);
                        }
                        if (data.ContactName != null)
                        {
                            var updateDefinition = Builders <BsonDocument> .Update.Set("ContactName", data.ContactName);

                            update = MH.UpdateSingleObject(officeinfo_collection, "OfficeId", officeId, null, null, updateDefinition);
                        }
                        if (data.ContactNo != null)
                        {
                            var updateDefinition = Builders <BsonDocument> .Update.Set("ContactNo", data.ContactNo);

                            update = MH.UpdateSingleObject(officeinfo_collection, "OfficeId", officeId, null, null, updateDefinition);
                        }
                        if (data.Address != null)
                        {
                            var updateDefinition = Builders <BsonDocument> .Update.Set("Address", data.Address);

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

                            update = MH.UpdateSingleObject(officeinfo_collection, "OfficeId", officeId, null, null, updateDefinition);
                        }
                        AL.CreateLog(username, "UpdateOfficeInfo", BsonSerializer.Deserialize <OfficeInfo>(getOffice), data, activitylog_collection);
                        return(Ok(new ResponseData
                        {
                            Code = "200",
                            Message = "Updated"
                        }));
                    }
                    else
                    {
                        return(BadRequest(new ResponseData
                        {
                            Code = "404",
                            Message = "Office info not found"
                        }));
                    }
                }
                else
                {
                    return(BadRequest(new ResponseData
                    {
                        Code = "401",
                        Message = "Bad request"
                    }));
                }
            }
            catch (Exception ex)
            {
                SL.CreateLog("OfficeController", "UpdateOfficeInfo", ex.Message);
                return(BadRequest(new ResponseData
                {
                    Code = "400",
                    Message = "Failed",
                    Data = ex.Message
                }));
            }
        }
        public ActionResult UpdateRethreadingDetails([FromBody] RethreadingDetails data, string username, string tyreId)
        {
            try
            {
                if (data != null && username != null && tyreId != null)
                {
                    var tyreDetails = BsonSerializer.Deserialize <TyreInfo>(MH.GetSingleObject(tyreinfo_collection, "TyreId", tyreId, null, null).Result);
                    if (tyreDetails != null)
                    {
                        if (tyreDetails.RethreadingDetails == null)
                        {
                            data.Id = 1;
                        }
                        else
                        {
                            data.Id = tyreDetails.RethreadingDetails.Count + 1;
                        }
                        List <RethreadingDetails> detailsList = new List <RethreadingDetails>();
                        if (tyreDetails.RethreadingDetails != null)
                        {
                            foreach (var rework in tyreDetails.RethreadingDetails)
                            {
                                detailsList.Add(rework);
                            }
                        }
                        detailsList.Add(data);
                        var updateDefinition = Builders <BsonDocument> .Update.Set("RethreadingDetails", detailsList);

                        update = MH.UpdateSingleObject(tyreinfo_collection, "TyreId", tyreId, null, null, updateDefinition);
                        if (update != null)
                        {
                            AL.CreateLog(username, "UpdateRethreadingDetails", BsonSerializer.Deserialize <TyreInfo>(update), data, activitylog_collection);
                            return(Ok(new ResponseData
                            {
                                Code = "200",
                                Message = "Updated"
                            }));
                        }
                        else
                        {
                            return(BadRequest(new ResponseData
                            {
                                Code = "402",
                                Message = "Update failed"
                            }));
                        }
                    }
                    else
                    {
                        return(BadRequest(new ResponseData
                        {
                            Code = "404",
                            Message = "Tyre info not found"
                        }));
                    }
                }
                else
                {
                    return(BadRequest(new ResponseData
                    {
                        Code = "401",
                        Message = "Bad request"
                    }));
                }
            }
            catch (Exception ex)
            {
                SL.CreateLog("TyreController", "UpdateRethreadingDetails", ex.Message);
                return(BadRequest(new ResponseData
                {
                    Code = "400",
                    Message = "Failed",
                    Data = ex.Message
                }));
            }
        }