public IHttpActionResult Validate([FromBody] DuplexModel model) { try { var duplex = new Duplex(model.DuplexId); Mapper.Map(model, duplex); if (_duplexesService.IsDuplexExists(duplex)) { model.SetError("Duplex", "A duplex with this configuration already exists."); } return(Ok(model)); } catch (Exception) { return(null); } }
public IHttpActionResult CreateMultiple([FromBody] ICollection <DuplexModel> models) { var duplexes = new List <Duplex>(); foreach (var duplexModel in models) { var duplex = new Duplex(); Mapper.Map(duplexModel, duplex); if (!_duplexesService.IsDuplexExists(duplex)) { _duplexesService.CreateDuplex(duplex); duplexModel.Id = duplex.Id; } else { duplexModel.SetError("Duplex", "A duplex with this configuration already exists."); } } return(Ok(models)); }