Beispiel #1
0
        public async Task <IHttpActionResult> Get(int id)
        {
            try
            {
                var activity = _activityOperations.Get(id);
                if (activity == null)
                {
                    return(this.Result404("This activity is not found"));
                }
                var result   = Mapper.Map <ActivityViewModelGet>(activity);
                var pictures = await _pictureOperations.GetByLinkedObject(LinkedObjectType.Activity, id);

                var picturesVirewModels = new List <PictureViewModelShortGet>();
                foreach (var picture in pictures)
                {
                    picturesVirewModels.Add(new PictureViewModelShortGet
                    {
                        Id     = picture.Id,
                        Url    = Url.Content($"~/api/picture/{picture.Id}"),
                        IsMain = picture.IsMain
                    });
                }
                result.Pictures = picturesVirewModels;
                return(Ok(result));
            }
            catch (Exception ex)
            {
                ErrorLogger.Log("CANNOT GET ACTIVITY", ex);
                throw;
            }
        }
        public void Get_Ok_Test()
        {
            var activity = _context.Activities.First();
            var result   = _activityOperations.Get(activity.Id);

            Assert.AreEqual(activity.Name, result.Name);
        }