Exemple #1
0
        public IWsModel <ReqAddCar, ResCarConciseInfo> AddCarInfo([FromBody] WsModel <ReqAddCar, ResCarConciseInfo> model)
        {
            if (model == null)
            {
                return(new WsModel <ReqAddCar, ResCarConciseInfo>().Fail(ErrorCode.PARAM_NULL, "参数为空"));
            }
            if (model.Request == null)
            {
                return(model.Fail(ErrorCode.PARAM_NULL, "参数为空"));
            }
            if (!model.Request.Valid4Enum())
            {
                return(model.Fail(ErrorCode.PARAM_INVALID, "枚举参数无效"));
            }
            if (!model.Request.Valid4AddCar())
            {
                return(model.Fail(ErrorCode.PARAM_INVALID, "参数无效"));
            }
            var dbscar = new DBsCar();

            if (dbscar.GetBrandSeriesDetail(model.Request.BrandId, ValidityState.Enabled) == null)
            {
                return(model.Fail(ErrorCode.PARAM_INVALID, "参数BrandId无效"));
            }
            if (dbscar.GetBrandSeriesDetail(model.Request.SeriesId, ValidityState.Enabled) == null)
            {
                return(model.Fail(ErrorCode.PARAM_INVALID, "参数SeriesId无效"));
            }
            var dbsaccount = new DbsAccount();

            if (dbsaccount.ByOpenId(model.Request.AccountId, ValidityState.Enabled) == null)
            {
                return(model.Fail(ErrorCode.PARAM_INVALID, "参数AccountId无效"));
            }
            if (dbsaccount.GetCorporationInfo(model.Request.CorporationId, ValidityState.Enabled) == null)
            {
                return(model.Fail(ErrorCode.PARAM_INVALID, "参数CorporationId无效"));
            }
            var carDetail = new CarsDetails(model.Request.CarDrive, model.Request.CarEnergy, model.Request.CarGearbox, model.Request.CarSeat,
                                            model.Request.CarEmissionStandard, model.Request.Appearance, model.Request.Interior, model.Request.CarConfig, model.Request.CarLicenseTime, model.Request.CarAge,
                                            model.Request.Mileage, model.Request.Emission, model.Request.Images);
            var retDetail = new DBaCar().AddCarDetail(carDetail);

            if (retDetail == 0)
            {
                return(model.Fail(ErrorCode.DB_SAVE_FAILED, "添加失败"));
            }
            var carConcise = new CarsConcise(model.Request.AccountId, carDetail.Id, model.Request.CorporationId, model.Request.Name, model.Request.BrandId, model.Request.SeriesId, model.Request.GuidePrice,
                                             model.Request.SellingPrice, model.Request.BasePrice, ValidityState.Enabled, (carDetail.Images == null)?"":carDetail.Images[0], CarSell.Sale, model.Request.CarActivity);
            var retConcise = new DBaCar().AddCarConcise(carConcise);

            if (retConcise == 0)
            {
                return(model.Fail(ErrorCode.DB_SAVE_FAILED, "添加失败"));
            }
            var ret = new ResCarConciseInfo(carConcise, carDetail.CarLicenseTime, carDetail.Mileage);

            return(model.Ok(ret));
        }
Exemple #2
0
        public IWsModel <ReqAddAccount, ResAccount> AddAccount([FromBody] WsModel <ReqAddAccount, ResAccount> model)
        {
            if (model == null)
            {
                return(new WsModel <ReqAddAccount, ResAccount>().Fail(ErrorCode.PARAM_NULL, "参数为空"));
            }
            if (model.Request == null)
            {
                return(model.Fail(ErrorCode.PARAM_NULL, "参数为空"));
            }
            if (!model.Request.Valid4AddAccount())
            {
                return(model.Fail(ErrorCode.PARAM_NULL, "参数为空"));
            }
            var dbs = new DbsAccount();

            if (dbs.GetAccount(model.Request.OpenId) != null)
            {
                return(model.Fail(ErrorCode.DB_EXISTED, "数据已存在"));
            }
            //验证公司是否存在
            if (dbs.GetCorporationInfo(model.Request.Corporation, ValidityState.Enabled) == null)
            {
                return(model.Fail(ErrorCode.DB_NOTEXISTED, "公司不存在"));
            }
            var account = new Account(model.Request.Wechat, model.Request.WechatName, model.Request.OpenId, model.Request.Corporation, model.Request.Sex, model.Request.Email, model.Request.Phone, model.Request.Name, ValidityState.Disabled, Identity.Staff, model.Request.Logo, DateTime.Now);
            var result  = new DbaAccount().AddAccount(account);

            if (result == 0)
            {
                return(model.Fail(ErrorCode.DB_SAVE_FAILED, "添加失败"));
            }
            var ret = new ResAccount(account);

            return(model.Ok(ret));
        }