public async Task <Tuple <bool, string> > UpdateBrandedStyle(BrandedStyleDetailsModel style) { var styleEntity = await _undercarriageContext.DealershipBranding.Where(b => b.Id == style.Id).FirstOrDefaultAsync(); string currentUcUriHost = "http://" + styleEntity.UCUIHost + "/account/signInCallback"; string currentGetUriHost = "http://" + styleEntity.GETUIHost + "/account/signInCallback"; if (styleEntity == null) { return(Tuple.Create(false, "No style exists with this Id to update. ")); } var clientRedirectUriUc = await _undercarriageContext.ClientRedirectUris.Where(c => c.Uri == currentUcUriHost && c.Client_Id == 1).FirstOrDefaultAsync(); var clientRedirectUriGet = await _undercarriageContext.ClientRedirectUris.Where(c => c.Uri == currentGetUriHost && c.Client_Id == 2).FirstOrDefaultAsync(); if (clientRedirectUriGet == null || clientRedirectUriUc == null) { return(Tuple.Create(false, "Could not find client redirect uri's to update. Contact TrackTreads support. ")); } string[] LogoArr = style.Logo.Split(','); string dealershipLogo = ""; if (LogoArr.Length > 1) { dealershipLogo = LogoArr[1]; } styleEntity.ApplicationStyleId = style.ColourSchemeId; styleEntity.DealershipId = style.DealershipId; if (dealershipLogo != "") { styleEntity.DealershipLogo = Convert.FromBase64String(dealershipLogo); } styleEntity.GETHost = style.GetUrl; styleEntity.HelpCentreUrl = ""; styleEntity.GETUIHost = style.GetUiUrl; styleEntity.IdentityHost = style.IdentityServerUrl; styleEntity.LogoutRedirectUrl = style.LogoutRedirectUrl; styleEntity.UCHost = style.UndercarriageUrl; styleEntity.UCUIHost = style.UndercarriageUiUrl; styleEntity.Name = style.Name; // Need to update ClientRedirectUris table records so that the identity application knows that this application url is authorized clientRedirectUriUc.Uri = "http://" + style.UndercarriageUiUrl + "/account/signInCallback"; clientRedirectUriGet.Uri = "http://" + style.GetUiUrl + "/account/signInCallback"; try { await _undercarriageContext.SaveChangesAsync(); } catch { return(Tuple.Create(false, "Failed to update branded style. ")); } return(Tuple.Create(true, "Branded style updated successfully. ")); }
public async Task <Tuple <bool, string> > AddNewBrandedStyle(BrandedStyleDetailsModel style) { string[] LogoArr = style.Logo.Split(','); string dealershipLogo = ""; if (LogoArr.Length > 1) { dealershipLogo = LogoArr[1]; } // _undercarriageContext.DealershipBranding.Add(new DealershipBranding() { ApplicationStyleId = style.ColourSchemeId, DealershipId = style.DealershipId, DealershipLogo = Convert.FromBase64String(dealershipLogo), GETHost = style.GetUrl, HelpCentreUrl = "", GETUIHost = style.GetUiUrl, IdentityHost = style.IdentityServerUrl, LogoutRedirectUrl = style.LogoutRedirectUrl, UCHost = style.UndercarriageUrl, UCUIHost = style.UndercarriageUiUrl, Name = style.Name }); _undercarriageContext.ClientRedirectUris.Add(new ClientRedirectUri() { Client_Id = 1, //Undercarriage UI Client Uri = "http://" + style.UndercarriageUiUrl + "/account/signInCallback" }); _undercarriageContext.ClientRedirectUris.Add(new ClientRedirectUri() { Client_Id = 2, //GET UI Client Uri = "http://" + style.GetUiUrl + "/account/signInCallback" }); try { await _undercarriageContext.SaveChangesAsync(); } catch { return(Tuple.Create(false, "Failed to create new branded style. ")); } return(Tuple.Create(true, "Branded style created successfully. ")); }