示例#1
0
        public IHttpActionResult CreateStrandBatch([FromUri] int strandId, [FromBody] StrandBatchModel model)
        {
            if (ModelState.IsValid)
            {
                var strandBatch = new StrandBatch(model.RunId, model.Position);
                Mapper.Map(model, strandBatch);
                if (!_strandsService.IsStrandBatchExist(strandBatch))
                {
                    _strandsService.CreateStrandBatch(strandBatch);
                    model.Id = strandBatch.Id;
                }
                else
                {
                    model.SetError("BatchNumber", "Duplicate strand batch");
                }
            }
            else
            {
                foreach (var message in ModelState)
                {
                    model.SetError(message.Key, message.ToString());
                }
            }

            return(Ok(model));
        }
示例#2
0
        public IHttpActionResult Update([FromUri] int strandId, [FromUri] int strandBatchId, [FromBody] StrandBatchModel model)
        {
            if (ModelState.IsValid)
            {
                var strandBatch = _strandsService.GetStrandBatch(strandBatchId);
                if (strandBatch != null)
                {
                    Mapper.Map(model, strandBatch);
                    strandBatch.BatchNumber = string.Format("{0}_{1}", strandBatch.RunId, strandBatch.Position);
                    var isDuplicate = _strandsService.IsStrandBatchExist(strandBatch);
                    if (!isDuplicate)
                    {
                        _strandsService.UpdateStrandBatch(strandBatch);
                    }
                    else
                    {
                        model.SetError("BatchNumber", "Duplicate strand batch");
                    }
                }
                else
                {
                    return(NotFound());
                }
            }

            return(Ok(model));
        }