Exemplo 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
                }));
            }
        }
Exemplo n.º 2
0
        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
                }));
            }
        }
Exemplo 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
                }));
            }
        }
Exemplo 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
                }));
            }
        }
Exemplo 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
                }));
            }
        }
        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
                }));
            }
        }
Exemplo n.º 8
0
        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
                }));
            }
        }
Exemplo n.º 9
0
        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
                }));
            }
        }
Exemplo n.º 10
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
                }));
            }
        }
Exemplo n.º 11
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
         }));
     }
 }
Exemplo n.º 12
0
 public ActionResult InsertTripInfo([FromBody] TripInfo data, string username)
 {
     try
     {
         if (data != null && username != null)
         {
             if (data.TripType == null)
             {
                 return(BadRequest(new ResponseData
                 {
                     Code = "403",
                     Message = "Bad request. Invalid trip type"
                 }));
             }
             else
             {
                 if (data.TripType != "Local" && data.TripType != "Line")
                 {
                     return(BadRequest(new ResponseData
                     {
                         Code = "403",
                         Message = "Bad request. Invalid trip type"
                     }));
                 }
                 else
                 {
                     #region Calculate trip id
                     var getTrips = MH.GetListOfObjects(tripinfo_collection, null, null, null, null, true).Result;
                     if (getTrips.Count == 0)
                     {
                         data.TripId = "TP-1";
                     }
                     else
                     {
                         List <long> idList = new List <long>();
                         foreach (var trip in getTrips)
                         {
                             TripInfo tripInfo    = BsonSerializer.Deserialize <TripInfo>(trip);
                             long     seperatedId = Convert.ToInt64(tripInfo.TripId.Substring(tripInfo.TripId.LastIndexOf('-') + 1));
                             idList.Add(seperatedId);
                         }
                         var maxId = idList.Max();
                         data.TripId = "TP-" + (maxId + 1);
                     }
                     #endregion
                     data.IsActive = true;
                     var insert = MH.InsertNewTripInfo(data, tripinfoCollection);
                     if (insert == true)
                     {
                         AL.CreateLog(username, "InsertTripInfo", null, data, activitylog_collection);
                         return(Ok(new ResponseData
                         {
                             Code = "200",
                             Message = "Inserted",
                             Data = data
                         }));
                     }
                     else
                     {
                         return(BadRequest(new ResponseData
                         {
                             Code = "401",
                             Message = "Trip info with same id is already added"
                         }));
                     }
                 }
             }
         }
         else
         {
             return(BadRequest(new ResponseData
             {
                 Code = "402",
                 Message = "Bad request"
             }));
         }
     }
     catch (Exception ex)
     {
         SL.CreateLog("TripController", "InsertTripInfo", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }
Exemplo n.º 13
0
        public ActionResult InsertRole([FromBody] Roles data, string username)
        {
            try
            {
                if (data != null && username != null)
                {
                    var getRole = MH.GetSingleObject(roles_collection, "RoleName", data.RoleName, null, null).Result;
                    if (getRole == null)
                    {
                        data.IsActive = true;
                        var insert = MH.InsertNewRole(data, rolesCollection);
                        if (insert == true)
                        {
                            AL.CreateLog(username, "InsertRole", 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 = "Role with same id is already added"
                            }));
                        }
                        else
                        {
                            return(BadRequest(new ResponseData
                            {
                                Code = "400",
                                Message = "Failed",
                                Data = insert
                            }));
                        }
                    }
                    else
                    {
                        var roleDetails = BsonSerializer.Deserialize <Roles>(getRole);
                        if (roleDetails.IsActive == true)
                        {
                            return(BadRequest(new ResponseData
                            {
                                Code = "401",
                                Message = "Role with the same name is found"
                            }));
                        }
                        else
                        {
                            var updateDefinition = Builders <BsonDocument> .Update.Set("IsActive", true);

                            update = MH.UpdateSingleObject(roles_collection, "RoleName", data.RoleName, null, null, updateDefinition);
                            var detail = roleDetails;
                            detail.IsActive = true;
                            AL.CreateLog(username, "InsertRole", roleDetails, detail, activitylog_collection);
                            return(BadRequest(new ResponseData
                            {
                                Code = "402",
                                Message = "Role with the same name is found and is made active"
                            }));
                        }
                    }
                }
                else
                {
                    return(BadRequest(new ResponseData
                    {
                        Code = "405",
                        Message = "Bad request"
                    }));
                }
            }
            catch (Exception ex)
            {
                SL.CreateLog("AdminController", "InsertRole", ex.Message);
                return(BadRequest(new ResponseData
                {
                    Code = "400",
                    Message = "Failed",
                    Data = ex.Message
                }));
            }
        }
Exemplo n.º 14
0
        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
                }));
            }
        }
Exemplo n.º 15
0
 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
         }));
     }
 }
Exemplo n.º 16
0
        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
                }));
            }
        }
Exemplo n.º 17
0
        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
                }));
            }
        }
Exemplo n.º 18
0
 public ActionResult InsertTyreInfo([FromBody] TyreInfo data, string username)
 {
     try
     {
         if (data != null && username != null)
         {
             var checkTyre = MH.GetListOfObjects(tyreinfo_collection, null, null, null, null).Result;
             foreach (var details in checkTyre)
             {
                 var deserializedDetails = BsonSerializer.Deserialize <TyreInfo>(details).PurchaseDetails;
                 if (deserializedDetails.TyreNo == data.PurchaseDetails.TyreNo && deserializedDetails.BrandName == data.PurchaseDetails.BrandName)
                 {
                     alreadyAdded = true;
                 }
             }
             if (alreadyAdded == true)
             {
                 return(BadRequest(new ResponseData
                 {
                     Code = "401",
                     Message = "Tyre with same brand and tyre number is already added"
                 }));
             }
             else
             {
                 #region Calculate tyre id
                 var getTyres = MH.GetListOfObjects(tyreinfo_collection, null, null, null, null).Result;
                 if (getTyres.Count == 0)
                 {
                     data.TyreId = "TRE-1";
                 }
                 else
                 {
                     List <long> idList = new List <long>();
                     foreach (var tyre in getTyres)
                     {
                         TyreInfo tyreInfo    = BsonSerializer.Deserialize <TyreInfo>(tyre);
                         long     seperatedId = Convert.ToInt64(tyreInfo.TyreId.Substring(tyreInfo.TyreId.LastIndexOf('-') + 1));
                         idList.Add(seperatedId);
                     }
                     var maxId = idList.Max();
                     data.TyreId = "TRE-" + (maxId + 1);
                 }
                 #endregion
                 data.IsActive = true;
                 var insert = MH.InsertNewTyreInfo(data, tyreinfoCollection);
                 if (insert == true)
                 {
                     AL.CreateLog(username, "InsertTyreInfo", null, data, activitylog_collection);
                     return(Ok(new ResponseData
                     {
                         Code = "200",
                         Message = "Inserted",
                         Data = data
                     }));
                 }
                 else
                 {
                     return(BadRequest(new ResponseData
                     {
                         Code = "402",
                         Message = "Tyre info with same id is already added"
                     }));
                 }
             }
         }
         else
         {
             return(BadRequest(new ResponseData
             {
                 Code = "403",
                 Message = "Bad Request"
             }));
         }
     }
     catch (Exception ex)
     {
         SL.CreateLog("TyreController", "InsertTyreInfo", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }
Exemplo n.º 19
0
        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
                }));
            }
        }
Exemplo n.º 20
0
        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
                }));
            }
        }