public bool Delete(CategoriesEntity categoriesEntity) { db.CategoriesEntities.Remove(categoriesEntity); if (Convert.ToBoolean(db.SaveChanges())) { return(true); } return(false); }
public bool update(CategoriesEntity categoriesEntity) { db.CategoriesEntities.Attach(categoriesEntity); db.Entry(categoriesEntity).State = EntityState.Modified; if (Convert.ToBoolean(db.SaveChanges())) { return(true); } return(false); }
/// <summary> /// 新建分类 /// </summary> /// <param name="entity"></param> /// <returns></returns> public bool Insert(CategoriesEntity entity) { bool isSuccess = categories.Insert(entity); if (isSuccess) { ClearCacheOrSession.ClearFunctionsCacheByCRUD(); } return(isSuccess); }
/// <summary> /// 新增分类 /// </summary> /// <param name="entity"></param> /// <returns></returns> public bool Insert(CategoriesEntity entity) { bool isSuccess = false; SqlTransaction trans = null; StringBuilder sbSql = new StringBuilder(); sbSql.Append(" INSERT INTO M_CalendarType(ParentCalendarTypeID,CalendarTypeName,CalendarTypeKind,Descripition,Dismiss,PictureID) values(@ParentCalendarTypeID,@CalendarTypeName,@CalendarTypeKind,@Descripition,@Dismiss,@PictureID)"); SqlParameter[] prms = { new SqlParameter("@ParentCalendarTypeID", SqlDbType.Int), new SqlParameter("@CalendarTypeName", SqlDbType.NVarChar, 100), new SqlParameter("@CalendarTypeKind", SqlDbType.SmallInt), new SqlParameter("@Descripition", SqlDbType.NVarChar, 200), new SqlParameter("@Dismiss", SqlDbType.Bit), new SqlParameter("@PictureID", SqlDbType.Int) }; prms[0].Value = entity.ParentCalendarTypeID; prms[1].Value = entity.CalendarTypeName; prms[2].Value = entity.CalendarTypeKind; prms[3].Value = entity.Descripition; prms[4].Value = entity.Dismiss; prms[5].Value = entity.PictureID; try { using (SqlConnection conn = new SqlConnection(SQlHelper.MyConnectStr)) { conn.Open(); trans = conn.BeginTransaction(); SQlHelper.ExecuteScalar(trans, CommandType.Text, sbSql.ToString(), prms); isSuccess = true; trans.Commit(); } } catch (Exception ex) { if (trans != null) { trans.Rollback(); } LogUtil.WriteLog(ex); return(false); } return(isSuccess); }
public IResult Save(CategoriesDto categoriesDto) { CategoriesEntity categories = new CategoriesEntity(categoriesDto.Name); if (_categoriesRepository.Get(categories) != null) { return(new ValidateResult(categories, false, "Categoria informada já existe")); } categories.Validate(); if (categories.Invalid) { return(new ValidateResult(categories.Notifications, false, "Problemas ao cadastrar a Categoria")); } _categoriesRepository.Add(categories); return(new ValidateResult(categories, true, "Categoria cadastrada com sucessso")); }
private void InitData() { this.hidPid.Value = CategoriesID.ToString(); List <CategoriesEntity> CategoriesList = catebll.CategoriesFirstLevel(); foreach (CategoriesEntity item in CategoriesList) { this.selCategoriesLevel.Items.Add(new ListItem(item.CalendarTypeName, item.CalendarTypeID.ToString())); } if (CategoriesID > 0) //修改 { CategoriesEntity CategoriesOne = catebll.QueryCategories(CategoriesID); if (int.Parse(CategoriesOne.ParentCalendarTypeID.ToString()) > 0) //二级分类 { this.selCategoriesLevel.Value = CategoriesOne.ParentCalendarTypeID.ToString(); } this.txtCategoriesName.Value = CategoriesOne.CalendarTypeName.ToString(); } }
/// <summary> /// 修改分类 /// </summary> /// <param name="Cateedit"></param> /// <returns></returns> public bool Categoriesedit(CategoriesEntity Cateedit) { bool flg = false; SqlTransaction trans = null; string sql = "update M_CalendarType set ParentCalendarTypeID=@ParentCalendarTypeID,CalendarTypeName=@CalendarTypeName,CalendarTypeKind=@CalendarTypeKind,Descripition=@Descripition,Dismiss=@Dismiss,PictureID=@PictureID WHERE CalendarTypeID=@CalendarTypeID"; SqlParameter[] prms = { new SqlParameter("@ParentCalendarTypeID", SqlDbType.Int), new SqlParameter("@CalendarTypeName", SqlDbType.NVarChar, 100), new SqlParameter("@CalendarTypeKind", SqlDbType.SmallInt), new SqlParameter("@Descripition", SqlDbType.NVarChar, 200), new SqlParameter("@Dismiss", SqlDbType.Bit), new SqlParameter("@PictureID", SqlDbType.Int), new SqlParameter("@CalendarTypeID", SqlDbType.Int) }; prms[0].Value = Cateedit.ParentCalendarTypeID; prms[1].Value = Cateedit.CalendarTypeName; prms[2].Value = Cateedit.CalendarTypeKind; prms[3].Value = Cateedit.Descripition; prms[4].Value = Cateedit.Dismiss; prms[5].Value = Cateedit.PictureID; prms[6].Value = Cateedit.CalendarTypeID; try { using (SqlConnection conn = new SqlConnection(SQlHelper.MyConnectStr)) { conn.Open(); trans = conn.BeginTransaction(); SQlHelper.ExecuteScalar(trans, CommandType.Text, sql.ToString(), prms); flg = true; trans.Commit(); } } catch (Exception ex) { LogUtil.WriteLog(ex); } return(flg); }
private void SaveCategoriesBySubmit() { CategoriesEntity catEntity = new CategoriesEntity(); catEntity.CalendarTypeName = this.txtCategoriesName.Value.Trim(); int selFunLevel = int.Parse(this.selCategoriesLevel.Value); bool isSuccess = false; if (CategoriesID > 0) { #region 修改 catEntity.CalendarTypeID = CategoriesID; catEntity.CalendarTypeKind = 2; if (selFunLevel == 0) { #region 修改一级分类 catEntity.ParentCalendarTypeID = -1; isSuccess = catebll.Categoriesedit(catEntity); if (isSuccess) { RetrunPageAlert(enumPageAlert.Success); } else { RetrunPageAlert(enumPageAlert.Fail); } #endregion } else //修改二级分类 { catEntity.ParentCalendarTypeID = selFunLevel; isSuccess = catebll.Categoriesedit(catEntity); if (isSuccess) { RetrunPageAlert(enumPageAlert.Success); } else { RetrunPageAlert(enumPageAlert.Fail); } } #endregion } else { #region 保存 if (selFunLevel == 0) { #region 新建一级分类 catEntity.ParentCalendarTypeID = -1; catEntity.CalendarTypeKind = 2; isSuccess = catebll.Insert(catEntity); if (isSuccess) { RetrunPageAlert(enumPageAlert.Success); } else { RetrunPageAlert(enumPageAlert.Fail); } #endregion } else { #region 新建二级分类 catEntity.CalendarTypeName = this.txtCategoriesName.Value.Trim(); catEntity.CalendarTypeKind = 2; catEntity.ParentCalendarTypeID = selFunLevel; isSuccess = catebll.Insert(catEntity); if (isSuccess) { RetrunPageAlert(enumPageAlert.Success); } else { RetrunPageAlert(enumPageAlert.Fail); } #endregion } #endregion } }
/// <summary> /// 修改分类信息 /// </summary> /// <param name="Cateedit"></param> /// <returns></returns> public bool Categoriesedit(CategoriesEntity Cateedit) { return((bool)categories.Categoriesedit(Cateedit)); }