public async Task <IHttpActionResult> PostIPAddressRange(IPAddressRange iPAddressRange) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!iPAddressRange.ValidAddresses()) { return(BadRequest()); } WhitelistIP whitelistIP = new WhitelistIP() { RuleName = iPAddressRange.RuleName, StartIP = iPAddressRange.StartAddress.GetBytes(), EndIP = iPAddressRange.EndAddress.GetBytes(), IsActive = iPAddressRange.IsActive }; db.WhitelistIPs.Add(whitelistIP); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = iPAddressRange.Id }, iPAddressRange)); }
public async Task <IHttpActionResult> PutIPAddressRange(int id, IPAddressRange iPAddressRange) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != iPAddressRange.Id) { return(BadRequest()); } if (!iPAddressRange.ValidAddresses()) { return(BadRequest()); } WhitelistIP whitelistIP = new WhitelistIP() { Id = iPAddressRange.Id, RuleName = iPAddressRange.RuleName, StartIP = iPAddressRange.StartAddress.GetBytes(), EndIP = iPAddressRange.EndAddress.GetBytes(), IsActive = iPAddressRange.IsActive }; db.Entry(whitelistIP).State = EntityState.Modified; try { await db.SaveChangesAsync(); MemoryCacher.UpdateOrDelete(iPAddressRange); } catch (DbUpdateConcurrencyException) { if (!IPAddressRangeExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }