BMC: Send CompanyId in ValidateTenancy Response

This commit is contained in:
Palash Biswas 2022-12-16 12:23:24 +05:30
parent 3682a17d53
commit 097f0f1378
9 changed files with 132 additions and 29 deletions

View File

@ -36,7 +36,7 @@ using System.Net.Http;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using Newtonsoft.Json; using Newtonsoft.Json;
using Abp.Json; using Abp.Json;
using System.Diagnostics;
namespace BCS.BMC.CompanyMasters namespace BCS.BMC.CompanyMasters
{ {
@ -125,11 +125,11 @@ namespace BCS.BMC.CompanyMasters
protected async Task<int> Create(CreateOrUpdateCompanyMasterInput input) protected async Task<int> Create(CreateOrUpdateCompanyMasterInput input)
{ {
int companyId = 0; int companyId = 0;
// await GetUrlIsValid(input.Url);
var company = from m in _companyMaster.GetAllList().Where(m => m.Url.ToLower().Trim() == input.Url.ToLower().Trim()) var company = from m in _companyMaster.GetAllList().Where(m => m.Url.ToLower().Trim() == input.Url.ToLower().Trim())
select m; select m;
var entity = input.MapTo<CompanyMaster>(); var entity = input.MapTo<CompanyMaster>();
// entity.TenantId = AbpSession.TenantId; // entity.TenantId = AbpSession.TenantId;
@ -147,17 +147,57 @@ namespace BCS.BMC.CompanyMasters
} }
} }
entity.DomainName = host; entity.DomainName = host;
if (company == null || company.Count() == 0) if (company == null || company.Count() == 0)
{ {
companyId = await _companyMaster.InsertAndGetIdAsync(entity); companyId = await _companyMaster.InsertAndGetIdAsync(entity);
} }
else else
{ {
throw new UserFriendlyException("The Input Url Already Exist"); throw new UserFriendlyException("The Input Url Already Exist");
} }
return companyId; return companyId;
} }
public async Task<bool> GetUrlIsValid(string url)
{
try
{
HttpWebRequest request = HttpWebRequest.Create(url) as HttpWebRequest;
request.Timeout = 5000; //set the timeout to 5 seconds to keep the user from waiting too long for the page to load
request.Method = "HEAD"; //Get only the header information -- no need to download any content
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
int statusCode = (int)response.StatusCode;
if (statusCode >= 100 && statusCode < 400) //Good requests
{
return true;
}
else if (statusCode >= 500 && statusCode <= 510) //Server Errors
{
//log.Warn(String.Format("The remote server has thrown an internal error. Url is not valid: {0}", url));
Debug.WriteLine(String.Format("The remote server has thrown an internal error. Url is not valid: {0}", url));
return false;
}
}
}
catch (WebException ex)
{
if (ex.Status == WebExceptionStatus.ProtocolError) //400 errors
{
return false;
}
else
{
// log.Warn(String.Format("Unhandled status [{0}] returned for url: {1}", ex.Status, url), ex);
}
}
catch (Exception ex)
{
// log.Error(String.Format("Could not test url {0}.", url), ex);
}
return false;
}
protected async Task Update(CreateOrUpdateCompanyMasterInput input) protected async Task Update(CreateOrUpdateCompanyMasterInput input)
{ {
var entity = await _companyMaster.FirstOrDefaultAsync(x => x.Id == input.Id); var entity = await _companyMaster.FirstOrDefaultAsync(x => x.Id == input.Id);
@ -166,7 +206,7 @@ namespace BCS.BMC.CompanyMasters
//throw new UserFriendlyException(NotFoundRecord ("Name", input.ClientName)); //throw new UserFriendlyException(NotFoundRecord ("Name", input.ClientName));
throw new UserFriendlyException("No Record Found"); throw new UserFriendlyException("No Record Found");
} }
var getclient = from m in _companyMaster.GetAllList() var getclient = from m in _companyMaster.GetAllList()
.Where(m => m.Id == input.Id && m.CompanyName.ToLower().Trim() == input.CompanyName.ToLower().Trim() && m.Id != input.Id) .Where(m => m.Id == input.Id && m.CompanyName.ToLower().Trim() == input.CompanyName.ToLower().Trim() && m.Id != input.Id)
@ -217,11 +257,11 @@ namespace BCS.BMC.CompanyMasters
} }
var company = await _companyMaster.FirstOrDefaultAsync(x => x.Url == input.CompanyUrl.ToString()); var company = await _companyMaster.FirstOrDefaultAsync(x => x.Url == input.CompanyUrl.ToString());
if(company == null) if (company == null)
{ {
return new HttpStatusCodeResult(HttpStatusCode.BadRequest); return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
} }
using (HttpClient client = new HttpClient()) using (HttpClient client = new HttpClient())
{ {
Uri uri = new Uri(input.CompanyUrl); Uri uri = new Uri(input.CompanyUrl);
@ -245,7 +285,7 @@ namespace BCS.BMC.CompanyMasters
return new HttpStatusCodeResult(HttpStatusCode.OK, responseStream); return new HttpStatusCodeResult(HttpStatusCode.OK, responseStream);
} }
} }
return new HttpStatusCodeResult(HttpStatusCode.OK); return new HttpStatusCodeResult(HttpStatusCode.OK);
} }
} }
} }

