示例#1
0
 public async Task<IActionResult> Get(Guid id)
 {
     var collectionWithGroups = await _collectionRepository.GetByIdWithGroupsAsync(id);
     var collection = collectionWithGroups?.Item1;
     if (collection == null || collection.OrganizationId != _currentContext.OrganizationId)
     {
         return new NotFoundResult();
     }
     var response = new CollectionResponseModel(collection, collectionWithGroups.Item2);
     return new JsonResult(response);
 }
示例#2
0
 public async Task<IActionResult> Put(Guid id, [FromBody] CollectionUpdateRequestModel model)
 {
     var existingCollection = await _collectionRepository.GetByIdAsync(id);
     if (existingCollection == null || existingCollection.OrganizationId != _currentContext.OrganizationId)
     {
         return new NotFoundResult();
     }
     var updatedCollection = model.ToCollection(existingCollection);
     var associations = model.Groups?.Select(c => c.ToSelectionReadOnly());
     await _collectionService.SaveAsync(updatedCollection, associations);
     var response = new CollectionResponseModel(updatedCollection, associations);
     return new JsonResult(response);
 }
示例#3
0
        public async Task <IActionResult> GetCollection(int id)
        {
            CustomValidation();

            var userId = User.GetSubjectId();

            var user = await _context.UserData.FirstOrDefaultAsync(UserIdPredicate(userId));

            if (user == null)
            {
                throw new HttpResponseException(null, HttpStatusCode.Unauthorized);
            }

            var collection = await _context.Collection
                             .Include(c => c.Image)
                             .Include(c => c.Records)
                             .FirstOrDefaultAsync(c => c.Id == id && c.OwnerId == user.Id);

            if (collection == null)
            {
                throw new HttpResponseException(null, HttpStatusCode.NotFound);
            }

            var customCollection = new CollectionResponseModel
            {
                Id           = collection.Id,
                Description  = collection.Description,
                Name         = collection.Name,
                CreationDate = collection.CreationDate,
                RecordCount  = collection.Records.Count,
                Image        = collection.Image,
                ImageId      = collection.ImageId,
                OwnerId      = collection.OwnerId
            };

            return(Ok(customCollection));
        }