public bool Add(IpAddressElement ipAddressElement) { using (var db = new LicenseDbEntities()) { if (db.IpFilters.Any(x => x.Address == ipAddressElement.Address)) { return(false); } db.IpFilters.Add(new IpFilter() { Address = ipAddressElement.Address.Trim(), Denied = ipAddressElement.Denied }); db.SaveChanges(); } return(true); }
public bool Edit(int id, IpAddressElement ipAddressElement) { using (var db = new LicenseDbEntities()) { if (db.IpFilters.Any(x => x.Address == ipAddressElement.Address && x.Id != id)) { return(false); } var result = db.IpFilters.FirstOrDefault(x => x.Id == id); if (result != null) { result.Address = ipAddressElement.Address.Trim(); result.Denied = ipAddressElement.Denied; db.SaveChanges(); } } return(true); }
/// <summary> /// Searches using the search model. /// </summary> /// <param name="searchModel">The search model.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">searchModel</exception> public virtual IListPage Search(CustomerSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } EmailElement.SetValue(searchModel.Email); FirstNameElement.SetValue(searchModel.FirstName); LastNameElement.SetValue(searchModel.LastName); if (searchModel.DateOfBirth.HasValue) { DateOfBirthMonthElement.SelectByValue( searchModel.DateOfBirth.Value.Month.ToString()); DateOfBirthDayElement.SelectByValue( searchModel.DateOfBirth.Value.Day.ToString()); } else { DateOfBirthMonthElement.SelectByIndex(0); DateOfBirthDayElement.SelectByIndex(0); } CompanyElement.SetValue(searchModel.Company); IpAddressElement.SetValue(searchModel.IpAddress); var currentlySelectedItems = CustomerRoles.GetSelectedOptions(); if (searchModel.CustomerRoles != null) { foreach (var opt in currentlySelectedItems) { if (!searchModel.CustomerRoles?.Contains(opt) ?? true) { CustomerRoles.DeselectItem(opt); } // Check if there are items that have yet to be selected. if (searchModel.CustomerRoles?.Except(currentlySelectedItems).Any() ?? false) { foreach (var _opt in searchModel.CustomerRoles) { CustomerRoles.SelectItem(_opt); } } } } SearchElement.Click(); // Wait for the ajax indicator to toggle. WrappedDriver .Wait(TimeSpan.FromSeconds(10)) .TrySequentialWait( out var exception, d => IsAjaxBusy(), d => !IsAjaxBusy()); // Page should reload. Load(); return(this); }