/// <summary> /// 保存广告 /// </summary> /// <param name="dbModel"></param> /// <returns></returns> public bool SaveAdertising(Bas_Advertising dbModel) { bool result = false; if (dbModel.Bad_EndTime == DateTime.MinValue) { dbModel.Bad_EndTime = DateTimeExtensions.DefaultDateTime; } if (dbModel.Bad_CreateTime == DateTime.MinValue) { dbModel.Bad_CreateTime = DateTime.Now; } using (TransactionScope scope = new TransactionScope()) { try { if (dbModel.Bad_Id > 0) { var oldDbModel = GetAdvertisingById(dbModel.Bad_Id); var needCreate = NeedCreatNew(dbModel, oldDbModel); if (needCreate) { dbModel.Bad_Id = 0; dbModel.Bad_CreateTime = DateTime.Now; oldDbModel.Bad_EndTime = DateTime.Now; oldDbModel.Bad_Status = (int)StatusEnum.无效; var updateOld = AdvertisingRepository.Update(oldDbModel); var insertNew = AdvertisingRepository.Insert(dbModel); result = updateOld && insertNew > 0; } else { result = AdvertisingRepository.Update(dbModel); } } else { var updateOld = AdvertisingRepository.UpdateStatusByBabPosId(dbModel.Bad_PosId, (int)StatusEnum.效, (int)StatusEnum.无效, DateTime.Now); var insertNew = AdvertisingRepository.Insert(dbModel); result = insertNew > 0; } if (result) { scope.Complete(); } else { RollbackTran(); } } catch (Exception ex) { RollbackTran(); throw ex; } } return(result); }
public ActionResult SaveAdertising(AdvertingInputModel model) { var bll = new AdvertisingBll(); Bas_Advertising dbModel = null; if (model.Bad_Id > 0) { dbModel = bll.GetAdvertisingById(model.Bad_Id); var modelByPos = bll.GetAdvertisingByPosId(model.Bad_PosId); if (dbModel == null || modelByPos == null || modelByPos.Bad_Id != dbModel.Bad_Id) { throw new AbhsException(ErrorCodeEnum.ParameterInvalid, AbhsErrorMsg.ConstParameterInvalid); } } //dbModel = model.ToAdvertisingDbModel(); //dbModel.Bad_Creator = CurrentUserID; dbModel = model.ConvertTo <Bas_Advertising>(dbModel); bool success = bll.SaveAdertising(dbModel); var msg = success ? "保存成功" : "保存失败"; return(Json(new JsonSimpleResponse() { State = success, ErrorMsg = msg })); }
public ActionResult Edit(int badPosId, int badId) { AdvertingInputModel viewModel; Bas_Advertising dbModel = null; if (badId > 0) { dbModel = new AdvertisingBll().GetAdvertisingById(badId); } if (dbModel == null) { viewModel = new AdvertingInputModel(badPosId); viewModel.Bad_Url = ""; } else { viewModel = new AdvertingInputModel(dbModel); } var bapModel = new AdvertisingBll().GetAdvertisingPosById(badPosId); if (bapModel != null) { viewModel.Bap_Code = bapModel.Bap_Code; } return(View(viewModel)); }
public AdvertingInputModel(Bas_Advertising dbModel) { if (dbModel != null) { this.Bad_Id = dbModel.Bad_Id; this.Bad_ImageUrl = dbModel.Bad_ImageUrl; this.Bad_PosId = dbModel.Bad_PosId; this.Bad_ReferId = dbModel.Bad_ReferId; this.Bad_Status = dbModel.Bad_Status; this.Bad_Url = dbModel.Bad_Url; } }
public Bas_Advertising ToAdvertisingDbModel() { Bas_Advertising dbModel = new Bas_Advertising(); dbModel.Bad_Id = this.Bad_Id; dbModel.Bad_ImageUrl = this.Bad_ImageUrl; dbModel.Bad_PosId = this.Bad_PosId; dbModel.Bad_ReferId = this.Bad_ReferId; dbModel.Bad_Status = this.Bad_Status; dbModel.Bad_Url = string.IsNullOrEmpty(this.Bad_Url) ? "" : this.Bad_Url; return(dbModel); }
/// <summary> /// 判断是否需要新增 /// </summary> /// <param name="newModel"></param> /// <param name="oldModel"></param> /// <returns></returns> private bool NeedCreatNew(Bas_Advertising newModel, Bas_Advertising oldModel) { return(newModel.Bad_ReferId != oldModel.Bad_ReferId || newModel.Bad_Url != oldModel.Bad_Url); }