Пример #1
0
        /// <summary>
        /// 选择寝室信息
        /// </summary>
        /// <param name="id">寝室编号</param>
        /// <param name="context">数据库上下文对象</param>
        /// <returns></returns>
        public static async Task <BunkInfo> InsertAsync(long id, ApplicationDbContext context)
        {
            var user = await PSURepository.GetUserByIdAsync(CurrentUser.UserId, context);

            var dorm = await DormitoryRepository.GetDormAsync(id, context);

            //数据不准确
            if (user == null || dorm == null)
            {
                return(new BunkInfo
                {
                    Id = -1
                });
            }

            // 寝室已被选完
            if (dorm.SelectedCount == dorm.Count)
            {
                return(new BunkInfo
                {
                    Id = -2
                });
            }

            dorm.SelectedCount = Convert.ToInt16(dorm.SelectedCount + 1);

            BunkInfo model = new BunkInfo
            {
                BuildingId     = dorm.BuildingId,
                BuildingName   = dorm.BuildingName,
                Chosen         = dorm.SelectedCount,
                Count          = dorm.Count,
                DormId         = dorm.Id,
                DormName       = dorm.Name,
                Floor          = dorm.Floor,
                InstructorId   = user.InstructorId,
                MajorClassId   = user.MajorClassId,
                MajorClassName = user.MajorClass,
                StudentId      = user.Id,
                StudentName    = user.Name,
                BunkType       = dorm.BunkName,
            };

            await context.BunkInfo.AddAsync(model);

            return(model);
        }
Пример #2
0
        private BunkInfo constructBunkView(Bunk bunk, MatchedPolicy policy, BasicPrice price)
        {
            var result = new BunkInfo()
            {
                Policy = new PolicyView()
                {
                    Id               = policy.OriginalPolicy == null ? Guid.Empty : policy.OriginalPolicy.Id,
                    Owner            = policy.Provider,
                    Type             = policy.PolicyType,
                    CustomerResource = false
                }
            };

            result.ShowPrice = policy.ParValue != 0;
            if (policy.PolicyType == PolicyType.Special)
            {
                // 特殊票是单独处理的
                var specialPolicy = policy.OriginalPolicy as DataTransferObject.Policy.SpecialPolicyInfo;
                result.Code        = bunk == null ? string.Empty : bunk.Code;
                result.SeatCount   = bunk == null ? specialPolicy.ResourceAmount : bunk.SeatCount; // 剩余位置数 从政策上获取
                result.Fare        = policy.ParValue.TrimInvaidZero();                             // 票面价从政策上取
                result.Rebate      = string.Empty;                                                 // 无返点
                result.Amount      = policy.SettleAmount;
                result.Description = "特殊票";
                result.BunkType    = bunk == null ? new BunkType?() : bunk.Type;
                switch (specialPolicy.Type)
                {
                case SpecialProductType.Singleness:
                case SpecialProductType.Disperse:
                    result.Policy.CustomerResource = true;
                    break;

                case SpecialProductType.CostFree:
                    result.Policy.CustomerResource = !specialPolicy.SynBlackScreen;
                    result.ShowPrice = true;
                    break;
                }
            }
            else
            {
                result.Code      = bunk.Code;
                result.SeatCount = bunk.SeatCount;
                result.Fare      = policy.ParValue.TrimInvaidZero();
                result.Rebate    = policy.Commission.TrimInvaidZero();
                result.Amount    = policy.SettleAmount;

                if (policy.PolicyType == PolicyType.Bargain && bunk is Service.FlightQuery.Domain.GeneralBunk)
                {
                    result.Description = "特价票";
                }
                else
                {
                    if (bunk is Service.FlightQuery.Domain.FirstOrBusinessBunk)
                    {
                        result.Description = (bunk as Service.FlightQuery.Domain.FirstOrBusinessBunk).Description;
                    }
                    else if (bunk is Service.FlightQuery.Domain.EconomicBunk)
                    {
                        result.Description = "经济舱";
                    }
                    else if (bunk is Service.FlightQuery.Domain.PromotionBunk)
                    {
                        result.Description = (bunk as Service.FlightQuery.Domain.PromotionBunk).Description;
                    }
                    else if (bunk is Service.FlightQuery.Domain.ProductionBunk)
                    {
                        result.Description = "往返产品";
                    }
                    else
                    {
                        result.Description = string.Empty;
                    }
                }
                result.BunkType = bunk.Type;
            }
            if (bunk != null && bunk is Service.FlightQuery.Domain.GeneralBunk)
            {
                result.Discount = ((bunk as Service.FlightQuery.Domain.GeneralBunk).Discount).TrimInvaidZero();
                if (policy.PolicyType == PolicyType.Special)
                {
                    result.RenderDiscount = price != null && policy.ParValue != 0 ? Math.Round(policy.ParValue / price.Price, 2).ToString() : string.Empty;
                }
                else
                {
                    result.RenderDiscount = ((bunk as Service.FlightQuery.Domain.GeneralBunk).Discount).TrimInvaidZero();
                }
            }
            else
            {
                result.RenderDiscount = result.Discount = string.Empty;
            }
            // 退改签规定
            // 普通政策时,获取基础数据中普通舱位的退改签信息
            // 其他情况,获取政策上的退改签信息
            if ((policy.PolicyType == PolicyType.Normal || policy.PolicyType == PolicyType.NormalDefault || policy.PolicyType == PolicyType.OwnerDefault) && bunk is Service.FlightQuery.Domain.GeneralBunk)
            {
                result.EI = GetGeneralBunkRegulation(bunk);
            }
            else
            {
                if (policy.OriginalPolicy is DataTransferObject.Policy.IHasRegulation)
                {
                    var regulation = policy.OriginalPolicy as DataTransferObject.Policy.IHasRegulation;
                    result.EI = GetRegulation(regulation);
                }
                else
                {
                    result.EI = string.Empty;
                }
            }
            result.SuportChild = bunk != null && bunk.SuportChild;
            return(result);
        }