public async Task <Result <GroupDto> > Create(CreateGroupDto createGroupDto) { var owner = await Context.Users.FirstOrDefaultAsync(u => u.Id == createGroupDto.OwnerId); if (owner == null) { return(Result <GroupDto> .Failed(new NotFoundObjectResult( new ApiMessage { Message = ResponseMessage.UserNotFound }))); } var group = _mapper.Map <Group>(createGroupDto); group.User = owner; group.Members = 1; group.Id = Guid.NewGuid(); await AddAsync(group); await Context.SaveChangesAsync(); return(Result <GroupDto> .SuccessFull(_mapper.Map <GroupDto>(group))); }
/// <summary> /// 批量插入 /// </summary> /// <param name="inputDto"></param> /// <returns></returns> public async Task CreateAsync(CreateGroupDto inputDto) { bool exist = await _groupRepository.Select.AnyAsync(r => r.Name == inputDto.Name); if (exist) { throw new LinCmsException("分组已存在,不可创建同名分组", ErrorCode.RepeatField); } LinGroup linGroup = _mapper.Map <LinGroup>(inputDto); _freeSql.Transaction(() => { long groupId = _freeSql.Insert(linGroup).ExecuteIdentity(); List <LinPermission> allPermissions = _freeSql.Select <LinPermission>().ToList(); List <LinGroupPermission> linPermissions = new List <LinGroupPermission>(); inputDto.PermissionIds.ForEach(r => { LinPermission pdDto = allPermissions.FirstOrDefault(u => u.Id == r); if (pdDto == null) { throw new LinCmsException($"不存在此权限:{r}", ErrorCode.NotFound); } linPermissions.Add(new LinGroupPermission(groupId, pdDto.Id)); }); _freeSql.Insert <LinGroupPermission>().AppendData(linPermissions).ExecuteAffrows(); }); }
public IHttpActionResult CreateGroup([FromBody] CreateGroupDto groupModel) { if (groupModel == null || !ModelState.IsValid) { return(BadRequest(ModelState)); } var currentUser = this._userService.GetUserById(this._currentUserId); try { var group = new Group { Name = groupModel.Name, Creator = currentUser }; group.Members.Add(currentUser); this._groupService.CreateGroup(group); var model = new GroupDto(group.Name, group.Creator.DisplayName); return(Content(HttpStatusCode.Created, model)); } catch (Exception) { return(Content(HttpStatusCode.Conflict, "Groupname should be unique.")); } }
/// <summary> /// 批量插入 /// </summary> /// <param name="inputDto"></param> /// <returns></returns> public async Task CreateAsync(CreateGroupDto inputDto) { bool exist = await _groupRepository.Select.AnyAsync(r => r.Name == inputDto.Name); if (exist) { throw new LinCmsException("分组已存在,不可创建同名分组", ErrorCode.RepeatField); } LinGroup linGroup = _mapper.Map <LinGroup>(inputDto); using var conn = _freeSql.Ado.MasterPool.Get(); DbTransaction transaction = conn.Value.BeginTransaction(); try { long groupId = _freeSql.Insert(linGroup).WithTransaction(transaction).ExecuteIdentity(); List <LinPermission> allPermissions = _freeSql.Select <LinPermission>().ToList(); List <LinGroupPermission> linPermissions = new List <LinGroupPermission>(); inputDto.PermissionIds.ForEach(r => { LinPermission pdDto = allPermissions.FirstOrDefault(u => u.Id == r); if (pdDto == null) { throw new LinCmsException($"不存在此权限:{r}", ErrorCode.NotFound); } linPermissions.Add(new LinGroupPermission(groupId, pdDto.Id)); }); _freeSql.Insert <LinGroupPermission>().WithTransaction(transaction).AppendData(linPermissions).ExecuteAffrows(); transaction.Commit(); } catch { transaction.Rollback(); throw; } //_freeSql.Transaction(() => //{ // long groupId = _freeSql.Insert(linGroup).ExecuteIdentity(); // List<LinPermission> allPermissions = _freeSql.Select<LinPermission>().ToList(); // List<LinGroupPermission> linPermissions = new List<LinGroupPermission>(); // inputDto.PermissionIds.ForEach(r => // { // LinPermission pdDto = allPermissions.FirstOrDefault(u => u.Id == r); // if (pdDto == null) // { // throw new LinCmsException($"不存在此权限:{r}", ErrorCode.NotFound); // } // linPermissions.Add(new LinGroupPermission(groupId, pdDto.Id)); // }); // _freeSql.Insert<LinGroupPermission>().AppendData(linPermissions).ExecuteAffrows(); //}); }
public ResultDto Post([FromBody] CreateGroupDto inputDto) { bool exist = _freeSql.Select <LinGroup>().Any(r => r.Name == inputDto.Name); if (exist) { throw new LinCmsException("分组已存在,不可创建同名分组", ErrorCode.RepeatField); } LinGroup linGroup = _mapper.Map <LinGroup>(inputDto); List <PermissionDto> permissionDtos = ReflexHelper.GeAssemblyLinCmsAttributes(); _freeSql.Transaction(() => { long groupId = _freeSql.Insert(linGroup).ExecuteIdentity(); //批量插入 List <LinAuth> linAuths = new List <LinAuth>(); inputDto.Auths.ForEach(r => { PermissionDto pdDto = permissionDtos.FirstOrDefault(u => u.Permission == r); if (pdDto == null) { throw new LinCmsException($"不存在此权限:{r}", ErrorCode.NotFound); } linAuths.Add(new LinAuth(r, pdDto.Module, (int)groupId)); }); _freeSql.Insert <LinAuth>().AppendData(linAuths).ExecuteAffrows(); }); return(ResultDto.Success("新建分组成功")); }
public async Task <ActionResult <Group> > CreateGroup(CreateGroupDto groupDto) { Group createdGroup; try { var group = new Group() { Name = groupDto.Name, Email = groupDto.Email, Description = groupDto.Description }; createdGroup = await _groupService.CreateGroupAsync(group); } catch (AlreadyExistException ex) { return(BadRequest(ex.Message)); } catch (Exception ex) { _logger.LogError(ex.Message); return(StatusCode(500, new { error = ex.Message })); } return(CreatedAtAction("GetGroupById", new { id = createdGroup.Id }, createdGroup)); }
public async Task CreateGroupAsync(CreateGroupDto group) { var superVisor = await _userManager.FindByIdAsync(group.SuperVisorId) as Teacher; var headMan = await _userManager.FindByIdAsync(group.HeadManId) as Student; var students = await InitializeStudents(group.StudentIds); Group groupToDb = new() { Name = group.Name, Class = group.Class, Courses = null, SuperVisor = superVisor, SuperVisorId = superVisor?.Id, Students = students, HeadMan = headMan, HeadManId = headMan?.Id }; await _groupRepository.AddAsync(groupToDb); await _groupRepository.UnitOfWork.SaveChangesAsync(); var groupId = await GetGroupIdByName(group.Name); await UpdateStudentsAsync(groupId, students); }
public async Task <ActionResult> CreateGroup([FromBody] CreateGroupDto model) { var group = _mapper.Map <Group>(model); await _groupService.CreateGroup(group); return(Ok()); }
public async Task <ActionResult> UpdateGroup( [FromRoute] Guid groupId, [FromBody] CreateGroupDto model) { var group = _mapper.Map <Group>(model); await _groupService.UpdateGroup(groupId, group); return(Ok()); }
public async Task <IActionResult> Creat(CreateGroupDto createGroupDto) { var res = await _groupService.AddAsync(createGroupDto); if (!res.Sucess) { return(Conflict()); } return(Ok(res.Data)); }
public async Task <HttpResponseMessage> CreateGroupAsync(CreateGroupDto createGroupDto) { var serializedGroup = JsonConvert.SerializeObject(createGroupDto); var stringContent = new StringContent(serializedGroup, Encoding.UTF8, "application/json"); RequestHelper.Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", TokenWraper.Token); var response = await RequestHelper.Client.PostAsync("api/Group/CreateGroup", stringContent); return(response); }
public async Task <IActionResult> Create([FromBody] CreateGroupDto createGroupDto) { createGroupDto.OwnerId = UserId; var result = await _unitOfWork.GroupService.Create(createGroupDto); if (!result.Success) { return(result.ApiResult); } return(Created(Url.Link("GetGroup", new { result.Data.Id }), _mapper.Map <GroupDto>(result.Data))); }
public CreatedAtActionResult AddGroup(CreateGroupDto group) { var createdGroup = _groupService.Create(new Group { Name = group.Name }); return(CreatedAtAction(nameof(AddGroup), new { id = createdGroup.Id }, createdGroup)); }
public async Task <BaseResponse <GroupDto> > CreateGroup([FromBody] CreateGroupDto dto) { if (dto == null) { throw new BusinessException("Invalid parameter!", ErrorCode.INVALID_PARAMETER); } var response = new BaseResponse <GroupDto> { Data = await _groupService.CreateGroup(dto), Status = true }; return(await Task.FromResult(response)); }
public async Task <GroupDto> CreateGroup(CreateGroupDto dto) { await ValidateCreateGroup(dto); var now = DateTime.UtcNow; var createdBy = _sessionService.UserId; using (IDbTransaction trans = this.DatabaseConnectService.Connection.BeginTransaction()) { try { var group = dto.ToGroup(); group.CreatedAt = now; group.CreatedBy = createdBy; await this.DatabaseConnectService.Connection.InsertAsync <Group>(group, x => x.AttachToTransaction(trans)); if (dto.Features.Length > 0) { foreach (var item in dto.Features) { var groupFeature = new GroupFeature { FeatureId = item.Id, GroupId = group.Id, CreatedAt = now, ModifiedAt = now }; await this.DatabaseConnectService.Connection.InsertAsync <GroupFeature>(groupFeature, x => x.AttachToTransaction(trans)); } } trans.Commit(); _redisCache.Remove(CacheConst.AllGroup); //return await GetGroupById(group.Id); return(null); } catch (Exception e) { trans.Rollback(); throw new BusinessException(e.Message, ErrorCode.INTERNAL_SERVER_ERROR); } } }
private async Task ValidateCreateGroup(CreateGroupDto dto) { if (dto.Name.IsNullOrWhiteSpace() || dto.Description.IsNullOrWhiteSpace()) { throw new BusinessException("Invalid parameter!", ErrorCode.INVALID_PARAMETER); } var validateGroupName = (await this.DatabaseConnectService.Connection.FindAsync <Group>(x => x .Where($" bys_group.name = @GroupName ") .WithParameters(new { GroupName = dto.Name }))).FirstOrDefault(); if (validateGroupName != null) { throw new BusinessException("Group name already exists", ErrorCode.GROUP_NAME_EXIST); } }
public async Task <IActionResult> CreateGroup([FromBody] CreateGroupDto groupDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var group = _mapper.Map <CreateGroupDto, Group>(groupDto); group.CreateDateTime = DateTime.Now; _groupRepository.AddAsync(group); await _unitOfWork.CompleteAsync(); var result = _mapper.Map <Group, CreateGroupDto>(group); return(Ok(result)); }
public static Group ToGroup(this CreateGroupDto dto) { if (dto == null) { return(null); } Group entity = new Group(); entity.Id = Guid.NewGuid(); entity.Name = dto.Name; entity.Description = dto.Description; return(entity); }
public void IMapper() { CreateGroupDto inputDto = new CreateGroupDto() { Info = "11", Name = "11" }; UpdateGroupDto update = new UpdateGroupDto() { Info = "11", Name = "11" }; LinGroup d = _mapper.Map <LinGroup>(inputDto); LinGroup d2 = _mapper.Map <LinGroup>(update); }
public async Task OrganizationOwnerShouldCreateGroup() { var dto = new CreateGroupDto { Name = "New group" }; var json = fixture.Serialize(dto); var response = await fixture.RequestSender.PostAsync("groups", json); response.StatusCode.Should().Be(HttpStatusCode.OK); var responseData = await response.Content.ReadAsStringAsync(); int groupId; int.TryParse(responseData, out groupId).Should().BeTrue(); var group = await fixture.ExecuteDbContext(x => x.Groups.Include(x => x.GroupMembers).FirstOrDefaultAsync(x => x.Id == groupId)); group.Name.Should().Be(dto.Name); group.GroupMembers.Should().OnlyContain(x => x.UserId == fixture.UserId); }
public void IMapper() { CreateGroupDto inputDto = new CreateGroupDto() { Auths = new List <string>() { "查询日志记录的用户" }, Info = "11", Name = "11" }; UpdateGroupDto update = new UpdateGroupDto() { Info = "11", Name = "11" }; LinGroup d = _mapper.Map <LinGroup>(inputDto); LinGroup d2 = _mapper.Map <LinGroup>(update); }
public async Task <IActionResult> Create([FromForm] CreateGroupDto newGroup) { var imageName = string.Empty; var imageUploadPath = Path.Combine(_hostingEnvironment.WebRootPath, "Media/GroupImage/"); try { if (newGroup.Image != null && newGroup.Image.Length > 0) { string extension = Path.GetExtension(newGroup.Image.FileName); imageName = DateTime.Now.ToFileTime() + "_" + UserId + extension; var filePath = Path.Combine(imageUploadPath, imageName); //Path.Combine(imageUploadPath, DateTime.Now.ToFileTime()+"_"+ userid + extension); using (var fileStream = new FileStream(filePath, FileMode.Create)) { await newGroup.Image.CopyToAsync(fileStream); } } var groupMaster = new Post_GroupMaster { CDate = DateTime.UtcNow, CLogin = UserId, Description = newGroup.Description, FormedOn = DateTime.UtcNow, OpenOrClosed = newGroup.OpenOrClosed, Type = GroupType.Group, GroupImage = imageName, GroupName = newGroup.GroupName, GroupMembers = new List <Post_GroupMember>() }; if (newGroup.Members.Any()) { foreach (var memberId in newGroup.Members) { groupMaster.GroupMembers.Add(new Post_GroupMember { AddedBy = UserId, CDate = DateTime.UtcNow, IsActive = true, IsGroupAdmin = false, MemberId = memberId }); } } groupMaster.GroupMembers.Add(new Post_GroupMember { AddedBy = UserId, CDate = DateTime.UtcNow, IsActive = true, IsGroupAdmin = true, MemberId = UserId }); await _db.Post_GroupMasters.AddAsync(groupMaster); await _db.SaveChangesAsync(); return(Ok(new GroupResultDto { Id = groupMaster.Id, Name = groupMaster.GroupName, Discription = groupMaster.Description, Image = groupMaster.GroupImage })); } catch (Exception e) { throw e; } }
public Task <OperationResult <int> > CreateGroup(CreateGroupDto createGroupDto) { return(groupService.CreateGroup(createGroupDto.Name)); }
public async Task <IActionResult> CreateGroup(CreateGroupDto createGroupDto) { var result = await groupOrchestrator.CreateGroup(createGroupDto); return(ActionResult(result)); }
public async Task <UnifyResponseDto> CreateAsync([FromBody] CreateGroupDto inputDto) { await _groupService.CreateAsync(inputDto); return(UnifyResponseDto.Success("新建分组成功")); }