Пример #1
0
        public ActionResult MakeVendorInfoActive(string username, string vendorId)
        {
            try
            {
                if (vendorId != null && username != null)
                {
                    var getVendor = MH.GetSingleObject(vendorinfo_collection, "VendorId", vendorId, null, null).Result;
                    if (getVendor != null)
                    {
                        var updateDefinition = Builders <BsonDocument> .Update.Set("IsActive", true);

                        update = MH.UpdateSingleObject(vendorinfo_collection, "VendorId", vendorId, null, null, updateDefinition);
                        var data = BsonSerializer.Deserialize <VendorInfo>(getVendor);
                        data.IsActive = true;
                        AL.CreateLog(username, "MakeVendorInfoActive", BsonSerializer.Deserialize <VendorInfo>(getVendor), data, activitylog_collection);
                        return(Ok(new ResponseData
                        {
                            Code = "200",
                            Message = "Vendor info made active"
                        }));
                    }
                    else
                    {
                        return(BadRequest(new ResponseData
                        {
                            Code = "404",
                            Message = "Vendor info not found"
                        }));
                    }
                }
                else
                {
                    return(BadRequest(new ResponseData
                    {
                        Code = "401",
                        Message = "Bad Request"
                    }));
                }
            }
            catch (Exception ex)
            {
                SL.CreateLog("VendorController", "MakeVendorInfoActive", ex.Message);
                return(BadRequest(new ResponseData
                {
                    Code = "400",
                    Message = "Failed",
                    Data = ex.Message
                }));
            }
        }
 public ActionResult UploadImageToS3([FromForm] ImageData data)
 {
     try
     {
         if (data != null)
         {
             var objectName = data.ObjectName + ".jpg";
             var result     = AmazonHelper.UploadImageToS3(data.Image, data.BucketName, objectName);
             var Image_Url  = AmazonHelper.GetS3Object(data.BucketName, objectName);
             if (result.Result == true)
             {
                 return(Ok(new ResponseData
                 {
                     Code = "200",
                     Message = "Image uploaded",
                     Data = Image_Url
                 }));
             }
             else
             {
                 return(BadRequest(new ResponseData
                 {
                     Code = "401",
                     Message = "Image upload failed",
                     Data = null
                 }));
             }
         }
         else
         {
             return(BadRequest(new ResponseData
             {
                 Code = "404",
                 Message = "Image upload data not found",
                 Data = null
             }));
         }
     }
     catch (Exception ex)
     {
         SL.CreateLog("AdminContoller", "UploadImageToS3", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }
 public ActionResult 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
         }));
     }
 }
Пример #4
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
         });
     }
 }
 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
         }));
     }
 }
