public void UpdatePassTest()
        {
            try
            {
                var originalCondition = getConditionMock();
                originalCondition = service.Create(originalCondition);

                var newCondition = new FreightConditionBO();
                newCondition.Id = originalCondition.Id;
                newCondition.DangerousGoodsNumber = originalCondition.DangerousGoodsNumber;
                newCondition.DangerousGoodsName   = originalCondition.DangerousGoodsName;
                newCondition.DangerousGoodsName   = "Pressured-Cylinder";
                newCondition = service.Update(newCondition);

                var updatedCondition = service.Get(originalCondition.Id);

                Assert.Equal(originalCondition.Id, newCondition.Id);

                Assert.Equal("Pressured-Cylinder", newCondition.DangerousGoodsName);

                Assert.Equal(newCondition.DangerousGoodsName, updatedCondition.DangerousGoodsName);

                Assert.NotEqual(originalCondition.DangerousGoodsName, newCondition.DangerousGoodsName);
            }
            catch (Exception e)
            {
                Assert.True(false, e.Message);
            }
            finally
            {
                clearDb();
            }
        }
Beispiel #2
0
 public IActionResult Post([FromBody] FreightConditionBO condition)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     return(Ok(_facade.FreightConditionService.Create(condition)));
 }
        public FreightConditionBO getConditionMock()
        {
            FreightConditionBO condition = new FreightConditionBO()
            {
                DangerousGoodsNumber = "1200",
                DangerousGoodsName   = "Pressured-Cylinder"
            };

            return(condition);
        }
 public FreightConditionBO Create(FreightConditionBO condition)
 {
     if (condition == null)
     {
         return(null);
     }
     using (var uow = _facade.UnitOfWork)
     {
         var createdCondition = uow.FreightConditionRepository.Create(_conv.ConvertBO(condition));
         uow.Complete();
         return(_conv.Convert(createdCondition));
     }
 }
        public FreightCondition ConvertBO(FreightConditionBO conditionBO)
        {
            if (conditionBO == null)
            {
                return(null);
            }
            return(new FreightCondition()
            {
                Id = conditionBO.Id,
                DangerousGoodsNumber = conditionBO.DangerousGoodsNumber,
                DangerousGoodsName = conditionBO.DangerousGoodsName,

                Items = conditionBO.ItemIds?.Select(iID => new ItemFreightCondition()
                {
                    ItemID = iID,
                    FreightConditionID = conditionBO.Id
                }).ToList()
            });
        }
        public FreightConditionBO Update(FreightConditionBO condition)
        {
            if (condition == null)
            {
                return(null);
            }

            using (var uow = _facade.UnitOfWork)
            {
                var conditionEnt = uow.FreightConditionRepository.Get(condition.Id);
                if (conditionEnt == null)
                {
                    return(null);
                }

                var conditionUpdated = _conv.ConvertBO(condition);

                conditionEnt.Id = conditionUpdated.Id;
                conditionEnt.DangerousGoodsNumber = conditionUpdated.DangerousGoodsNumber;
                conditionEnt.DangerousGoodsName   = conditionUpdated.DangerousGoodsName;

                if (conditionUpdated != null)
                {
                    //Related to Item relation
                    conditionEnt.Items.RemoveAll(
                        fc => !conditionUpdated.Items.Exists(
                            ic => ic.ItemID == fc.ItemID &&
                            ic.FreightConditionID == fc.FreightConditionID));

                    conditionUpdated.Items.RemoveAll(
                        fc => conditionEnt.Items.Exists(
                            ic => ic.ItemID == fc.ItemID &&
                            ic.FreightConditionID == fc.FreightConditionID));

                    conditionEnt.Items.AddRange(
                        conditionUpdated.Items);
                }

                uow.Complete();
                return(_conv.Convert(conditionEnt));
            }
        }
Beispiel #7
0
 public IActionResult Put(int id, [FromBody] FreightConditionBO condition)
 {
     if (id != condition.Id)
     {
         return(BadRequest("Path ID does not match freight condition ID in JSON object."));
     }
     try
     {
         var updatedCondition = _facade.FreightConditionService.Update(condition);
         if (updatedCondition == null)
         {
             return(StatusCode(404, "No freight condition found with that ID"));
         }
         return(Ok(updatedCondition));
     }
     catch (Exception e)
     {
         return(StatusCode(404, e.Message + "/n" + e.StackTrace));
     }
 }
 public void reset()
 {
     condition = new FreightConditionBO();
 }