public int AddOrUpdateTextLocalConfiguration(TextlocalConfiguration textlocalConfiguration) { using (DataContext context = new DataContext()) { TextlocalConfiguration config = context.TextlocalConfigurations.FirstOrDefault(x => x.CabofficeId == textlocalConfiguration.CabofficeId && x.IsActive == true); if (config == null) { textlocalConfiguration.CreatedDate = DateTime.Now; textlocalConfiguration.IsActive = true; context.TextlocalConfigurations.Add(textlocalConfiguration); } else { config.Password = textlocalConfiguration.Password; config.Username = textlocalConfiguration.Username; config.APIKey = textlocalConfiguration.APIKey; config.Hash = textlocalConfiguration.Hash; } context.SaveChanges(); return(textlocalConfiguration.Id); } }
public async Task <IHttpActionResult> GetCabOfficeTextlocalConfiguration(TextLocalConfigurationModel textLocalConfigurationModel) { TextLocalConfigurationDto textLocalConfigurationDto = new TextLocalConfigurationDto(); ConfigurationService configurationService = new ConfigurationService(); try { AccountService accountService = new AccountService(); Account account = null; string email = ""; int cabOfficeId = 0; if (Request.Headers.Contains("CabOfficeEmail")) { IEnumerable <string> headerValues = Request.Headers.GetValues("CabOfficeEmail"); email = headerValues.FirstOrDefault(); } if (Request.Headers.Contains("CabOfficeId")) { IEnumerable <string> headerValues = Request.Headers.GetValues("CabOfficeId"); cabOfficeId = Convert.ToInt32(headerValues.FirstOrDefault()); } account = accountService.getCabOfficeByEmailAndCabOfficeId(email, cabOfficeId); if (account == null) { textLocalConfigurationDto.IsSuccess = true; textLocalConfigurationDto.Error = Constant.APIError.AccountNotFound.ToString(); textLocalConfigurationDto.ErrorCode = (int)Constant.APIError.AccountNotFound; return(Ok(textLocalConfigurationDto)); } TextlocalConfiguration textlocalConfiguration = configurationService.GetCabOfficeTextlocalConfiguration(account.Token); TextLocalConfigurationDetail textLocalConfigurationDetail = new TextLocalConfigurationDetail(); textLocalConfigurationDetail.TextLocalAPIKey = textlocalConfiguration.APIKey; textLocalConfigurationDetail.TextLocalHash = textlocalConfiguration.Hash; textLocalConfigurationDetail.TextLocalPassword = textlocalConfiguration.Password; textLocalConfigurationDetail.TextLocalUsername = textlocalConfiguration.Username; textLocalConfigurationDto.textLocalConfiguration = textLocalConfigurationDetail; textLocalConfigurationDto.IsSuccess = true; textLocalConfigurationDto.Error = ""; textLocalConfigurationDto.ErrorCode = 0; return(Ok(textLocalConfigurationDto)); } catch (Exception ex) { textLocalConfigurationDto.Error = ex.ToString(); textLocalConfigurationDto.ErrorCode = (int)Constant.APIError.Exception; textLocalConfigurationDto.IsSuccess = false; return(Ok(textLocalConfigurationDto)); } }
public TextlocalConfiguration GetCabOfficeTextlocalConfiguration(string cabofficetoken) { using (DataContext context = new DataContext()) { TextlocalConfiguration textlocalConfiguration = (from txtlocal in context.TextlocalConfigurations join account in context.Accounts on txtlocal.CabofficeId equals account.Id where account.IsActive == true && account.Token == cabofficetoken select txtlocal).FirstOrDefault(); return(textlocalConfiguration); } }
public int AddOrUpdateTextLocalConfiguration(TextlocalConfiguration textLocalConfiguration) { return(configurationService.AddOrUpdateTextLocalConfiguration(textLocalConfiguration)); }