public static TAServerCouponTransaction ToServer(this TSBCouponTransaction value)
        {
            if (null == value)
            {
                return(null);
            }

            var inst = new TAServerCouponTransaction();

            inst.TransactionDate = value.TransactionDate.Value();
            inst.CouponStatus    = (int)value.TransactionType;
            inst.SerialNo        = value.CouponId;
            inst.CouponPK        = value.CouponPK.Value();
            inst.CouponType      = (int)value.CouponType;
            inst.FinishFlag      = (int)value.FinishFlag;
            inst.Price           = value.Price.Value();
            inst.SoldBy          = value.SoldBy;
            inst.SoldDate        = value.SoldDate.Value();
            inst.TSBId           = value.TSBId;
            if (value.TransactionType == TSBCouponTransaction.TransactionTypes.Stock)
            {
                inst.UserId = string.Empty;
            }
            else
            {
                inst.UserId = value.UserId;
            }
            inst.UserReceiveDate = value.UserReceiveDate.Value();

            return(inst);
        }
            public NRestResult <TSBCouponTransaction> SaveTransaction(TSBCouponTransaction value)
            {
                NRestResult <TSBCouponTransaction> ret;
                NRestClient client = NRestClient.CreateLocalClient();

                if (null == client)
                {
                    ret = new NRestResult <TSBCouponTransaction>();
                    ret.RestInvalidConfig();
                    return(ret);
                }

                if (null != value)
                {
                    ret = client.Execute <TSBCouponTransaction>(
                        RouteConsts.Coupon.SaveTSBCouponTransaction.Url, value);
                }
                else
                {
                    ret = new NRestResult <TSBCouponTransaction>();
                    ret.ParameterIsNull();
                    ret.data = null;
                }
                return(ret);
            }
 /// <summary>
 /// Update Coupon Transaction - Return coupon (restore back to stock).
 /// </summary>
 /// <param name="value">The TSB coupon transaction.</param>
 public void Return(TSBCouponTransaction value)
 {
     if (value.TransactionType != TSBCouponTransaction.TransactionTypes.Lane)
     {
         return;
     }
     value.TransactionType = TSBCouponTransaction.TransactionTypes.Stock;
     value.UserId          = string.Empty;
     value.FullNameEN      = string.Empty;
     value.FullNameTH      = string.Empty;
     value.UserReceiveDate = DateTime.MinValue;
 }
 /// <summary>
 /// Update Coupon Transaction - Unsold by TSB (restored back to stock).
 /// </summary>
 /// <param name="value">The TSB coupon transaction.</param>
 public void UnsoldByTSB(TSBCouponTransaction value)
 {
     //if (null == User) return;
     if (value.TransactionType != TSBCouponTransaction.TransactionTypes.SoldByTSB)
     {
         return;
     }
     value.TransactionType  = TSBCouponTransaction.TransactionTypes.Stock;
     value.SoldBy           = User.UserId;
     value.SoldByFullNameEN = User.FullNameEN;
     value.SoldByFullNameTH = User.FullNameTH;
     value.SoldDate         = DateTime.MinValue;
 }
 /// <summary>
 /// Update Coupon Transaction - Sold by TSB.
 /// </summary>
 /// <param name="value">The TSB coupon transaction.</param>
 public void SoldByTSB(TSBCouponTransaction value)
 {
     //if (null == User) return;
     if (value.TransactionType != TSBCouponTransaction.TransactionTypes.Stock)
     {
         return;
     }
     value.TransactionType  = TSBCouponTransaction.TransactionTypes.SoldByTSB;
     value.SoldBy           = User.UserId;
     value.SoldByFullNameEN = User.FullNameEN;
     value.SoldByFullNameTH = User.FullNameTH;
     value.SoldDate         = DateTime.Now;
     //value.UserReceiveDate = DateTime.Now;
 }
 /// <summary>
 /// Update Coupon Transaction - Unsold user coupon (restore back to Lane).
 /// </summary>
 /// <param name="value">The TSB coupon transaction.</param>
 public void UnsoldByLane(TSBCouponTransaction value)
 {
     //if (null == User) return;
     if (value.TransactionType != TSBCouponTransaction.TransactionTypes.SoldByLane)
     {
         return;
     }
     value.TransactionType  = TSBCouponTransaction.TransactionTypes.Lane;
     value.SoldBy           = string.Empty;
     value.SoldByFullNameEN = string.Empty;
     value.SoldByFullNameTH = string.Empty;
     value.SoldDate         = DateTime.MinValue;
     //value.UserReceiveDate = DateTime.MinValue;
 }
        public NDbResult <List <TSBCouponTransaction> > GetTSBCouponTransactions([FromBody] TSB value)
        {
            NDbResult <List <TSBCouponTransaction> > result;

            if (null == value)
            {
                result = new NDbResult <List <TSBCouponTransaction> >();
                result.ParameterIsNull();
            }
            else
            {
                result = TSBCouponTransaction.GetTSBCouponTransactions(value);
            }
            return(result);
        }
        public NDbResult SaveTransactions([FromBody] List <TSBCouponTransaction> values)
        {
            NDbResult result;

            if (null == values)
            {
                result = new NDbResult();
                result.ParameterIsNull();
            }
            else
            {
                result = TSBCouponTransaction.SaveTransactions(values);
            }
            return(result);
        }
 /// <summary>
 /// Update Coupon Transaction - Assigned to User/Lane.
 /// </summary>
 /// <param name="value">The TSB coupon transaction.</param>
 public void Borrow(TSBCouponTransaction value)
 {
     if (null == User)
     {
         return;
     }
     if (value.TransactionType != TSBCouponTransaction.TransactionTypes.Stock)
     {
         return;
     }
     value.TransactionType = TSBCouponTransaction.TransactionTypes.Lane;
     value.UserId          = User.UserId;
     value.FullNameEN      = User.FullNameEN;
     value.FullNameTH      = User.FullNameTH;
     value.UserReceiveDate = DateTime.Now;
 }
        public NDbResult <TSBCouponTransaction> SaveTransaction(
            [FromBody] TSBCouponTransaction value)
        {
            NDbResult <TSBCouponTransaction> result;

            if (null == value)
            {
                result = new NDbResult <TSBCouponTransaction>();
                result.ParameterIsNull();
            }
            else
            {
                result = TSBCouponTransaction.SaveTransaction(value);
            }
            return(result);
        }
        public static TSBCouponTransaction ToLocal(this TAServerCouponTransaction value)
        {
            if (null == value)
            {
                return(null);
            }
            var inst = new TSBCouponTransaction();

            inst.TransactionDate = value.TransactionDate.Value();
            inst.TransactionType = (TSBCouponTransaction.TransactionTypes)value.CouponStatus.Value();
            inst.CouponId        = value.SerialNo;
            inst.CouponPK        = value.CouponPK.Value();
            inst.CouponType      = (CouponType)value.CouponType.Value();
            inst.FinishFlag      = (TSBCouponTransaction.FinishedFlags)value.FinishFlag.Value();
            inst.Price           = value.Price.Value();
            inst.SoldBy          = value.SoldBy;
            var soldUsr = (!string.IsNullOrWhiteSpace(value.SoldBy)) ?
                          User.GetUser(value.SoldBy).Value() : null;

            if (null != soldUsr)
            {
                inst.SoldByFullNameEN = soldUsr.FullNameEN;
                inst.SoldByFullNameTH = soldUsr.FullNameTH;
            }
            inst.SoldDate = value.SoldDate.Value();
            inst.TSBId    = value.TSBId;
            if (inst.TransactionType == TSBCouponTransaction.TransactionTypes.Stock)
            {
                inst.UserId     = string.Empty;
                inst.FullNameEN = string.Empty;
                inst.FullNameTH = string.Empty;
            }
            else
            {
                inst.UserId = value.UserId;
                var user = (!string.IsNullOrWhiteSpace(value.UserId)) ?
                           User.GetUser(value.UserId).Value() : null;
                if (null != user)
                {
                    inst.FullNameEN = user.FullNameEN;
                    inst.FullNameTH = user.FullNameTH;
                }
            }
            inst.UserReceiveDate = value.UserReceiveDate.Value();

            return(inst);
        }
        private void cmdAddCoupon_Click(object sender, RoutedEventArgs e)
        {
            string idRange = txtRange.Text;

            txtRange.Text = string.Empty;

            var tsb = listView.SelectedItem as TSB;

            if (null == tsb)
            {
                return;
            }

            var ids = idRange.ParseRange(0, 999999);

            if (null != ids)
            {
                // remove duplicate id.
                ids = ids.Distinct();
                foreach (var id in ids)
                {
                    TSBCouponTransaction item = new TSBCouponTransaction();
                    item.TSBId = tsb.TSBId;
                    if ((cbCouponType.SelectedIndex == 0))
                    {
                        item.CouponId   = "ข" + id.ToString("D6");
                        item.CouponType = CouponType.BHT35;
                        item.Price      = 665;
                    }
                    else
                    {
                        item.CouponId   = "C" + id.ToString("D6");
                        item.CouponType = CouponType.BHT80;
                        item.Price      = 1520;
                    }
                    ops.Coupons.SaveTransaction(item);
                }

                RefreshCoupon(tsb);
            }
        }