Esempio n. 1
0
 /// <summary>
 /// 增加
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public WebResult <bool> Add_OilCard(OilCard model)
 {
     using (DbRepository entities = new DbRepository())
     {
         if (Cache_Get_OilCardList().Where(x => x.CardNO == model.CardNO && (x.Flag & (long)GlobalFlag.Removed) == 0).Any())
         {
             return(Result(false, ErrorCode.datadatabase_no_had));
         }
         model.ID          = Guid.NewGuid().ToString("N");
         model.CreatedTime = DateTime.Now;
         model.Flag        = (long)GlobalFlag.Normal;
         model.UpdatedTime = DateTime.Now;
         model.UpdaterID   = model.CreatedUserID = Client.LoginUser.ID;
         entities.OilCard.Add(model);
         if (entities.SaveChanges() > 0)
         {
             var list = Cache_Get_OilCardList();
             list.Add(model);
             return(Result(true));
         }
         else
         {
             return(Result(false, ErrorCode.sys_fail));
         }
     }
 }
Esempio n. 2
0
    public Card createCard(int cardId)
    {
        Card card = null;

        switch (cardId)
        {
        case 1001:
            card = new PortalCard();
            break;

        case 1002:
            card = new StrengtheningTowerCard();
            break;

        case 1003:
            card = new StrengtheningAllTowerCard();
            break;

        case 1004:
            card = new OilCard();
            break;

        case 1005:
            card = new SnowstormCard();
            break;

        case 1006:
            card = new BarrierCard();
            break;

        case 1007:
            card = new HornCard();
            break;

        case 1008:
            card = new CrazyCard();
            break;

        case 1009:
            card = new HardeningCard();
            break;

        case 1010:
            card = new UpgradeCard();
            break;

        case 1011:
            card = new BlackCard();
            break;

        case 1012:
            card = new WhiteCard();
            break;
        }
        return(card);
    }
Esempio n. 3
0
        /// <summary>
        /// 增加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public WebResult <bool> Add_Waste(Waste model)
        {
            using (DbRepository entities = new DbRepository())
            {
                var oilModel = new OilCard();
                model.ID            = Guid.NewGuid().ToString("N");
                model.UpdatedTime   = model.CreatedTime = DateTime.Now;
                model.CreatedUserID = model.UpdaterID = Client.LoginUser.ID;
                model.Flag          = (long)GlobalFlag.Normal;
                entities.Waste.Add(model);
                if (model.Code == WasteCode.Oil)
                {
                    oilModel = entities.OilCard.Find(model.OilID);
                    if (oilModel == null)
                    {
                        return(Result(false, ErrorCode.sys_param_format_error));
                    }
                    if (oilModel.Balance < model.Money)
                    {
                        return(Result(false, ErrorCode.card__no_had_money));
                    }
                    oilModel.Balance -= model.Money;
                }
                if (entities.SaveChanges() > 0)
                {
                    var list = Cache_Get_WasteList();
                    if (model.Code == WasteCode.Oil)
                    {
                        var oilCardList = Cache_Get_OilCardList();
                        var index       = oilCardList.FindIndex(x => x.ID.Equals(model.OilID));
                        if (index > -1)
                        {
                            oilCardList[index] = oilModel;
                        }
                        else
                        {
                            oilCardList.Add(oilModel);
                        }
                    }

                    list.Add(model);
                    return(Result(true));
                }
                else
                {
                    return(Result(false, ErrorCode.sys_fail));
                }
            }
        }
Esempio n. 4
0
 /// <summary>
 /// 修改
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 public JsonResult Update(OilCard entity)
 {
     ModelState.Remove("UpdaterID");
     ModelState.Remove("UpdatedTime");
     ModelState.Remove("CreatedTime");
     ModelState.Remove("CreatedUserID");
     if (ModelState.IsValid)
     {
         var result = WebService.Update_OilCard(entity);
         return(JResult(result));
     }
     else
     {
         return(ParamsErrorJResult(ModelState));
     }
 }
Esempio n. 5
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public WebResult <bool> Update_OilCard(OilCard model)
        {
            using (DbRepository entities = new DbRepository())
            {
                if (Cache_Get_OilCardList().Where(x => x.CardNO == model.CardNO && (x.Flag & (long)GlobalFlag.Removed) == 0 && !model.ID.Equals(x.ID)).Any())
                {
                    return(Result(false, ErrorCode.datadatabase_no_had));
                }
                var oldEntity = entities.OilCard.Find(model.ID);
                if (oldEntity != null)
                {
                    oldEntity.Company     = model.Company;
                    oldEntity.CardNO      = model.CardNO;
                    oldEntity.CoachID     = model.CoachID;
                    oldEntity.UpdatedTime = DateTime.Now;
                    oldEntity.UpdaterID   = Client.LoginUser.ID;
                }
                else
                {
                    return(Result(false, ErrorCode.sys_param_format_error));
                }

                if (entities.SaveChanges() > 0)
                {
                    var list  = Cache_Get_OilCardList();
                    var index = list.FindIndex(x => x.ID.Equals(model.ID));
                    if (index > -1)
                    {
                        list[index] = oldEntity;
                    }
                    else
                    {
                        list.Add(oldEntity);
                    }
                    return(Result(true));
                }
                else
                {
                    return(Result(false, ErrorCode.sys_fail));
                }
            }
        }