/// <summary> /// 修改计费模板 /// </summary> /// <returns></returns> public bool ModifyBillingTemplate(BillingTemplateModel model) { //当前车类是否存在 CarTypeModel carTypeModel = _iCarTypeContext.GetCarType(model.CarTypeGuid); if (carTypeModel == null || (carTypeModel.CarType != CarTypeEnum.TempCar && carTypeModel.CarType != CarTypeEnum.ValueCar)) { LastErrorDescribe = BussinessErrorCodeEnum.BUSINESS_NOTEXISTS_CARTYPE.GetDesc(); return(false); } bool flag = _iBillingTemplateContext.ModifyBillingTemplate(model); if (!flag) { LastErrorDescribe = BussinessErrorCodeEnum.BUSINESS_SAVE_BILLING.GetDesc(); return(false); } //下发缴费模板给相机(车类对应缴费模板) SendTempCarTypeOfPlateColor(model.ProjectGuid, model.ParkCode); //将数据进行格式化,再同步到主平台 bool toFujicaResult = EditTemplateDataToFujica(model, carTypeModel.CarType); if (!toFujicaResult) { LastErrorDescribe = BussinessErrorCodeEnum.BUSINESS_SAVE_BILLING_TOFUJICA.GetDesc(); } return(toFujicaResult); }
/// <summary> /// 添加计费模板 /// </summary> /// <returns></returns> public bool AddNewBillingTemplate(BillingTemplateModel model) { //当前车类是否存在 CarTypeModel carTypeModel = _iCarTypeContext.GetCarType(model.CarTypeGuid); if (carTypeModel == null || (carTypeModel.CarType != CarTypeEnum.TempCar && carTypeModel.CarType != CarTypeEnum.ValueCar)) { LastErrorDescribe = BussinessErrorCodeEnum.BUSINESS_NOTEXISTS_CARTYPE.GetDesc(); return(false); } bool flag = _iBillingTemplateContext.AddBillingTemplate(model); if (!flag) { LastErrorDescribe = BussinessErrorCodeEnum.BUSINESS_SAVE_BILLING.GetDesc(); return(false); } //将数据进行格式化,再同步到主平台 bool toFujicaResult = AddTemplateDataToFujica(model, carTypeModel.CarType); if (!toFujicaResult) { LastErrorDescribe = BussinessErrorCodeEnum.BUSINESS_SAVE_BILLING_TOFUJICA.GetDesc(); } return(toFujicaResult); }
/// <summary> /// 设置默认车类(临时车用) /// </summary> /// <param name="guid">车类guid</param> /// <returns></returns> public bool SetDefaultCarType(string guid) { CarTypeModel model = GetCarType(guid); //设置默认值 bool flag = extendatabaseoperate.ToggleValue(model); if (!flag) { return(false); } //更新当前车场redis中所有的车类数据 List <CarTypeModel> allmodel = AllCarType(model.ParkCode, model.ProjectGuid); foreach (var item in allmodel) { if (item.Guid == guid) { item.DefaultType = true; } else { item.DefaultType = false; } //批量保存到redis redisoperate.model = item; redisoperate.SaveToRedis(); //此时不需要判断redis是否成功,因为修改时redis一定会返回false //if (!flag) //{ // break; //} } return(flag); }
public bool deleteCarType(CarTypeModel carTypeToDelete)//todo: add field isactive and instead of delete, set to inactive. change the select all to ignore inactive { try { using (CarRentalEntities carEntities = new CarRentalEntities()) { CarType carTypeToDel = null; foreach (var singleCarType in carEntities.CarTypes) { if (singleCarType.Manufacturer == carTypeToDelete.Producer && singleCarType.Model == carTypeToDelete.Model && singleCarType.ProductionYear == carTypeToDelete.ManufacturingYear && (singleCarType.AutomaticGear && carTypeToDelete.Gear == CarTypeModel.AUTOMATIC || !singleCarType.AutomaticGear && carTypeToDelete.Gear == CarTypeModel.MANUAL)) { //found!! carTypeToDel = singleCarType; break; } } if (carTypeToDel != null) { carEntities.CarTypes.Remove(carTypeToDel); carEntities.SaveChanges(); return(true); } } return(false); } catch (Exception e) { return(false); } }
public HttpResponseMessage AddCarType([FromBody] CarTypeModel carTypeModel) { using (logic = new CarTypeManager()) { try { //בדיקה האם הפרמטר שעבר לפונקציה בתור מודל עומד בדרישות הואלידציה //BOהגדרות הואלידציה מוגדרות בתוך ה //Data annotation בתור if (!ModelState.IsValid) { string error = ModelState.Where(ms => ms.Value.Errors.Any()).Select(ms => ms.Value.Errors[0].ErrorMessage).FirstOrDefault(); return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, error)); } // הולידציה עברה בהצלחה carTypeModel = logic.AddCarType(carTypeModel); return(Request.CreateResponse(HttpStatusCode.Created, carTypeModel)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ExceptionHelper.GetInnerMessage(ex))); } } }
/// <summary> /// UpdateAuthorByName updates a specific Author from the DB by the EF ref /// by the `authorName` parameter /// and returns bool value - if the action was success /// </summary> static public bool UpdateCarTypeByModel(string carModel, CarTypeModel newCarType) { try { using (CarsRentalEntities ef = new CarsRentalEntities()) { CarType selectedCarType = ef.CarTypes.FirstOrDefault(dbCarType => dbCarType.model == carModel); if (selectedCarType == null) { return(false); } // selectedCarType.carTypeId = newCarType.CarTypeId; selectedCarType.manufacturer = newCarType.Manufacturer; selectedCarType.model = newCarType.Model; selectedCarType.dailyCost = newCarType.DailyCost; selectedCarType.dayDelayCost = newCarType.DayDelayCost; selectedCarType.manufactureYear = newCarType.ManufactureYear; selectedCarType.gear = newCarType.Gear; ef.SaveChanges(); return(true); } } catch (Exception) { return(false); } }
/// <summary> /// InsertAuthor inserts a new Author to the DB by the EF ref /// maps the `newAuthor` parameter (BOL object) to a `Author` (DAL object) /// and returns bool value - if the action was success /// </summary> static public bool InsertCarType(CarTypeModel newCarType) { try { using (CarsRentalEntities ef = new CarsRentalEntities()) { CarType newDbCarType = new CarType { manufacturer = newCarType.Manufacturer, model = newCarType.Model, dailyCost = newCarType.DailyCost, dayDelayCost = newCarType.DayDelayCost, manufactureYear = newCarType.ManufactureYear, gear = newCarType.Gear, }; ef.CarTypes.Add(newDbCarType); ef.SaveChanges(); return(true); } } catch (Exception) { return(false); } }
/// <summary> /// edit a car type info /// </summary> /// <param name="cartypeModle">the car type model from the user--string</param> /// <param name="cartypeparam">an car type object contain all of the car type info</param> /// <returns>true if the actions secseed false if it didnt</returns> public static bool EditCarType(string cartypeModle, CarTypeModel cartypeparam) { try { using (CarRentalDbV2Entities db = new CarRentalDbV2Entities()) { CarsTypesTable dbcartype = db.CarsTypesTables.SingleOrDefault(a => a.Model == cartypeModle); if (dbcartype == null) { return(false); } dbcartype.Model = cartypeparam.Model; dbcartype.Year = cartypeparam.Year; dbcartype.CostPerDay = cartypeparam.CostPerDay; dbcartype.FinePrice = cartypeparam.FinePrice; dbcartype.Manufacturer = cartypeparam.Manufacturer; dbcartype.IsAutomatic = cartypeparam.IsAutomatic; db.SaveChanges(); return(true); } } catch { return(false); } }
//add car type public bool AddCarType(CarTypeModel cars) { try { CarType ct = db.CarTypes.Where(a => cars.CarTypeID == a.CarTypeID).FirstOrDefault(); if (ct != null) { return(false); } db.CarTypes.Add(new CarType { CarTypeID = cars.CarTypeID, Brand = cars.Brand, Model = cars.Model, PricePerDay = cars.PricePerDay, PriceExtraPerDay = cars.PriceExtraPerDay, Year = cars.Year, IsManual = cars.IsManual, }); db.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public HttpResponseMessage Post([FromBody] CarTypeModel newCarType) { try { if (ModelState.IsValid) { CarTypeModel addedCarType = carTypesManager.AddCarType(newCarType); if (addedCarType != null) { return(Request.CreateResponse(HttpStatusCode.OK, true)); } } else { var errorMessage = ModelState.Values.SelectMany(v => v.Errors).ToList().Select(e => e.ErrorMessage).Where(e => e != "").FirstOrDefault(); if (errorMessage == null) { errorMessage = ModelState.Values.SelectMany(v => v.Errors).ToList().Select(e => e.Exception).Where(e => e.Message != "").Select(e => e.Message).FirstOrDefault(); } if (errorMessage != null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, errorMessage)); } } return(Request.CreateErrorResponse(HttpStatusCode.NotFound, new HttpError("Problem in car type data"))); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex)); } }
/// <summary> /// Add a new car type to the DB /// </summary> /// <param name="NewCartype">an car type object conatains all the car type data</param> /// <returns>true if the actions secseed false if it didnt</returns> public static bool AddNewCartype(CarTypeModel NewCartype) { try { using (CarRentalDbV2Entities db = new CarRentalDbV2Entities()) { CarsTypesTable dbCarType = new CarsTypesTable { Model = NewCartype.Model, IsAutomatic = NewCartype.IsAutomatic, CostPerDay = NewCartype.CostPerDay, Year = NewCartype.Year, Manufacturer = NewCartype.Manufacturer, FinePrice = NewCartype.FinePrice, }; db.CarsTypesTables.Add(dbCarType); db.SaveChanges(); return(true); } } catch { return(false); } }
/// <summary> /// 保存储值卡数据到redis /// </summary> /// <param name="model"></param> /// <param name="m_ilogger"></param> /// <param name="m_serializer"></param> /// <returns></returns> public static bool SaveValueCarToRedis(CardServiceModel model, ILogger m_ilogger, ISerializer m_serializer) { try { IDatabase db = RedisHelper.GetDatabase(0); CarTypeModel cartype = m_serializer.Deserialize <CarTypeModel>(db.HashGet("CarTypeList", model.CarTypeGuid)); if (cartype.CarType == CarTypeEnum.ValueCar) { //储值车 string hashkey = model.ParkCode + Convert.ToBase64String(Encoding.UTF8.GetBytes(model.CarNo)); ValueCarModel monthcarmodel = new ValueCarModel() { ProjectGuid = model.ProjectGuid, ParkCode = model.ParkCode, CarOwnerName = model.CarOwnerName, Mobile = model.Mobile, CarNo = model.CarNo, CarTypeGuid = model.CarTypeGuid, Enable = model.Enable, StartDate = model.StartDate, Locked = model.Locked, Balance = model.Balance, DrivewayGuidList = model.DrivewayGuidList }; return(db.HashSet("PermanentCarList", hashkey, m_serializer.Serialize(monthcarmodel))); } return(false); } catch (Exception ex) { m_ilogger.LogFatal(LoggerLogicEnum.Tools, "", model.ParkCode, model.CarNo, "Fujica.com.cn.MonitorServiceClient.PayDataManager.SaveValueCarToRedis", "保存储值车数据异常", ex.ToString()); return(false); } }
public bool SaveToRedis() { try { IDatabase db = RedisHelper.GetDatabase(0); CarTypeModel cartype = m_serializer.Deserialize <CarTypeModel>(db.HashGet("CarTypeList", model.CarTypeGuid)); //暂不做固定车延期模板的验证(规则的匹配) //PermanentTemplateModel template= m_serializer.Deserialize<PermanentTemplateModel>(db.HashGet("PermanentTemplateList", model.CarTypeGuid)); if (cartype.CarType == CarTypeEnum.MonthCar || cartype.CarType == CarTypeEnum.VIPCar) { //月卡车 string hashkey = model.ParkCode + Convert.ToBase64String(Encoding.UTF8.GetBytes(model.CarNo)); MonthCarModel monthcarmodel = new MonthCarModel() { ProjectGuid = model.ProjectGuid, ParkCode = model.ParkCode, CarOwnerName = model.CarOwnerName, Mobile = model.Mobile, CarNo = model.CarNo, CarTypeGuid = model.CarTypeGuid, //Cost= template.Amount, //Units= template.Months, Enable = model.Enable, Locked = model.Locked, StartDate = model.StartDate, EndDate = model.EndDate, DrivewayGuidList = model.DrivewayGuidList }; return(db.HashSet("PermanentCarList", hashkey, m_serializer.Serialize(monthcarmodel))); } else if (cartype.CarType == CarTypeEnum.ValueCar) { //储值车 string hashkey = model.ParkCode + Convert.ToBase64String(Encoding.UTF8.GetBytes(model.CarNo)); ValueCarModel monthcarmodel = new ValueCarModel() { ProjectGuid = model.ProjectGuid, ParkCode = model.ParkCode, CarOwnerName = model.CarOwnerName, Mobile = model.Mobile, CarNo = model.CarNo, CarTypeGuid = model.CarTypeGuid, Enable = model.Enable, StartDate = model.StartDate, Locked = model.Locked, Balance = model.Balance, DrivewayGuidList = model.DrivewayGuidList }; return(db.HashSet("PermanentCarList", hashkey, m_serializer.Serialize(monthcarmodel))); } return(false); } catch (Exception ex) { m_logger.LogFatal(LoggerLogicEnum.DataService, "", "", "", "Fujica.com.cn.DataService.RedisCache.CardServiceRedisCache.SaveToRedis", "保存固定车数据异常", ex.ToString()); return(false); } }
/// <summary> /// 添加车类 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool AddCarType(CarTypeModel model) { redisoperate.model = model; bool flag = databaseoperate.SaveToDataBase(model); if (!flag) { return(false); //数据库不成功就不要往下执行了 } return(redisoperate.SaveToRedis()); }
public IActionResult UpdateCarType(int id, [FromForm] CarTypeModel carTypeModel) { try { return(Ok(carTypesLogic.UpdateCarType(carTypeModel))); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }
/// <summary> /// 删除车类 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool DeleteCarType(CarTypeModel model) { redisoperate.model = model; bool flag = databaseoperate.DeleteInDataBase(model); if (!flag) { return(false); //数据库不成功就不要往下执行了 } return(redisoperate.DeleteInRedis()); }
public IHttpActionResult GetCarTypes() { var carTypes = new List <CarTypeModel>(); foreach (var ct in db.CarTypes.ToList()) { var cartype = new CarTypeModel(ct.index, ct.Manufacturer, ct.Model, ct.Model_Year, ct.Daily_Cost, ct.Daily_Late_Cost, ct.Transmission); carTypes.Add(cartype); } return(Ok(carTypes)); }
/// <summary> /// 修改车类 /// </summary> /// <returns></returns> public bool ModifyCarType(CarTypeModel model) { bool flag = _iCarTypeContext.ModifyCarType(model); if (!flag) { LastErrorDescribe = BussinessErrorCodeEnum.BUSINESS_SAVE_CARTYPE.GetDesc(); return(false); } return(flag); }
public HttpResponseMessage Delete(CarTypeModel deleteCarType) { bool deleteResult = CarTypesManager.InsertUpdateDeleteCarType(deleteCarType); HttpStatusCode responseCode = deleteResult ? HttpStatusCode.OK : HttpStatusCode.BadRequest; return(new HttpResponseMessage(responseCode) { Content = new ObjectContent <bool>(deleteResult, new JsonMediaTypeFormatter()) }); }
public IActionResult AddCarType([FromForm] CarTypeModel carTypeModel) { try { CarTypeModel addedCarType = carTypesLogic.AddNewCarType(carTypeModel); return(Created("api/cartypes/" + addedCarType.CarTypeId, addedCarType)); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }
public HttpResponseMessage GetACartype([FromUri] int id) { try { CarTypeModel car = carTypeManager.GetACar(id); return(Request.CreateResponse(HttpStatusCode.OK, car)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex)); } }
/// <summary> /// 修改车类 /// </summary> /// <returns></returns> public bool ModifyCarType(CarTypeModel model) { redisoperate.model = model; bool flag = databaseoperate.SaveToDataBase(model); if (!flag) { return(false); //数据库不成功就不要往下执行了 } //此时不需要判断redis是否成功,因为修改时redis一定会返回false redisoperate.SaveToRedis(); return(true); }
// GET: api/CarTypes/5 public HttpResponseMessage Get(string cartypemodel) { CarTypeModel Singletype = CarTypeManager.GetSpesificCartype(cartypemodel); if (Singletype == null) { return(new HttpResponseMessage(HttpStatusCode.BadRequest)); } return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new ObjectContent <CarTypeModel>(Singletype, new JsonMediaTypeFormatter()) }); }
public static bool InsertUpdateDeleteCarType(CarTypeModel editCarType) { try { using (CarRentEntitiesModel db = new CarRentEntitiesModel()) { CarType selectedCarType = null; if (editCarType.CarTypeID > 0) { selectedCarType = db.CarTypes.FirstOrDefault(x => x.CarTypeID == editCarType.CarTypeID && !x.IsDeleted); if (selectedCarType == null) { return(false); } } else { selectedCarType = new CarType(); } selectedCarType.Manufacturer = editCarType.Manufacturer; selectedCarType.Model = editCarType.Model; selectedCarType.CarYear = editCarType.CarYear; selectedCarType.DailyRate = editCarType.DailyRate; selectedCarType.LateDailyRate = editCarType.LateDailyRate; selectedCarType.IsAutomatic = editCarType.IsAutomatic; if (editCarType.IsDeleted) { selectedCarType.IsDeleted = true; } if (editCarType.CarTypeID == 0) { db.CarTypes.Add(selectedCarType); } db.SaveChanges(); return(true); } } catch (Exception) { return(false); } }
public HttpResponseMessage DeleteCarType([FromUri] CarTypeModel carType) { try { if (carTypesManager.deleteCarType(carType)) { return(Request.CreateResponse(HttpStatusCode.OK, true)); } return(Request.CreateErrorResponse(HttpStatusCode.NotFound, new HttpError())); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex)); } }
public HttpResponseMessage GetOneCarType([FromUri] int CarTypeID) { using (logic = new CarTypeManager()) { try { CarTypeModel CarType = logic.GetOneCarType(CarTypeID); return(Request.CreateResponse(HttpStatusCode.OK, CarType)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ExceptionHelper.GetInnerMessage(ex))); } } }
// GET: api/Author/5 public HttpResponseMessage Get(string carModel) { CarTypeModel carType = CarTypeManager.SelectCarTypeByModel(carModel); if (carType != null) { return new HttpResponseMessage(HttpStatusCode.OK) { Content = new ObjectContent <CarTypeModel>(carType, new JsonMediaTypeFormatter()) } } ; return(new HttpResponseMessage(HttpStatusCode.BadRequest)); }
public IHttpActionResult GetCarType(int id) { CarType carType = db.CarTypes.Find(id); if (carType == null) { return(NotFound()); } var cartypeToReturn = new CarTypeModel( carType.index, carType.Manufacturer, carType.Model, carType.Model_Year, carType.Daily_Cost, carType.Daily_Late_Cost, carType.Transmission); return(Ok(cartypeToReturn)); }
// PUT: api/CarTypes/5 public HttpResponseMessage Put(string cartypemodel, [FromBody] CarTypeModel value) { bool updateResult = false; if (ModelState.IsValid) { updateResult = CarTypeManager.EditCarType(cartypemodel, value); } HttpStatusCode rsponseCode = (updateResult) ? HttpStatusCode.OK : HttpStatusCode.BadRequest; return(new HttpResponseMessage(rsponseCode) { Content = new ObjectContent <bool>(updateResult, new JsonMediaTypeFormatter()) }); }
// POST: api/CarTypes public HttpResponseMessage Post([FromBody] CarTypeModel value) { bool InsertResult = false; if (ModelState.IsValid) { InsertResult = CarTypeManager.AddNewCartype(value); } HttpStatusCode ResponsCode = InsertResult ? HttpStatusCode.Created : HttpStatusCode.BadRequest; return(new HttpResponseMessage(ResponsCode) { Content = new ObjectContent <bool>(InsertResult, new JsonMediaTypeFormatter()) }); }