View File

@ -28,5 +28,6 @@ namespace BCS.BMC.CompanyMasters
Task DeleteCompany(EntityDto<int> input); Task DeleteCompany(EntityDto<int> input);
[HttpPost] [HttpPost]
Task<HttpStatusCodeResult> TokenByCompanyUrl(GetInputUrl input); Task<HttpStatusCodeResult> TokenByCompanyUrl(GetInputUrl input);
Task<bool> GetUrlIsValid(string url);
} }
} }

View File

@ -27,5 +27,7 @@ namespace BCS.BMC.FirebaseCloudMessaging.Dto
public bool Status { get; set; } public bool Status { get; set; }
[FirestoreProperty] [FirestoreProperty]
public List<string> UserId { get; set; } public List<string> UserId { get; set; }
[FirestoreProperty]
public int CompanyId { get; set; }
} }
} }

View File

@ -13,13 +13,8 @@ namespace BCS.BMC.FirebaseCloudMessaging.Dto
[AutoMapTo(typeof (FirebaseCloudMessageDetails))] [AutoMapTo(typeof (FirebaseCloudMessageDetails))]
public class NotificationModel public class NotificationModel
{ {
//[JsonProperty("title")]
//public List<string> Title { get; set; }
//[JsonProperty("body")]
public string FcmToken { get; set; } public string FcmToken { get; set; }
//public List<string> Id { get; set; }
public string Message { get; set; } public string Message { get; set; }
public DateTime? MessageSentDateTime { get; set; } public DateTime? MessageSentDateTime { get; set; }
@ -28,6 +23,7 @@ namespace BCS.BMC.FirebaseCloudMessaging.Dto
public bool Status { get; set; } public bool Status { get; set; }
public List<string> UserId { get; set; } public List<string> UserId { get; set; }
public string CompanyUrl { get; set; }
} }

View File

@ -267,7 +267,12 @@ namespace BCS.BMC.Controllers
{ {
return BadRequest("Url Not Found"); return BadRequest("Url Not Found");
} }
return Ok("Success"); var result = new
{
CompanyId = company.Id,
};
return Ok(result);
} }
[HttpPost] [HttpPost]

View File

@ -37,5 +37,10 @@ namespace BCS.BMC.Web.Controllers
return PartialView("_EditModal", output); return PartialView("_EditModal", output);
} }
//public async Task<bool> GetUrlIsValid(string url)
//{
// bool isSuccess = await _companyasterService.GetUrlIsValid(url);
// return isSuccess;
//}
} }
} }

View File

