public IHttpActionResult Update([FromUri] int duplexId, [FromUri] int duplexBatchId, [FromBody] DuplexBatchModel model) { if (ModelState.IsValid) { var duplexBatch = _duplexesService.GetDuplexBatch(duplexBatchId); if (duplexBatch != null) { duplexBatch.DuplexBatchStrandBatches.Clear(); Mapper.Map(model, duplexBatch); duplexBatch.DuplexBatchNumber = string.Format("{0}_{1}", duplexBatch.RunId, duplexBatch.Position); if (!_duplexesService.IsDuplexBatchExists(duplexBatch)) { _duplexesService.UpdateDuplexBatch(duplexBatch); model.Id = duplexBatch.Id; } else { model.SetError("DuplexBatchNumber", "Duplicate strand batch"); } } } else { foreach (var message in ModelState) { model.SetError(message.Key, message.ToString()); } } return(Ok(model)); }
public IHttpActionResult CreateDuplexBatch([FromUri] int duplexId, [FromBody] DuplexBatchModel model) { if (ModelState.IsValid) { var duplexBatch = new DuplexBatch(model.RunId, model.Position); Mapper.Map(model, duplexBatch); if (!_duplexesService.IsDuplexBatchExists(duplexBatch)) { _duplexesService.CreateDuplexBatch(duplexBatch); model.Id = duplexBatch.Id; } else { model.SetError("DuplexBatchNumber", "Duplicate strand batch"); } } else { foreach (var message in ModelState) { model.SetError(message.Key, message.ToString()); } } return(Ok(model)); }