public ShipmentGoodEntity Create(ShipmentGoodEntity ShipmentGoodEntity)
        {
            ShipmentGoods shipmentGood = ShipmentGoodEntity.ToModel();

            smartDeliveryContext.ShipmentGoods.Add(shipmentGood);
            smartDeliveryContext.SaveChanges();
            return(new ShipmentGoodEntity(shipmentGood));
        }
 public ShipmentGoods ToModel(ShipmentGoods shipmentGood = null)
 {
     if (shipmentGood == null)
     {
         shipmentGood    = new ShipmentGoods();
         shipmentGood.Id = Guid.NewGuid();
     }
     shipmentGood.GoodsId    = this.GoodsId;
     shipmentGood.ShipmentId = this.ShipmentId;
     return(shipmentGood);
 }
        public ShipmentGoodEntity Get(Guid ShipmentGoodId)
        {
            ShipmentGoods shipmentGood = smartDeliveryContext.ShipmentGoods.Where(m => m.Id == ShipmentGoodId)
                                         .Include(u => u.Goods)
                                         .Include(u => u.Shipment)
                                         .FirstOrDefault();

            if (shipmentGood == null)
            {
                throw new BadRequestException("ShipmentGood khong ton tai");
            }
            return(new ShipmentGoodEntity(shipmentGood, shipmentGood.Goods, shipmentGood.Shipment));
        }
        public bool Delete(Guid ShipmentGoodId)
        {
            ShipmentGoods shipmentGood = smartDeliveryContext.ShipmentGoods.Where(m => m.Id == ShipmentGoodId)
                                         .Include(u => u.Goods)
                                         .Include(u => u.Shipment)
                                         .FirstOrDefault();

            if (shipmentGood == null)
            {
                throw new BadRequestException("ShipmentGood khong ton tai");
            }
            smartDeliveryContext.ShipmentGoods.Remove(shipmentGood);
            smartDeliveryContext.SaveChanges();
            return(true);
        }
        public ShipmentGoodEntity Update(Guid ShipmentGoodId, ShipmentGoodEntity ShipmentGoodEntity)
        {
            ShipmentGoods shipmentGood = smartDeliveryContext.ShipmentGoods.Where(m => m.Id == ShipmentGoodId)
                                         .Include(u => u.Goods)
                                         .Include(u => u.Shipment)
                                         .FirstOrDefault();

            if (shipmentGood == null)
            {
                throw new BadRequestException("ShipmentGood khong ton tai");
            }
            ShipmentGoodEntity.ToModel(shipmentGood);
            smartDeliveryContext.ShipmentGoods.Update(shipmentGood);
            smartDeliveryContext.SaveChanges();
            return(new ShipmentGoodEntity(shipmentGood));
        }
 public ShipmentGoodEntity(ShipmentGoods shipmentGood, params object[] args)
 {
     this.Id         = shipmentGood.Id;
     this.ShipmentId = shipmentGood.ShipmentId;
     this.GoodsId    = shipmentGood.GoodsId;
     foreach (var arg in args)
     {
         if (arg is Shipment)
         {
             this.Shipment = shipmentGood.Shipment == null ? null : new ShipmentEntity(arg as Shipment);
         }
         if (arg is Goods)
         {
             this.Goods = shipmentGood.Goods == null ? null : new GoodsEntity(arg as Goods);
         }
     }
 }