public CustomJsonResult Add(string operater, string merchId, RopPrdSubjectAdd rop) { var result = new CustomJsonResult(); using (TransactionScope ts = new TransactionScope()) { var isExists = CurrentDb.PrdSubject.Where(m => m.Name == rop.Name).FirstOrDefault(); if (isExists != null) { return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "该名称已经存在")); } var pPrdSubject = CurrentDb.PrdSubject.Where(m => m.Id == rop.PId).FirstOrDefault(); if (pPrdSubject == null) { return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "找不到上级节点")); } var prdSubject = new PrdSubject(); prdSubject.Id = GuidUtil.New(); prdSubject.PId = rop.PId; prdSubject.Name = rop.Name; prdSubject.DispalyImgUrls = rop.DispalyImgUrls.ToJsonString(); prdSubject.MainImgUrl = ImgSet.GetMain(prdSubject.DispalyImgUrls); prdSubject.MerchId = merchId; prdSubject.Description = rop.Description; prdSubject.Depth = pPrdSubject.Depth + 1; prdSubject.CreateTime = DateTime.Now; prdSubject.Creator = operater; CurrentDb.PrdSubject.Add(prdSubject); CurrentDb.SaveChanges(); ts.Complete(); result = new CustomJsonResult(ResultType.Success, ResultCode.Success, "保存成功"); } return(result); }
public CustomJsonResult Add(string operater, RopMerchMasterAdd rop) { var result = new CustomJsonResult(); if (string.IsNullOrEmpty(rop.UserName)) { return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "用户名不能为空")); } if (string.IsNullOrEmpty(rop.Password)) { return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "密码不能为空")); } var isExistUserName = CurrentDb.SysUser.Where(m => m.UserName == rop.UserName).FirstOrDefault(); if (isExistUserName != null) { return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, string.Format("该用户名({0})已被使用", rop.UserName))); } using (TransactionScope ts = new TransactionScope()) { string merchId = GuidUtil.New(); var user = new SysMerchUser(); user.Id = GuidUtil.New(); user.MerchId = merchId; user.PId = GuidUtil.Empty(); user.UserName = rop.UserName; user.FullName = rop.FullName; user.PasswordHash = PassWordHelper.HashPassword(rop.Password); user.Email = rop.Email; user.PhoneNumber = rop.PhoneNumber; user.BelongSite = Enumeration.BelongSite.Merch; user.IsDelete = false; user.IsDisable = false; user.IsMaster = true; user.Creator = operater; user.CreateTime = DateTime.Now; user.RegisterTime = DateTime.Now; user.SecurityStamp = Guid.NewGuid().ToString().Replace("-", ""); CurrentDb.SysMerchUser.Add(user); var merch = new LocalS.Entity.Merch(); merch.Id = merchId; merch.MerchUserId = user.Id; merch.Name = rop.FullName; merch.CreateTime = DateTime.Now; merch.Creator = operater; CurrentDb.Merch.Add(merch); var sysRole = CurrentDb.SysRole.Where(m => m.BelongSite == Enumeration.BelongSite.Merch && m.IsSuper == true).FirstOrDefault(); if (sysRole == null) { return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "未配置系统管理角色")); } CurrentDb.SysUserRole.Add(new SysUserRole { Id = GuidUtil.New(), RoleId = sysRole.Id, UserId = user.Id, Creator = operater, CreateTime = DateTime.Now }); var sysOrg = new SysOrg(); sysOrg.Id = GuidUtil.New(); sysOrg.Name = "根组织"; sysOrg.PId = GuidUtil.Empty(); sysOrg.BelongSite = Enumeration.BelongSite.Merch; sysOrg.ReferenceId = merch.Id; sysOrg.IsDelete = false; sysOrg.Priority = 0; sysOrg.Depth = 0; sysOrg.CreateTime = DateTime.Now; sysOrg.Creator = operater; CurrentDb.SysOrg.Add(sysOrg); var sysUserOrg = new SysUserOrg(); sysUserOrg.Id = GuidUtil.New(); sysUserOrg.OrgId = sysOrg.Id; sysUserOrg.UserId = user.Id; sysUserOrg.CreateTime = DateTime.Now; sysUserOrg.Creator = operater; CurrentDb.SysUserOrg.Add(sysUserOrg); var prdKind = new PrdKind(); prdKind.Id = GuidUtil.New(); prdKind.MerchId = merchId; prdKind.Name = "我的品类"; prdKind.PId = GuidUtil.Empty(); prdKind.Depth = 0; prdKind.Priority = 0; prdKind.IsDelete = false; prdKind.CreateTime = DateTime.Now; prdKind.Creator = operater; CurrentDb.PrdKind.Add(prdKind); var prdSubject = new PrdSubject(); prdSubject.Id = GuidUtil.New(); prdSubject.PId = GuidUtil.Empty(); prdSubject.MerchId = merchId; prdSubject.Name = "我的栏目"; prdSubject.Priority = 0; prdSubject.IsDelete = false; prdSubject.CreateTime = DateTime.Now; prdSubject.Creator = operater; CurrentDb.PrdSubject.Add(prdSubject); CurrentDb.SaveChanges(); ts.Complete(); result = new CustomJsonResult(ResultType.Success, ResultCode.Success, "保存成功"); } return(result); }