/// <summary> /// 添加 /// </summary> /// <param name="model"></param> /// <returns></returns> public async Task <ApiResult <string> > Add(SysMenuParam model) { var result = new ApiResult <string>(); try { model.Id = Unique.Id(); var menuModel = model.MapTo <SysMenuParam, SysMenu>(m => m.Id); if (model.Parent.Any()) { menuModel.ParentId = model.Parent[model.Parent.Count - 1]; menuModel.ParentGroupId = string.Join(",", model.Parent.ToArray()) + "," + menuModel.Id; //查询,上级的层级 var paramModel = await _thisRepository.GetModelAsync(m => m.Id == menuModel.ParentId); if (paramModel != null && !string.IsNullOrEmpty(paramModel.Id)) { menuModel.Layer = paramModel.Layer + 1; } } menuModel.CreateUser = "******"; await _thisRepository.AddAsync(menuModel); } catch (Exception ex) { result.StatusCode = (int)HttpStatusCode.InternalServerError; result.Message = ex.Message; } return(result); }
/// <summary> /// 添加 /// </summary> /// <param name="model"></param> /// <returns></returns> public async Task <ApiResult <string> > Add(SysOrganizeParam model) { var result = new ApiResult <string>(); try { var organizeModel = model.MapTo <SysOrganizeParam, SysOrganize>(m => m.Id); organizeModel.Id = Unique.Id(); organizeModel.ParentId = model.Parent[model.Parent.Count - 1]; organizeModel.ParentIdList = string.Join(",", model.Parent.ToArray()) + "," + organizeModel.Id; organizeModel.CreateUser = "******"; //根据父级查询等级 var parentModel = await _thisRepository.GetModelAsync(m => m.Id == organizeModel.ParentId); if (parentModel != null) { organizeModel.Layer = parentModel.Layer + 1; } await _thisRepository.AddAsync(organizeModel); } catch (Exception ex) { result.StatusCode = (int)HttpStatusCode.InternalServerError; result.Message = ex.Message; } return(result); }
/// <summary> /// 添加 /// </summary> /// <param name="model"></param> /// <returns></returns> public async Task <ApiResult <string> > Add(SysPost model) { var result = new ApiResult <string>(); try { model.Id = Unique.Id(); model.CreateUser = "******"; await _thisRepository.AddAsync(model); } catch (Exception ex) { result.StatusCode = (int)HttpStatusCode.InternalServerError; result.Message = ex.Message; } return(result); }
private static void GetID() { for (var i = 0; i < N; i++) { var id = Unique.Id(); lock (o) { if (set.Contains(id)) { Console.WriteLine("发现重复项 : {0}", id); } else { set.Add(id); } } } Console.WriteLine($"任务{++taskCount}完成"); }