Пример #6
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 GetRole(string rolename)
 {
     try
     {
         if (rolename != null)
         {
             var getRole = MH.GetSingleObject(roles_collection, "RoleName", rolename, null, null).Result;
             if (getRole != null)
             {
                 return(Ok(new ResponseData
                 {
                     Code = "200",
                     Message = "Success",
                     Data = BsonSerializer.Deserialize <Roles>(getRole)
                 }));
             }
             else
             {
                 return(BadRequest(new ResponseData
                 {
                     Code = "404",
                     Message = "Role not found"
                 }));
             }
         }
         else
         {
             return(BadRequest(new ResponseData
             {
                 Code = "401",
                 Message = "Bad Request"
             }));
         }
     }
     catch (Exception ex)
     {
         SL.CreateLog("AdminController", "GetRole", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }
        public ActionResult GetJWT([FromQuery] Parameters parameters)
        {
            try
            {
                if (parameters == null)
                {
                    return(Json(new ResponseData
                    {
                        Code = "901",
                        Message = "null of parameters",
                        Data = null
                    }));
                }

                if (parameters.grant_type == "password")
                {
                    return(Ok(Json(TH.DoPassword(parameters, _repo, _settings, users_collection))));
                }
                else if (parameters.grant_type == "refresh_token")
                {
                    return(Ok(Json(TH.DoRefreshToken(parameters, _repo, _settings, users_collection))));
                }
                else
                {
                    return(Json(new ResponseData
                    {
                        Code = "904",
                        Message = "bad request",
                        Data = null
                    }));
                }
            }
            catch (Exception ex)
            {
                SL.CreateLog("TokenController", "GetJWT", ex.Message);
                return(BadRequest(new ResponseData
                {
                    Code = "400",
                    Message = "Failed",
                    Data = null
                }));
            }
        }
Пример #9
0
 /// <summary>Get Mongo Client</summary>
 public static MongoClient GetClient()
 {
     try
     {
         var ip               = GlobalHelper.ReadXML().Elements("mongo").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("ip").First().Value;
         var port             = GlobalHelper.ReadXML().Elements("mongo").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("port").First().Value;
         var user             = GlobalHelper.ReadXML().Elements("mongo").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("user").First().Value;
         var password         = GlobalHelper.ReadXML().Elements("mongo").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("password").First().Value;
         var db               = GlobalHelper.ReadXML().Elements("mongo").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("db").First().Value;
         var connectionString = "mongodb://" + user + ":" + password + "@" + ip + ":27018/" + db;
         //var connectionString = "mongodb://" + ip + ":" + port + "/" + db;
         var mongoClient = new MongoClient(connectionString);
         return(mongoClient);
     }
     catch (Exception ex)
     {
         SL.CreateLog("MongoHelper", "GetClient", ex.Message);
         return(null);
     }
 }
Пример #10
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="data"></param>
 /// <param name="collection"></param>
 /// <returns></returns>
 public static dynamic InsertNewRole(Roles data, IMongoCollection <Roles> collection)
 {
     try
     {
         collection.Indexes.CreateOne("{ RoleId: " + data.RoleId + " }");
         collection.InsertOne(data);
         return(true);
     }
     catch (Exception ex)
     {
         if (ex.Message.Contains("duplicate key error"))
         {
             return(ex.Message);
         }
         else
         {
             SL.CreateLog("MongoHelper", "InsertNewRole", ex.Message);
             return(false);
         }
     }
 }
Пример #11
0
 public ActionResult GetAllTrips()
 {
     try
     {
         var getTrips = MH.GetListOfObjects(tripinfo_collection, null, null, null, null).Result;
         if (getTrips != null)
         {
             List <TripInfo> tripInfo = new List <TripInfo>();
             foreach (var trip in getTrips)
             {
                 tripInfo.Add(BsonSerializer.Deserialize <TripInfo>(trip));
             }
             var sortedList = tripInfo.OrderBy(o => o.LoadDate).ToList();
             return(Ok(new ResponseData
             {
                 Code = "200",
                 Message = "Success",
                 Data = sortedList
             }));
         }
         else
         {
             return(BadRequest(new ResponseData
             {
                 Code = "404",
                 Message = "No trips found"
             }));
         }
     }
     catch (Exception ex)
     {
         SL.CreateLog("TripController", "GetAllTrips", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }
Пример #12
0
 public ActionResult GetAllVehicles()
 {
     try
     {
         var getVehicles = MH.GetListOfObjects(vehicleinfo_collection, null, null, null, null).Result;
         if (getVehicles != null)
         {
             List <VehicleInfo> vehicleInfo = new List <VehicleInfo>();
             foreach (var vehicle in getVehicles)
             {
                 vehicleInfo.Add(BsonSerializer.Deserialize <VehicleInfo>(vehicle));
             }
             var sortedList = vehicleInfo.OrderBy(o => o.VehicleNo).ToList();
             return(Ok(new ResponseData
             {
                 Code = "200",
                 Message = "Success",
                 Data = sortedList
             }));
         }
         else
         {
             return(BadRequest(new ResponseData
             {
                 Code = "404",
                 Message = "No vehicles found"
             }));
         }
     }
     catch (Exception ex)
     {
         SL.CreateLog("VehicleController", "GetAllVehicle", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }
Пример #13
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
                }));
            }
        }
Пример #14
0
 /// <summary>Get JWT</summary>
 /// <param name="username"></param>
 /// <param name="refreshToken"></param>
 /// <param name="_settings"></param>
 /// <param name="userRole"></param>
 public static string GetJwt(string username, string refreshToken, IOptions <Audience> _settings, string userRole)
 {
     try
     {
         var now    = DateTime.UtcNow;
         var claims = new Claim[]
         {
             new Claim(JwtRegisteredClaimNames.Sub, username),
             new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
             new Claim(JwtRegisteredClaimNames.Iat, now.ToUniversalTime().ToString(), ClaimValueTypes.Integer64),
             new Claim(ClaimTypes.Role, userRole)
         };
         var symmetricKeyAsBase64 = _settings.Value.Secret;
         var keyByteArray         = Encoding.ASCII.GetBytes(symmetricKeyAsBase64);
         var signingKey           = new SymmetricSecurityKey(keyByteArray);
         var jwt = new JwtSecurityToken(
             issuer: _settings.Value.Iss,
             audience: _settings.Value.Aud,
             claims: claims,
             notBefore: now,
             expires: now.Add(TimeSpan.FromMinutes(5)),
             signingCredentials: new SigningCredentials(signingKey, SecurityAlgorithms.HmacSha256));
         var encodedJwt = new JwtSecurityTokenHandler().WriteToken(jwt);
         var response   = new
         {
             accessToken  = encodedJwt,
             expiresIn    = (int)TimeSpan.FromMinutes(1).TotalSeconds,
             refreshToken = refreshToken,
         };
         return(JsonConvert.SerializeObject(response, new JsonSerializerSettings {
             Formatting = Formatting.Indented
         }));
     }
     catch (Exception ex)
     {
         SL.CreateLog("TokenHelper", "GetJwt", ex.Message);
         return(null);
     }
 }
 public ActionResult GetAllDrivers()
 {
     try
     {
         var getDrivers = MH.GetListOfObjects(driverinfo_collection, null, null, null, null).Result;
         if (getDrivers != null)
         {
             List <DriverInfo> driverInfo = new List <DriverInfo>();
             foreach (var driver in getDrivers)
             {
                 driverInfo.Add(BsonSerializer.Deserialize <DriverInfo>(driver));
             }
             return(Ok(new ResponseData
             {
                 Code = "200",
                 Message = "Success",
                 Data = driverInfo
             }));
         }
         else
         {
             return(BadRequest(new ResponseData
             {
                 Code = "404",
                 Message = "No drivers found"
             }));
         }
     }
     catch (Exception ex)
     {
         SL.CreateLog("DriverController", "GetAllDrivers", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }
Пример #16
0
 public ActionResult GetAllTyres()
 {
     try
     {
         var getTyres = MH.GetListOfObjects(tyreinfo_collection, null, null, null, null).Result;
         if (getTyres != null)
         {
             List <TyreInfo> tyreInfo = new List <TyreInfo>();
             foreach (var tyre in getTyres)
             {
                 tyreInfo.Add(BsonSerializer.Deserialize <TyreInfo>(tyre));
             }
             return(Ok(new ResponseData
             {
                 Code = "200",
                 Message = "Success",
                 Data = tyreInfo
             }));
         }
         else
         {
             return(BadRequest(new ResponseData
             {
                 Code = "404",
                 Message = "No tyres found"
             }));
         }
     }
     catch (Exception ex)
     {
         SL.CreateLog("TyreController", "GetAllTyres", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }
Пример #17
0
 public ActionResult GetAllRoles()
 {
     try
     {
         var getRoles = MH.GetListOfObjects(roles_collection, null, null, null, null).Result;
         if (getRoles != null)
         {
             List <Roles> roles = new List <Roles>();
             foreach (var role in getRoles)
             {
                 roles.Add(BsonSerializer.Deserialize <Roles>(role));
             }
             return(Ok(new ResponseData
             {
                 Code = "200",
                 Message = "Success",
                 Data = roles
             }));
         }
         else
         {
             return(BadRequest(new ResponseData
             {
                 Code = "404",
                 Message = "No roles found"
             }));
         }
     }
     catch (Exception ex)
     {
         SL.CreateLog("AdminController", "GetAllRoles", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }
Пример #18
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="data"></param>
 /// <param name="collection"></param>
 /// <returns></returns>
 public static dynamic InsertNewDriverInfo(DriverInfo data, IMongoCollection <DriverInfo> collection)
 {
     try
     {
         #region Create index
         //collection.Indexes.CreateOne("{ DriverId: " + data.DriverId + " }");
         #endregion
         collection.InsertOne(data);
         return(true);
     }
     catch (Exception ex)
     {
         if (ex.Message.Contains("duplicate key error"))
         {
             return(ex.Message);
         }
         else
         {
             SL.CreateLog("MongoHelper", "InsertNewDriverInfo", ex.Message);
             return(false);
         }
     }
 }
Пример #19
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
                }));
            }
        }
Пример #20
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
         }));
     }
 }
