public CrResult <ChannelRoleDto> CreateChannel(ChannelCrDto channelDto, long userId) { var result = new CrResult <ChannelRoleDto>(); CheckData(result, channelDto); if (result.ActionResult == ActionResult.Success) { try { var c = _context.Channel.Add(Converter.ConvertToChannel(channelDto)); var userRole = UserRolesManager.AddUserRole(c.channel_id, userId, _adminId, _context); _context.SaveChanges(); userRole.Role = new Role { role_id = 0, role_name = "Admin" }; result.CreatedObject = Converter.ConvertToChannelRoleDto(userRole); } catch (DbUpdateException) { result.ActionResult = ActionResult.DatabaseError; } } return(result); }
public ChannelCreationViewModel(ObservableCollection <ChannelInfo> channels, SchedulerClient cl, IEnumerable <RolePermitions> rolesPermitions, IEnumerable <ImportanceDto> importanceDtos) { _cl = cl; this._rolesPermitions = rolesPermitions; this._importanceDtos = importanceDtos; _channelCreationDto = new ChannelCrDto(); _channels = channels; }
private void CheckData(Result r, ChannelCrDto channelCrDto) { if (channelCrDto == null) { r.AddError(new Error(CheckStatus.ArgumentIsNull, nameof(channelCrDto))); return; } var checkStatus = Helper.CheckParam(channelCrDto.Description, _descriptionLength, _descriptionNullAllowed); if (checkStatus != CheckStatus.Success) { r.AddError(new Error(checkStatus, nameof(channelCrDto.Description))); } checkStatus = Helper.CheckParam(channelCrDto.Name, _nameLength, _nameNullAllowed); if (checkStatus != CheckStatus.Success) { r.AddError(new Error(checkStatus, nameof(channelCrDto.Name))); } }