Exemple #1
0
        /// <summary>上
        /// 转换为MailAddress
        /// </summary>
        /// <returns></returns>
        public MailAddress AsMailAddress()
        {
            MailAddress mailAddress = null;

            if (this.AddressId <= 0) //创建
            {
                mailAddress = MailAddress.New();
            }
            else       //编辑
            {
                mailAddress = new MailAddressService().Get(this.AddressId);
                if (mailAddress == null)        //找不到实体
                {
                    return(null);
                }
                mailAddress.LastModified = DateTime.UtcNow;
            }
            mailAddress.UserId    = UserContext.CurrentUser.UserId;
            mailAddress.Address   = this.Address;
            mailAddress.Addressee = this.Addressee;
            mailAddress.PostCode  = this.PostCode;
            mailAddress.Tel       = this.Tel;

            return(mailAddress);
        }
        public ActionResult _CreateRecord(long giftId)
        {
            //获取默认邮寄地址
            MailAddress mailAddress         = null;
            IEnumerable <MailAddress> mails = new MailAddressService().GetsOfUser(UserContext.CurrentUser.UserId);

            //从数据库中取实体,取不到则创建
            mailAddress = mails.Count() > 0 ? mails.First() : MailAddress.New();
            var mailAddressEditModel = mailAddress.AsEditModel();

            //创建兑换记录的EditModel
            IUser     currentUser     = UserContext.CurrentUser;
            PointGift gift            = pointMallService.GetGift(giftId);
            var       recordEditModel = new RecordEditModel();

            recordEditModel.Address     = mailAddressEditModel.Address ?? string.Empty;
            recordEditModel.Addressee   = mailAddressEditModel.Addressee ?? string.Empty;
            recordEditModel.PostCode    = mailAddressEditModel.PostCode ?? string.Empty;
            recordEditModel.Tel         = mailAddressEditModel.Tel ?? string.Empty;
            recordEditModel.GiftId      = giftId;
            recordEditModel.Payer       = currentUser.DisplayName;
            recordEditModel.PayerUserId = currentUser.UserId;
            recordEditModel.GiftName    = gift.Name;
            ViewData["recordEditModel"] = recordEditModel;

            return(View(mailAddressEditModel));
        }