|
|
@ -36,7 +36,7 @@ using System.Net.Http; |
|
|
|
using System.Net.Http.Headers; |
|
|
|
using Newtonsoft.Json; |
|
|
|
using Abp.Json; |
|
|
|
|
|
|
|
using System.Diagnostics; |
|
|
|
|
|
|
|
namespace BCS.BMC.CompanyMasters |
|
|
|
{ |
|
|
@ -125,11 +125,11 @@ namespace BCS.BMC.CompanyMasters |
|
|
|
protected async Task<int> Create(CreateOrUpdateCompanyMasterInput input) |
|
|
|
{ |
|
|
|
int companyId = 0; |
|
|
|
|
|
|
|
// await GetUrlIsValid(input.Url);
|
|
|
|
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>(); |
|
|
|
// entity.TenantId = AbpSession.TenantId;
|
|
|
|
|
|
|
@ -147,17 +147,57 @@ namespace BCS.BMC.CompanyMasters |
|
|
|
} |
|
|
|
} |
|
|
|
entity.DomainName = host; |
|
|
|
if (company == null || company.Count() == 0) |
|
|
|
if (company == null || company.Count() == 0) |
|
|
|
{ |
|
|
|
companyId = await _companyMaster.InsertAndGetIdAsync(entity); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
throw new UserFriendlyException("The Input Url Already Exist"); |
|
|
|
} |
|
|
|
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) |
|
|
|
{ |
|
|
|
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("No Record Found"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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) |
|
|
@ -217,11 +257,11 @@ namespace BCS.BMC.CompanyMasters |
|
|
|
} |
|
|
|
|
|
|
|
var company = await _companyMaster.FirstOrDefaultAsync(x => x.Url == input.CompanyUrl.ToString()); |
|
|
|
if(company == null) |
|
|
|
if (company == null) |
|
|
|
{ |
|
|
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
using (HttpClient client = new HttpClient()) |
|
|
|
{ |
|
|
|
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); |
|
|
|
return new HttpStatusCodeResult(HttpStatusCode.OK); |
|
|
|
} |
|
|
|
} |
|
|
|
} |