Пример #21
0
 public ActionResult GetTripInfoWithUnPaidBalanceAmountWithFliter(DateTime?fromdate, DateTime?todate)
 {
     try
     {
         List <TripInfo> tripDetailsList = new List <TripInfo>();
         var             getTrips        = MH.GetListOfObjects(tripinfo_collection, null, null, null, null).Result;
         if (getTrips == null)
         {
             return(BadRequest(new ResponseData
             {
                 Code = "404",
                 Message = "No trips found"
             }));
         }
         else
         {
             foreach (var trip in getTrips)
             {
                 var deserlizedData = BsonSerializer.Deserialize <TripInfo>(trip);
                 if (deserlizedData.BalanceAmount > 0)
                 {
                     tripDetailsList.Add(deserlizedData);
                 }
             }
         }
         if (fromdate != null && todate == null)
         {
             var             dateList = GH.GetDateRange(fromdate.Value.Date, DateTime.UtcNow.AddDays(1).Date);
             List <TripInfo> tripList = new List <TripInfo>();
             foreach (var trip in tripDetailsList)
             {
                 if (trip.LoadDate != null && dateList.Contains(trip.LoadDate.Value.Date))
                 {
                     tripList.Add(trip);
                 }
             }
             if (tripList.Count == 0)
             {
                 {
                     return(BadRequest(new ResponseData
                     {
                         Code = "404",
                         Message = "No trips found"
                     }));
                 }
             }
             else
             {
                 var sortedList = tripList.OrderBy(o => o.LoadDate).ToList();
                 return(Ok(new ResponseData
                 {
                     Code = "200",
                     Message = "Success",
                     Data = sortedList
                 }));
             }
         }
         else if (fromdate == null && todate == null)
         {
             var sortedList = tripDetailsList.OrderBy(o => o.LoadDate).ToList();
             return(Ok(new ResponseData
             {
                 Code = "200",
                 Message = "Success",
                 Data = sortedList
             }));
         }
         else if (fromdate == null && todate != null)
         {
             return(BadRequest(new ResponseData
             {
                 Code = "400",
                 Message = "Bad Request"
             }));
         }
         else
         {
             var             dateList = GH.GetDateRange(fromdate.Value.Date, todate.Value.AddDays(1).Date);
             List <TripInfo> tripList = new List <TripInfo>();
             foreach (var trip in tripDetailsList)
             {
                 if (trip.LoadDate != null && dateList.Contains(trip.LoadDate.Value.Date))
                 {
                     tripList.Add(trip);
                 }
             }
             if (tripList.Count == 0)
             {
                 {
                     return(BadRequest(new ResponseData
                     {
                         Code = "404",
                         Message = "No trips found"
                     }));
                 }
             }
             else
             {
                 var sortedList = tripList.OrderBy(o => o.LoadDate).ToList();
                 return(Ok(new ResponseData
                 {
                     Code = "200",
                     Message = "Success",
                     Data = sortedList
                 }));
             }
         }
     }
     catch (Exception ex)
     {
         SL.CreateLog("TripController", "GetTripInfoWithUnPaidBalanceAmountWithFliter", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }
Пример #22
0
 public ActionResult GetTripsWithFilter(string triptype, string vehicleno, DateTime?fromdate, DateTime?todate)
 {
     try
     {
         if (triptype != "Local" && triptype != "Line")
         {
             return(BadRequest(new ResponseData
             {
                 Code = "401",
                 Message = "Bad Request. Invalid trip type"
             }));
         }
         if (vehicleno == null && fromdate == null && todate == null)
         {
             var getTrips = MH.GetListOfObjects(tripinfo_collection, "TripType", triptype, null, null).Result;
             if (getTrips != null)
             {
                 List <TripInfo> tripInfo    = new List <TripInfo>();
                 var             currentDate = DateTime.Now;
                 List <DateTime> dateList    = GH.GetDateRange(DateTime.UtcNow.AddDays(-2).Date, DateTime.UtcNow.Date);
                 foreach (var trip in getTrips)
                 {
                     var tripData = BsonSerializer.Deserialize <TripInfo>(trip);
                     if (tripData.LoadDate != null && dateList.Contains(tripData.LoadDate.Value.Date))
                     {
                         tripInfo.Add(tripData);
                     }
                 }
                 var sortedList = tripInfo.OrderBy(o => o.LoadDate).ToList();
                 if (tripInfo.Count == 0)
                 {
                     return(BadRequest(new ResponseData
                     {
                         Code = "404",
                         Message = "No trips found"
                     }));
                 }
                 else
                 {
                     return(Ok(new ResponseData
                     {
                         Code = "200",
                         Message = "Success",
                         Data = sortedList
                     }));
                 }
             }
             else
             {
                 return(BadRequest(new ResponseData
                 {
                     Code = "404",
                     Message = "No trips found"
                 }));
             }
         }
         else
         {
             if (vehicleno != null)
             {
                 var getTripsWithVehicleNo = MH.GetListOfObjects(tripinfo_collection, "VehicleNo", vehicleno, "TripType", triptype).Result;
                 if (fromdate == null && todate == null)
                 {
                     var date = DateTime.UtcNow.Date;
                     if (getTripsWithVehicleNo != null)
                     {
                         List <TripInfo> tripInfo = new List <TripInfo>();
                         foreach (var trip in getTripsWithVehicleNo)
                         {
                             tripInfo.Add(BsonSerializer.Deserialize <TripInfo>(trip));
                         }
                         var sortedList = tripInfo.OrderBy(o => o.LoadDate).ToList();
                         return(Ok(new ResponseData
                         {
                             Code = "200",
                             Message = "Success",
                             Data = sortedList
                         }));
                     }
                     else
                     {
                         return(BadRequest(new ResponseData
                         {
                             Code = "404",
                             Message = "No trips found"
                         }));
                     }
                 }
                 else if (fromdate != null && todate == null)
                 {
                     var             dateList = GH.GetDateRange(fromdate.Value.Date, DateTime.UtcNow.AddDays(1).Date);
                     List <TripInfo> tripList = new List <TripInfo>();
                     foreach (var trip in getTripsWithVehicleNo)
                     {
                         var tripData = BsonSerializer.Deserialize <TripInfo>(trip);
                         if (tripData.LoadDate != null && dateList.Contains(tripData.LoadDate.Value.Date))
                         {
                             tripList.Add(tripData);
                         }
                     }
                     if (tripList.Count == 0)
                     {
                         {
                             return(BadRequest(new ResponseData
                             {
                                 Code = "404",
                                 Message = "No trips found"
                             }));
                         }
                     }
                     else
                     {
                         var sortedList = tripList.OrderBy(o => o.LoadDate).ToList();
                         return(Ok(new ResponseData
                         {
                             Code = "200",
                             Message = "Success",
                             Data = sortedList
                         }));
                     }
                 }
                 else if (fromdate == null && todate != null)
                 {
                     return(BadRequest(new ResponseData
                     {
                         Code = "400",
                         Message = "Bad Request"
                     }));
                 }
                 else
                 {
                     var             dateList = GH.GetDateRange(fromdate.Value.Date, todate.Value.AddDays(1).Date);
                     List <TripInfo> tripList = new List <TripInfo>();
                     foreach (var trip in getTripsWithVehicleNo)
                     {
                         var tripData = BsonSerializer.Deserialize <TripInfo>(trip);
                         if (tripData.LoadDate != null && dateList.Contains(tripData.LoadDate.Value.Date))
                         {
                             tripList.Add(tripData);
                         }
                     }
                     if (tripList.Count == 0)
                     {
                         {
                             return(BadRequest(new ResponseData
                             {
                                 Code = "404",
                                 Message = "No trips found"
                             }));
                         }
                     }
                     else
                     {
                         var sortedList = tripList.OrderBy(o => o.LoadDate).ToList();
                         return(Ok(new ResponseData
                         {
                             Code = "200",
                             Message = "Success",
                             Data = sortedList
                         }));
                     }
                 }
             }
             else
             {
                 var getTripsWithOutVehicleNo = MH.GetListOfObjects(tripinfo_collection, "TripType", triptype, null, null).Result;
                 if (fromdate != null && todate == null)
                 {
                     var             dateList = GH.GetDateRange(fromdate.Value.Date, DateTime.UtcNow.AddDays(1).Date);
                     List <TripInfo> tripList = new List <TripInfo>();
                     foreach (var trip in getTripsWithOutVehicleNo)
                     {
                         var tripData = BsonSerializer.Deserialize <TripInfo>(trip);
                         if (tripData.LoadDate != null && dateList.Contains(tripData.LoadDate.Value.Date))
                         {
                             tripList.Add(tripData);
                         }
                     }
                     if (tripList.Count == 0)
                     {
                         {
                             return(BadRequest(new ResponseData
                             {
                                 Code = "404",
                                 Message = "No trips found"
                             }));
                         }
                     }
                     else
                     {
                         var sortedList = tripList.OrderBy(o => o.LoadDate).ToList();
                         return(Ok(new ResponseData
                         {
                             Code = "200",
                             Message = "Success",
                             Data = sortedList
                         }));
                     }
                 }
                 else if (fromdate == null && todate != null)
                 {
                     return(BadRequest(new ResponseData
                     {
                         Code = "400",
                         Message = "Bad Request"
                     }));
                 }
                 else
                 {
                     var             dateList = GH.GetDateRange(fromdate.Value.Date, todate.Value.AddDays(1).Date);
                     List <TripInfo> tripList = new List <TripInfo>();
                     foreach (var trip in getTripsWithOutVehicleNo)
                     {
                         var tripData = BsonSerializer.Deserialize <TripInfo>(trip);
                         if (tripData.LoadDate != null && dateList.Contains(tripData.LoadDate.Value.Date))
                         {
                             tripList.Add(tripData);
                         }
                     }
                     if (tripList.Count == 0)
                     {
                         {
                             return(BadRequest(new ResponseData
                             {
                                 Code = "404",
                                 Message = "No trips found"
                             }));
                         }
                     }
                     else
                     {
                         var sortedList = tripList.OrderBy(o => o.LoadDate).ToList();
                         return(Ok(new ResponseData
                         {
                             Code = "200",
                             Message = "Success",
                             Data = sortedList
                         }));
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         SL.CreateLog("TripController", "GetTripsWithFilter", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }
Пример #23
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
                }));
            }
        }
Пример #24
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
                }));
            }
        }
