public static ContainerDetailsViewModel ContainerDetailsToViewModel(this ContainerDetails containerDetails)
        {
            if (Equals(containerDetails, null))
            {
                return(null);
            }

            var containerDetailsViewModel = new ContainerDetailsViewModel()
            {
                Id     = containerDetails.Id,
                TestId = containerDetails.TestId,
                CollectionContainerType = containerDetails?.CollectionContainerType.CollectionContainerTypeToViewModel(),
                SpecimenType            = containerDetails?.SpecimenType.ToSpecimenTypeViewModel(),
                Active                               = containerDetails.Active,
                GeneralDetails                       = containerDetails.GeneralDetails,
                CollectionConditions                 = containerDetails.CollectionConditions,
                CollectionContainerTypeId            = containerDetails.CollectionContainerTypeId,
                DietaryRequirements                  = containerDetails.DietaryRequirements,
                DrawOrder                            = containerDetails.DrawOrder,
                NumberOfCollectionContainersRequired = containerDetails.NumberOfCollectionContainersRequired,
                SpecimenTypeId                       = containerDetails.SpecimenTypeId,
                StorageConditions                    = containerDetails.StorageConditions,
                TransportConditions                  = containerDetails.TransportConditions
            };

            return(containerDetailsViewModel);
        }
Пример #2
0
        private static List <string> RetrieveBlobs(ContainerDetails details)
        {
            var sourceConnectionString = CloudConfigurationManager.GetSetting(details.Source);
            var sourceStorageAccount   =
                CloudStorageAccount.Parse(sourceConnectionString);
            var blobClient         = sourceStorageAccount.CreateCloudBlobClient();
            var containerReference = blobClient.GetContainerReference(details.ContainerName);
            var blobs = containerReference.ListBlobs().Cast <CloudBlob>().Select(x => JsonConvert.SerializeObject(new BlobDetails
            {
                Source        = details.Source,
                Destination   = details.Destination,
                ContainerName = details.ContainerName,
                BlobName      = x.Name
            })).ToList();

            blobs.Add(JsonConvert.SerializeObject(new BlobDetails
            {
                Source        = details.Source,
                Destination   = details.Destination,
                ContainerName = details.ContainerName,
                BlobName      = "blob404"
            }));

            return(blobs);
        }
        private static void CreateContainers(ContainerDetails details)
        {
            var destConnectionString = CloudConfigurationManager.GetSetting(details.Destination);
            var destStorageAccount   =
                CloudStorageAccount.Parse(destConnectionString);
            var blobClient         = destStorageAccount.CreateCloudBlobClient();
            var containerReference = blobClient.GetContainerReference(details.ContainerName);

            containerReference.CreateIfNotExists();
        }
        public async Task <IActionResult> PutContainerDetails([FromRoute] int id, [FromBody] ContainerDetails containerDetails)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != containerDetails.Id)
            {
                return(BadRequest());
            }

            containerDetails.DateModified   = DateTime.Now;
            containerDetails.ModifiedBy     = HttpContext.User.Identity.Name;
            containerDetails.GeneralDetails = UpdateGeneralDetails(containerDetails);

            _context.Entry(containerDetails).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ContainerDetailsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            var updatedContainerDetails = await _context.ContainerDetails
                                          .Include(cd => cd.CollectionContainerType)
                                          .Include(cd => cd.SpecimenType)
                                          .SingleOrDefaultAsync(cd => cd.Id == id);

            if (updatedContainerDetails == null)
            {
                return(NotFound());
            }

            return(Ok(updatedContainerDetails));
        }
        public async Task <IActionResult> PostContainerDetails([FromBody] ContainerDetails containerDetails)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (containerDetails.TestId == 0)
            {
                return(BadRequest(ModelState));
            }

            containerDetails.CreatedBy      = HttpContext.User.Identity.Name;
            containerDetails.DateCreated    = DateTime.Now;
            containerDetails.DrawOrder      = GetLastContainerDrawOrderForTest(containerDetails.TestId) + 1;
            containerDetails.GeneralDetails = UpdateGeneralDetails(containerDetails);
            // Save to add back after creation
            var containerType = containerDetails.CollectionContainerType;
            var specimenType  = containerDetails.SpecimenType;

            // Make them null so that save completes
            containerDetails.CollectionContainerType = null;
            containerDetails.SpecimenType            = null;

            try
            {
                _context.ContainerDetails.Add(containerDetails);
                await _context.SaveChangesAsync();

                // Add types back in so they are returned to client
                containerDetails.CollectionContainerType = containerType;
                containerDetails.SpecimenType            = specimenType;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            return(CreatedAtAction("GetContainerDetails", new { id = containerDetails.Id }, containerDetails));
        }
        private string UpdateGeneralDetails(ContainerDetails containerDetails)
        {
            var sb = new StringBuilder();

            var specimenType = _context.SpecimenTypes.SingleOrDefault(st => st.Id == containerDetails.SpecimenTypeId);

            if (!Equals(specimenType, null))
            {
                sb.Append($"Specimen Type: {specimenType.Description}");
            }

            var containerType =
                _context.CollectionContainerTypes.SingleOrDefault(ct =>
                                                                  ct.Id == containerDetails.CollectionContainerTypeId);

            if (!Equals(containerType, null))
            {
                sb.Append(
                    $", {containerType.Description}");
            }


            return(sb.ToString());
        }