public async Task <IHttpActionResult> AddPostion(PostionInDto postionInDto) { Position_User position_User = new Position_User { Id = IdentityManager.NewId(), PositionName = postionInDto.PositionName, PositionDes = postionInDto.PositionDes, Order = postionInDto.Order }; db.Position_Users.Add(position_User); if (await db.SaveChangesAsync() > 0) { return(Json(new { code = 200, msg = "添加成功" })); } return(Json(new { code = 200, msg = "添加失败" })); }
public async Task <IHttpActionResult> EditPostion(PostionInDto postionInDto) { Position_User type_res = new Position_User() { Id = postionInDto.Id }; type_res.PositionName = postionInDto.PositionName; type_res.PositionDes = postionInDto.PositionDes; type_res.Order = postionInDto.Order; db.Configuration.ValidateOnSaveEnabled = false; db.Entry(type_res).State = System.Data.Entity.EntityState.Unchanged; // Type type = typeof(Position_User); // Assembly assembly = Assembly.GetExecutingAssembly(); // object o = assembly.CreateInstance(type.FullName); // PropertyInfo[] propertyInfos = o.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public); //string str = string.Empty; // str += string.Format("类名称:{0}", type.Name); foreach (var item in type_res.GetType().GetProperties()) { string name = item.Name; object value = item.GetValue(type_res); if (item.GetValue(type_res) != null && value.ToString() != "" && item.Name != "Id") { Console.WriteLine(item.Name); db.Entry(type_res).Property(item.Name).IsModified = true; } else if (item.Name != "Id") { Console.WriteLine(item.Name); db.Entry(type_res).Property(item.Name).IsModified = false; } } if (await db.SaveChangesAsync() > 0) { db.Configuration.ValidateOnSaveEnabled = true; return(Json(new { code = 200, msg = "修改成功" })); } return(Json(new { code = 301, msg = "修改失败" })); }
public async Task <IHttpActionResult> RemovePostion(PostionInDto postionInDto) { foreach (var item in postionInDto.Del_Id) { var type_res = new Position_User() { Id = item }; db.Entry(type_res).State = System.Data.Entity.EntityState.Unchanged; type_res.del_Or = true; } if (await db.SaveChangesAsync() > 0) { return(Json(new { code = 200, msg = "修改成功" })); } return(Json(new { code = 301, msg = "修改失败" })); }