@ -29,6 +29,7 @@ namespace BCS.BMC.Web.Controllers
private readonly IFirebaseNotificationAppService _notificationService; private readonly IFirebaseNotificationAppService _notificationService;
private readonly IRepository<FirebaseCloudMessageDetails> _firebaseCloudMessageDetails; private readonly IRepository<FirebaseCloudMessageDetails> _firebaseCloudMessageDetails;
private readonly IRepository<FirebaseToken, int> _firebaseToken; private readonly IRepository<FirebaseToken, int> _firebaseToken;
private readonly IRepository<CompanyMaster, int> _companyMasterService;
//IFirebaseConfig config = new FirebaseConfig //IFirebaseConfig config = new FirebaseConfig
//{ //{
// AuthSecret = "n6DTPQEbpnLahrrk2EYu4bJ2Wd3jCk2N8kocazdI", // AuthSecret = "n6DTPQEbpnLahrrk2EYu4bJ2Wd3jCk2N8kocazdI",
@ -37,11 +38,13 @@ namespace BCS.BMC.Web.Controllers
//IFirebaseClient client; //IFirebaseClient client;
public NotificationController(IFirebaseNotificationAppService notificationService, public NotificationController(IFirebaseNotificationAppService notificationService,
IRepository<FirebaseCloudMessageDetails> firebaseCloudMessageDetails, IRepository<FirebaseCloudMessageDetails> firebaseCloudMessageDetails,
IRepository<FirebaseToken, int> firebaseToken) IRepository<FirebaseToken, int> firebaseToken,
IRepository<CompanyMaster, int> companyMasterService)
{ {
_notificationService = notificationService; _notificationService = notificationService;
_firebaseCloudMessageDetails = firebaseCloudMessageDetails; _firebaseCloudMessageDetails = firebaseCloudMessageDetails;
_firebaseToken = firebaseToken; _firebaseToken = firebaseToken;
_companyMasterService = companyMasterService;
} }
@ -62,7 +65,7 @@ namespace BCS.BMC.Web.Controllers
{ {
string path = AppDomain.CurrentDomain.BaseDirectory + @"firechat-57601-firebase-adminsdk-anscp-e04366c4d4.json"; string path = AppDomain.CurrentDomain.BaseDirectory + @"firechat-57601-firebase-adminsdk-anscp-e04366c4d4.json";
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", path); Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", path);
var companyDetails = _companyMasterService.GetAllList().Where(x => x.Url.Trim() == notification.CompanyUrl.Trim()).FirstOrDefault();
try try
{ {
FirestoreDb db = FirestoreDb.Create("firechat-57601"); FirestoreDb db = FirestoreDb.Create("firechat-57601");
@ -77,6 +80,7 @@ namespace BCS.BMC.Web.Controllers
data.SenderName = notification.SenderName; data.SenderName = notification.SenderName;
data.Status = notification.Status; data.Status = notification.Status;
data.UserId = notification.UserId; data.UserId = notification.UserId;
data.CompanyId = companyDetails.Id;
await db.Collection("BMC_Notification").Document().SetAsync(data); await db.Collection("BMC_Notification").Document().SetAsync(data);
int userId = 0; int userId = 0;

View File

@ -24,20 +24,22 @@
</li> </li>
</ul>*@ </ul>*@
<div class="tab-content mt-4"> <div class="tab-content mt-4">
<div role="tabpanel" class="tab-pane container active" id="create-client-details"> <div role="tabpanel" class="tab-pane container active" id="create-client-details">
<div class="form-group row required">
<label class="col-md-3 col-form-label">@L("Url")</label>
<div class="col-md-9">
<input type="text" class="form-control" id="Url" name="Url" required maxlength="@AbpUserBase.MaxNameLength">
</div>
@* <input type="submit" value="Check Url" class="download-button" name="submit">*@
</div>
<div class="form-group row required"> <div class="form-group row required">
<label class="col-md-3 col-form-label">@L("Company")</label> <label class="col-md-3 col-form-label">@L("Company")</label>
<div class="col-md-9"> <div class="col-md-9">
<input type="text" class="form-control" name="CompanyName" required maxlength="@AbpUserBase.MaxUserNameLength" minlength="2"> <input type="text" class="form-control" name="CompanyName" required maxlength="@AbpUserBase.MaxUserNameLength" minlength="2">
</div> </div>
</div> </div>
<div class="form-group row required"> @* <div class="form-group row required">
<label class="col-md-3 col-form-label">@L("Url")</label>
<div class="col-md-9">
<input type="text" class="form-control" name="Url" required maxlength="@AbpUserBase.MaxNameLength">
</div>
</div>
@* <div class="form-group row required">
<label class="col-md-3 col-form-label">@L("ClientSubDomainName")</label> <label class="col-md-3 col-form-label">@L("ClientSubDomainName")</label>
<div class="col-md-9"> <div class="col-md-9">
<input type="text" class="form-control" name="ClientSubDomainName" required maxlength="@AbpUserBase.MaxSurnameLength"> <input type="text" class="form-control" name="ClientSubDomainName" required maxlength="@AbpUserBase.MaxSurnameLength">

View File

@ -84,9 +84,57 @@
$('input[type="checkbox"]', rows).prop('checked', this.checked); $('input[type="checkbox"]', rows).prop('checked', this.checked);
}); });
//function validateUrl (isValid) {
// var companydetails = _$form.serializeFormToObject();
// abp.ui.setBusy();
// var companyUrl = companydetails.Url;
// abp.notify.info(l('ValidatingUrl'));
// _companyService.urlIsValid(companyUrl);
//}
//_$form.find('.download-button').on('click', (e) => {
// debugger;
// var companydetails = _$form.serializeFormToObject();
// //abp.ui.setBusy();
// var companyUrl = companydetails.Url;
// $.ajax({
// url: abp.appPath + 'CompanyMaster/GetUrlIsValid?url=' + companyUrl,
// type: 'GET',
// data: { url: companyUrl },
// success: function (data) {
// alert('ok');
// console.log(data);
// if (data.result == true) {
// debugger;
// alert('correct');
// // window.location.replace("Management Page.aspx");
// }
// },
// Error: function () {
// alert('error');
// }
// });
// //var companydetails = _$form.serializeFormToObject();
// //abp.ui.setBusy();
// //var companyUrl = companydetails.Url;
// //var data = _companyService.getUrlIsValid(companyUrl);
// //data.done(function (result) {
// // var isSuccess = result;
// //})
// //console.log("Hello world!");
// //console.log('1', data);
// //});
//});
_$form.find('.save-button').on('click', (e) => { _$form.find('.save-button').on('click', (e) => {
e.preventDefault(); e.preventDefault();
if (!_$form.valid()) { if (!_$form.valid()) {
return; return;
} }