Esempio n. 1
0
        public async Task <IActionResult> PutMessage([FromRoute] int id, [FromBody] Message message)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(Ok(message));
        }
        public async Task <IActionResult> PutUnitOfMeasurement([FromRoute] int id, [FromBody] UnitOfMeasurement unitOfMeasurement)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(NoContent());
        }
Esempio n. 3
0
        public async Task <IActionResult> PutRefRange([FromRoute] int id, [FromBody] RefRange refRange)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            refRange.DateModified = DateTime.Now;
            refRange.ModifiedBy   = HttpContext.User.Identity.Name;

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

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

            return(Ok(refRange));
        }
Esempio n. 4
0
        public async Task <IActionResult> PutTest([FromRoute] int id, [FromBody] Test test)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            test.DateModified = DateTime.Now;
            test.ModifiedBy   = HttpContext.User.Identity.Name;

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

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

            UpdateTestTags(test);

            test = await _context.Tests
                   .Include(t => t.Department)
                   .ThenInclude(d => d.Contacts)
                   .ThenInclude(c => c.ContactDetails)
                   .ThenInclude(cd => cd.ContactType)
                   .Include(t => t.Containers)
                   .ThenInclude(c => c.SpecimenType)
                   .Include(t => t.Containers)
                   .ThenInclude(c => c.CollectionContainerType)
                   .Include(t => t.Tags)
                   .ThenInclude(tt => tt.TagType)
                   .Include(t => t.RefRanges)
                   .SingleOrDefaultAsync(m => m.Id == id);

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

            return(Ok(test));
        }
        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> PutDepartment([FromRoute] int id, [FromBody] Department department)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            if (DuplicateValues(department))
            {
                return(BadRequest(department));
            }

            department.DateModified = DateTime.Now;
            department.ModifiedBy   = HttpContext.User.Identity.Name;

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutTagType([FromRoute] int id, [FromBody] TagType tagType)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            if (DuplcateValues(tagType))
            {
                return(BadRequest(tagType));
            }

            tagType.ModifiedBy   = HttpContext.User.Identity.Name;
            tagType.DateModified = DateTime.Now;

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutContactDetail([FromRoute] int id, [FromBody] ContactDetail contactDetail)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            if (DuplicateValues(contactDetail))
            {
                return(BadRequest(contactDetail));
            }

            contactDetail.DateModified = DateTime.Now;
            contactDetail.ModifiedBy   = HttpContext.User.Identity.Name;

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutTag([FromRoute] int id, [FromBody] Tag tag)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            tag.DateModified = DateTime.Now;
            tag.ModifiedBy   = HttpContext.User.Identity.Name;

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

            try
            {
                await _context.SaveChangesAsync();

                tag.TagType =
                    _context.TagTypes.SingleOrDefault(tt => tt.Code == Enum.GetName(typeof(TagTypeEnums), TagTypeEnums.Synonym));

                return(Ok(tag));
            }
            catch (Exception e)
            {
                if (!TagExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
        }
        public async Task <IActionResult> UploadBlob(int containerTypeId, IFormFile file)
        {
            var containerType = await _context.CollectionContainerTypes.FirstOrDefaultAsync(ct => ct.Id == containerTypeId);

            if (Equals(containerType, null))
            {
                return(NotFound());
            }

            if (Equals(file, null))
            {
                return(BadRequest("null file"));
            }

            if (file.Length == 0)
            {
                return(BadRequest("Empty File"));
            }

            if (file.Length > _imageSettings.MaxBytes)
            {
                return(BadRequest("Max file size exceeded"));
            }

            if (!_imageSettings.AcceptedFileTypes.Any(s => s == Path.GetExtension(file.FileName)))
            {
                return(BadRequest("File type not allowed"));
            }

            await DeleteAllBlobsByContainerTypeId(containerTypeId);
            await DeleteAllThumbnailBlobsByContainerTypeId(containerTypeId);

            DeleteAllImagesByContainerTypeId(containerTypeId);

            var fileExtension = Path.GetExtension(file.FileName).ToLower();

            var fullSizeFolderPath = Path.Combine(_host.ContentRootPath, "fullsize");
            var fullsizeFileName   = Guid.NewGuid().ToString() + fileExtension;
            var fullsizeFilePath   = Path.Combine(fullSizeFolderPath, fullsizeFileName);

            await CreateFullsizeImageInLocalFolder(fullSizeFolderPath, file, fullsizeFilePath);
            await UploadFullsizeBlobToBlobStorage(fullsizeFileName, fullsizeFilePath);

            var thumbnailFolderPath = Path.Combine(_host.ContentRootPath, "thumbnail");
            var thumbnailFileName   = Guid.NewGuid().ToString() + fileExtension;
            var thumbnailFilePath   = Path.Combine(thumbnailFolderPath, thumbnailFileName);

            await CreateMagickThumbnailInLocalFolder(fullsizeFilePath, thumbnailFolderPath, thumbnailFilePath);
            await UploadThumbnailBlobStorage(thumbnailFileName, thumbnailFilePath);

            var image = new Image
            {
                FileName          = fullsizeFileName,
                FullsizeFileName  = fullsizeFileName,
                ThumbnailFileName = thumbnailFileName
            };

            containerType.Images.Add(image);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            Directory.Delete(fullSizeFolderPath, true);
            Directory.Delete(thumbnailFolderPath, true);

            return(Ok(image));
        }