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 })); } }
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 })); } }
public ActionResult Login([FromBody] LoginModel data) { try { var check = MH.CheckForData(users_collection, "UserName", data.UserName, null, null).Result; if (check == true) { var getUser = BsonSerializer.Deserialize <RegisterModel>(MH.GetSingleObject(users_collection, "UserName", data.UserName, null, null).Result); if (getUser.UserVerified == true && getUser.IsActive == true) { RegisterModel registerModel = new RegisterModel { UserName = data.UserName, FullName = getUser.FullName, Password = data.Password }; if (passwordHasher.VerifyHashedPassword(registerModel, getUser.Password, data.Password).ToString() == "Success") { Parameters parameters = new Parameters { username = getUser.UserName, fullname = getUser.FullName }; var result = TH.DoPassword(parameters, _repo, _settings, users_collection); return(Ok(Json(result))); } else { return(BadRequest(new ResponseData { Code = "402", Message = "Incorrect password" })); } } else { if (getUser.UserVerified == false) { return(BadRequest(new ResponseData { Code = "401", Message = "User not verified" })); } else { return(BadRequest(new ResponseData { Code = "402", Message = "User not active" })); } } } else { return(BadRequest(new ResponseData { Code = "404", Message = "User not found" })); } } catch (Exception ex) { SL.CreateLog("AuthController", "Login", ex.Message); return(BadRequest(new ResponseData { Code = "400", Message = "Failed", Data = ex.Message })); } }