Пример #1
0
 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));
 }
Пример #2
0
 public bool IsDuplexBatchExists(DuplexBatch duplexBatch)
 {
     return
         (_db.DuplexBatches.Where(d =>
                                  d.DuplexBatchNumber == duplexBatch.DuplexBatchNumber &&
                                  d.Id != duplexBatch.Id)
          .ToList()
          .Any(d => d.DuplexBatchNumber == duplexBatch.DuplexBatchNumber));
 }
Пример #3
0
        public void UpdateDuplexBatch(DuplexBatch duplexBatch)
        {
            var duplexId = duplexBatch.DuplexId;
            var duplex   = GetDuplex(duplexId);

            if (duplex != null && !IsDuplexBatchExists(duplexBatch))
            {
                foreach (var duplexStrandBatch in duplexBatch.DuplexBatchStrandBatches)
                {
                    var strandBatch = _db.StrandBatches.Find(duplexStrandBatch.StrandBatchId);
                    if (strandBatch != null)
                    {
                        _db.Entry(duplexStrandBatch).State = EntityState.Added;
                    }
                }

                _db.Entry(duplexBatch).State = EntityState.Modified;
                _db.Entry(duplex).State      = EntityState.Modified;
                _db.SaveChanges();
            }
        }