Пример #25
0
 public ActionResult NotificationForService()
 {
     try
     {
         var getVehicles = MH.GetListOfObjects(vehiclemaintenanceinfo_collection, null, null, null, null).Result;
         if (getVehicles != null)
         {
             List <string> oilService   = new List <string>();
             List <string> wheelGrease  = new List <string>();
             List <string> airFilter    = new List <string>();
             List <string> tyrePowder   = new List <string>();
             List <string> dieselFilter = new List <string>();
             List <string> stainner     = new List <string>();
             foreach (var vehicle in getVehicles)
             {
                 var vehicleData = BsonSerializer.Deserialize <VehicleMaintenanceInfo>(vehicle);
                 if (vehicleData.OilService.RunKilometer != null)
                 {
                     if (vehicleData.RunKm > vehicleData.OilService.RunKilometer + vehicleData.OilService.AvgKilometer)
                     {
                         oilService.Add(vehicleData.VehicleNo);
                     }
                 }
                 if (vehicleData.WheelGrease.RunKilometer != null)
                 {
                     if (vehicleData.RunKm > vehicleData.WheelGrease.RunKilometer + 40000)
                     {
                         wheelGrease.Add(vehicleData.VehicleNo);
                     }
                 }
                 if (vehicleData.AirFilter.RunKilometer != null)
                 {
                     if (vehicleData.RunKm > vehicleData.AirFilter.RunKilometer + 60000)
                     {
                         airFilter.Add(vehicleData.VehicleNo);
                     }
                 }
                 if (vehicleData.TyrePowder.RunKilometer != null)
                 {
                     if (vehicleData.RunKm > vehicleData.TyrePowder.RunKilometer + 10000)
                     {
                         tyrePowder.Add(vehicleData.VehicleNo);
                     }
                 }
                 if (vehicleData.DieselFilter.RunKilometer != null)
                 {
                     if (vehicleData.RunKm > vehicleData.DieselFilter.RunKilometer + 25000)
                     {
                         dieselFilter.Add(vehicleData.VehicleNo);
                     }
                 }
                 if (vehicleData.Stainner.RunKilometer != null)
                 {
                     if (vehicleData.RunKm > vehicleData.Stainner.RunKilometer + 10000)
                     {
                         stainner.Add(vehicleData.VehicleNo);
                     }
                 }
             }
             ServiceList serviceDetails = new ServiceList
             {
                 OilService   = oilService,
                 WheelGrease  = wheelGrease,
                 AirFilter    = airFilter,
                 TyrePowder   = tyrePowder,
                 DieselFilter = dieselFilter,
                 Stainner     = stainner
             };
             return(Ok(new ResponseData
             {
                 Code = "200",
                 Message = "Success",
                 Data = serviceDetails
             }));
         }
         else
         {
             return(BadRequest(new ResponseData
             {
                 Code = "404",
                 Message = "No vehicles found"
             }));
         }
     }
     catch (Exception ex)
     {
         SL.CreateLog("VehicleController", "GetServiceInfo", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }
Пример #26
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
                }));
            }
        }
