Beispiel #1
0
        /// <summary>
        /// 增加刮刮卡
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public string Add_ScratchCard(Domain.ScratchCard.Update model)
        {
            if (model == null ||
                !model.Name.IsNotNullOrEmpty() ||
                !model.OngoingTitle.IsNotNullOrEmpty() ||
                !model.OngoingTitle.IsNotNullOrEmpty() ||
                !model.PreheatingTitle.IsNotNullOrEmpty() ||
                !model.OverTitle.IsNotNullOrEmpty() ||
                model.OngoingTime == null ||
                model.OverTime == null ||
                !model.RepeatNotice.IsNotNullOrEmpty() ||
                !model.OnePrize.IsNotNullOrEmpty() ||
                !model.TwoPrize.IsNotNullOrEmpty() ||
                !model.ThreePrize.IsNotNullOrEmpty() ||
                !model.OnePrize.IsNotNullOrEmpty()
                )
            {
                return("数据为空");
            }
            if (model.OngoingTime < DateTime.Now)
            {
                return("开始时间需比晚于当前时间");
            }
            if (model.OverTime < model.OngoingTime || model.OverTime < DateTime.Now)
            {
                return("结束时间必须大于当前时间和开始时间");
            }
            using (DbRepository entities = new DbRepository())
            {
                var addEntity = model.AutoMap <Domain.ScratchCard.Update, ScratchCard>();
                addEntity.UNID        = Guid.NewGuid().ToString("N");
                addEntity.CreatedTime = DateTime.Now;
                addEntity.UpdatedTime = DateTime.Now;
                addEntity.Flag        = (long)GlobalFlag.Normal;
                //addEntity.AppId = this.Client.AppId;
                entities.ScratchCard.Add(addEntity);

                var addPrizeEntity = model.AutoMap <Domain.ScratchCard.Update, Prize>();
                if (model.AllCountLimt < model.DayLimt)
                {
                    return("个人抽奖次数总计要大于或等于每天次数限制");
                }

                if (model.ExpectedPeopleCount < (model.OnePrizeCount + model.TwoPrizeCount + model.ThreePrizeCount))
                {
                    return("预计参与人数须大于奖品的总数");
                }

                addPrizeEntity.UNID       = Guid.NewGuid().ToString("N");
                addPrizeEntity.TargetCode = (int)TargetCode.ScratchCard;
                addPrizeEntity.TargetID   = addEntity.UNID;
                addPrizeEntity.AllCount   = addPrizeEntity.OnePrizeCount + addPrizeEntity.TwoPrizeCount + addPrizeEntity.ThreePrizeCount;
                entities.Prize.Add(addPrizeEntity);

                return(entities.SaveChanges() > 0 ? "" : "保存出错");
            }
        }
Beispiel #2
0
        /// <summary>
        /// 增加刮刮卡
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public string Update_ScratchCard(Domain.ScratchCard.Update model, string unid)
        {
            if (model == null ||
                !model.Name.IsNotNullOrEmpty() ||
                !model.OngoingTitle.IsNotNullOrEmpty() ||
                !model.OngoingTitle.IsNotNullOrEmpty() ||
                !model.PreheatingTitle.IsNotNullOrEmpty() ||
                !model.OverTitle.IsNotNullOrEmpty() ||
                model.OngoingTime == null ||
                model.OverTime == null ||
                !model.RepeatNotice.IsNotNullOrEmpty() ||
                !model.PreheatingImage.IsNotNullOrEmpty() ||
                !model.OngoingImage.IsNotNullOrEmpty() ||
                !model.OverImage.IsNotNullOrEmpty() ||
                !model.OnePrize.IsNotNullOrEmpty() ||
                !model.TwoPrize.IsNotNullOrEmpty() ||
                !model.ThreePrize.IsNotNullOrEmpty() ||
                !model.OnePrize.IsNotNullOrEmpty()
                )
            {
                return("数据为空");
            }
            if (model.OngoingTime < DateTime.Now)
            {
                return("开始时间需比晚于当前时间");
            }
            if (model.OverTime < model.OngoingTime || model.OverTime < DateTime.Now)
            {
                return("结束时间必须大于当前时间和开始时间");
            }
            if (model.AllCountLimt < model.DayLimt)
            {
                return("个人抽奖次数总计要大于或等于每天次数限制");
            }
            using (DbRepository entities = new DbRepository())
            {
                var oldEntity = entities.ScratchCard.Find(unid);
                if (oldEntity != null)
                {
                    model.AutoMap <Domain.ScratchCard.Update, ScratchCard>(oldEntity);
                    oldEntity.UpdatedTime = DateTime.Now;
                    var oldPrizeEntity = entities.Prize.Where(x => x.TargetCode == (int)TargetCode.ScratchCard && x.TargetID.Equals(unid)).FirstOrDefault();
                    if (oldPrizeEntity != null)
                    {
                        oldPrizeEntity.OnePrize            = model.OnePrize;
                        oldPrizeEntity.TwoPrize            = model.TwoPrize;
                        oldPrizeEntity.ThreePrize          = model.ThreePrize;
                        oldPrizeEntity.IsShowCount         = model.IsShowCount;
                        oldPrizeEntity.ExpectedPeopleCount = model.ExpectedPeopleCount;
                        oldPrizeEntity.DayLimt             = model.DayLimt;
                        oldPrizeEntity.AllCountLimt        = model.AllCountLimt;

                        oldPrizeEntity.AllCount = oldPrizeEntity.OnePrizeCount + oldPrizeEntity.TwoPrizeCount + oldPrizeEntity.ThreePrizeCount;
                    }
                    else
                    {
                        return("数据为空");
                    }
                }
                else
                {
                    return("数据为空");
                }

                return(entities.SaveChanges() > 0 ? "" : "保存出错");
            }
        }