示例#1
0
        public async Task <IActionResult> GetNetworkAsync(int id)
        {
            NetworkDTO user = await _networkDAO.FindById(id);

            if (user == null)
            {
                return(new NotFoundResult());
            }

            return(new ObjectResult(user));
        }
示例#2
0
 public static Network FromDTO(NetworkDTO dto)
 {
     return(new Network
     {
         Id = dto.Id,
         AuthorId = dto.AuthorId,
         Name = dto.Name,
         Description = dto.Description,
         ImageUrl = dto.ImageUrl,
         Private = dto.Private
     });
 }
示例#3
0
        private async Task <NetworkDTO> joinWithSubscriptionAsync(NetworkDTO dto)
        {
            IEnumerable <SubscriptionDTO> subscriptions = await _subscriptionDAO.findByNetworkIdAsync(dto.Id);

            foreach (SubscriptionDTO subscription in subscriptions)
            {
                UserDTO user = await _userDAO.FindById(subscription.UserId);

                subscription.UserName = user.FirstName + " " + user.LastName;
            }

            dto.subscriptions = subscriptions;

            return(dto);
        }
示例#4
0
        public async Task <NetworkDTO> Insert(NetworkDTO dto)
        {
            Counter counter = await _counterDAO.GetCountersAsync();

            int id = counter.Networks++;
            await _counterDAO.UpdateCountersAsync(counter);

            Network network = Network.FromDTO(dto);

            network.Id = id;

            await _context.Networks.InsertOneAsync(network);

            return(NetworkDTO.FromNetwork(network));
        }
示例#5
0
        public async Task <IEnumerable <NetworkDTO> > FindAll()
        {
            IEnumerable <Network> networks = await _context.Networks.Find(_ => true).ToListAsync();

            List <NetworkDTO> result = new List <NetworkDTO>();

            foreach (Network network in networks)
            {
                NetworkDTO dto = NetworkDTO.FromNetwork(network);
                dto = await joinWithSubscriptionAsync(dto);

                result.Add(dto);
            }

            return(result);
        }
示例#6
0
        public async Task <NetworkDTO> FindById(int id)
        {
            Network network = await _context.Networks
                              .Find(Builders <Network> .Filter.Eq(u => u.Id, id))
                              .FirstOrDefaultAsync();

            if (network == null)
            {
                return(null);
            }

            NetworkDTO dto = NetworkDTO.FromNetwork(network);

            dto = await joinWithSubscriptionAsync(dto);

            return(dto);
        }
示例#7
0
        public List <NetworkDTO> GetSummary()
        {
            var list = new List <NetworkDTO>();

            foreach (var network in networks)
            {
                var d = new NetworkDTO();
                d.Name = network.Name;
                d.Id   = network.Id;
                foreach (var c in network.Channels)
                {
                    d.Channels.Add(new ChannelDTO()
                    {
                        Name = c.Name,
                        Id   = c.Id
                    });
                }
                list.Add(d);
            }

            return(list);
        }
示例#8
0
        public async Task <IActionResult> InsertNetwork([FromForm(Name = "image")] IFormFile imageFile, [FromForm] PostNetworkRequest request)
        {
            var storageConnectionString = _configuration["ConnectionStrings:AzureStorageConnectionString"];

            if (CloudStorageAccount.TryParse(storageConnectionString, out CloudStorageAccount storageAccount))
            {
                CloudBlobClient    blobClient = storageAccount.CreateCloudBlobClient();
                CloudBlobContainer container  = blobClient.GetContainerReference("networkimages");
                await container.CreateIfNotExistsAsync();

                var permissions = container.GetPermissions();
                if (permissions.PublicAccess == BlobContainerPublicAccessType.Off)
                {
                    permissions.PublicAccess = BlobContainerPublicAccessType.Blob;
                    container.SetPermissions(permissions);
                }

                var blob = container.GetBlockBlobReference(imageFile.FileName);

                await blob.UploadFromStreamAsync(imageFile.OpenReadStream());

                string uri = blob.Uri.ToString();

                NetworkDTO network = new NetworkDTO
                {
                    Name        = request.Name,
                    Description = request.Description,
                    AuthorId    = request.AuthorId,
                    ImageUrl    = uri
                };

                NetworkDTO insertedNetwork = await _networkDAO.Insert(network);

                return(new OkObjectResult(insertedNetwork));
            }

            return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
        }