Пример #27
0
 public ActionResult NotificationForRenewal()
 {
     try
     {
         var getVehicles = MH.GetListOfObjects(vehicleinfo_collection, null, null, null, null).Result;
         if (getVehicles != null)
         {
             List <RenewalDetails> insuranceRenewalList = new List <RenewalDetails>();
             List <RenewalDetails> fcRenewalList        = new List <RenewalDetails>();
             List <RenewalDetails> npTaxRenewalList     = new List <RenewalDetails>();
             List <RenewalDetails> permitRenewalList    = new List <RenewalDetails>();
             var currentDate = DateTime.UtcNow.Date;
             var dateList    = GH.GetDateRange(currentDate.Date, currentDate.AddDays(20).Date);
             foreach (var vehicle in getVehicles)
             {
                 var vehicleData = BsonSerializer.Deserialize <VehicleInfo>(vehicle);
                 if (vehicleData.InsuranceDate != null)
                 {
                     if (vehicleData.InsuranceDate < currentDate || dateList.Contains(vehicleData.InsuranceDate.Value.Date))
                     {
                         insuranceRenewalList.Add(new RenewalDetails {
                             VehicleNo = vehicleData.VehicleNo, Date = vehicleData.InsuranceDate.Value.Date
                         });
                     }
                 }
                 if (vehicleData.FCDate != null)
                 {
                     if (vehicleData.FCDate < currentDate || dateList.Contains(vehicleData.FCDate.Value.Date))
                     {
                         fcRenewalList.Add(new RenewalDetails {
                             VehicleNo = vehicleData.VehicleNo, Date = vehicleData.FCDate.Value.Date
                         });
                     }
                 }
                 if (vehicleData.NPTaxDate != null)
                 {
                     if (vehicleData.NPTaxDate < currentDate || dateList.Contains(vehicleData.NPTaxDate.Value.Date))
                     {
                         npTaxRenewalList.Add(new RenewalDetails {
                             VehicleNo = vehicleData.VehicleNo, Date = vehicleData.NPTaxDate.Value.Date
                         });
                     }
                 }
                 if (vehicleData.PermitDate != null)
                 {
                     if (vehicleData.PermitDate < currentDate || dateList.Contains(vehicleData.PermitDate.Value.Date))
                     {
                         permitRenewalList.Add(new RenewalDetails {
                             VehicleNo = vehicleData.VehicleNo, Date = vehicleData.PermitDate.Value.Date
                         });
                     }
                 }
             }
             List <RenewalDetails> sortedInsuranceRenewalList = new List <RenewalDetails>();
             List <RenewalDetails> sortedFCRenewalList        = new List <RenewalDetails>();
             List <RenewalDetails> sortedNPTaxRenewalList     = new List <RenewalDetails>();
             List <RenewalDetails> sortedPermitRenewalList    = new List <RenewalDetails>();
             if (insuranceRenewalList != null)
             {
                 sortedInsuranceRenewalList = insuranceRenewalList.OrderBy(o => o.Date).ToList();
             }
             if (fcRenewalList != null)
             {
                 sortedFCRenewalList = fcRenewalList.OrderBy(o => o.Date).ToList();
             }
             if (npTaxRenewalList != null)
             {
                 sortedNPTaxRenewalList = npTaxRenewalList.OrderBy(o => o.Date).ToList();
             }
             if (permitRenewalList != null)
             {
                 sortedPermitRenewalList = permitRenewalList.OrderBy(o => o.Date).ToList();
             }
             RenewalList renewalDateDetails = new RenewalList
             {
                 InsuranceRenewalList = sortedInsuranceRenewalList,
                 FCRenewalList        = sortedFCRenewalList,
                 NPTaxRenewalList     = sortedNPTaxRenewalList,
                 PermitRenewlList     = sortedPermitRenewalList
             };
             return(Ok(new ResponseData
             {
                 Code = "200",
                 Message = "Success",
                 Data = renewalDateDetails
             }));
         }
         else
         {
             return(BadRequest(new ResponseData
             {
                 Code = "404",
                 Message = "No vehicles found"
             }));
         }
     }
     catch (Exception ex)
     {
         SL.CreateLog("VehicleController", "GetInfoOfVehicle", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }
Пример #28
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
                }));
            }
        }
Пример #29
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
         }));
     }
 }
Пример #30
0
        public ActionResult InsertVehicleMaintenanceInfo([FromBody] VehicleMaintenanceInfo data, string username)
        {
            try
            {
                if (data != null && username != null)
                {
                    var check = MH.CheckForData(vehiclemaintenanceinfo_collection, "VehicleNo", data.VehicleNo, null, null).Result;
                    if (check == false)
                    {
                        #region Calculate Vehicle id
                        var getVehicles = MH.GetListOfObjects(vehiclemaintenanceinfo_collection, null, null, null, null).Result;
                        if (getVehicles.Count == 0)
                        {
                            data.VehicleId = "VC-1";
                        }
                        else
                        {
                            List <long> idList = new List <long>();
                            foreach (var vehicle in getVehicles)
                            {
                                VehicleMaintenanceInfo vehicleInfo = BsonSerializer.Deserialize <VehicleMaintenanceInfo>(vehicle);
                                long seperatedId = Convert.ToInt64(vehicleInfo.VehicleId.Substring(vehicleInfo.VehicleId.LastIndexOf('-') + 1));
                                idList.Add(seperatedId);
                            }
                            var maxId = idList.Max();
                            data.VehicleId = "VC-" + (maxId + 1);
                        }
                        #endregion
                        data.IsActive = true;



                        var insert = MH.InsertNewVehicleMaintenanceInfo(data, vehiclemaintenanceinfoCollection);
                        if (insert == true)
                        {
                            return(Ok(new ResponseData
                            {
                                Code = "200",
                                Message = "Inserted",
                                Data = data
                            }));
                        }
                        else
                        {
                            return(BadRequest(new ResponseData
                            {
                                Code = "401",
                                Message = "Vehicle maintenance info with same id is already added"
                            }));
                        }
                    }
                    else
                    {
                        return(BadRequest(new ResponseData
                        {
                            Code = "402",
                            Message = "Vehicle with same reg number is found"
                        }));
                    }
                }
                else
                {
                    return(BadRequest(new ResponseData
                    {
                        Code = "403",
                        Message = "Bad Request"
                    }));
                }
            }
            catch (Exception ex)
            {
                SL.CreateLog("VehicleController", "InsertVehicleMaintenanceInfo", ex.Message);
                return(BadRequest(new ResponseData
                {
                    Code = "400",
                    Message = "Failed",
                    Data = ex.Message
                }));
            }
        }