Esempio n. 1
0
 public FishDto Build(Fish fish)
 {
     return new FishDto
                {
                    Id = fish.Id,
                    Name = fish.Name,
                    LocaleName = fish.Locale.Name,
                    Latitude = fish.Locale.Latitude,
                    Longitude = fish.Locale.Longitude
                };
 }
Esempio n. 2
0
        public HeaderViewModel Build(Fish fish)
        {
            var viewModel = new HeaderViewModel
                {
                    Lakes = this.lakeRepository.GetAll().ToDtoList(),
                    SelectedGenusTypeId = fish.Genus.GenusType.Id,
                    SelectedLakeId = fish.Locale.Lake.Id,
                    GenusTypes = this.genusTypeRepository.GetFromLake(fish.Locale.Lake.Id).ToDtoList()
                };

            return viewModel;
        }
Esempio n. 3
0
 public static FishDto Build(Fish fish)
 {
     return new FishDto
         {
             Id = fish.Id,
             Name = fish.Name,
             Locale = Build(fish.Locale),
             UrlName = fish.UrlName,
             Genus = Build(fish.Genus),
             Species = Build(fish.Species),
             Description = string.IsNullOrEmpty(fish.Description) ? fish.Species.Description : fish.Description,
             Photos = fish.Photos.ToDtoList()
         };
 }
Esempio n. 4
0
        public CrudResult UpdateFish(FishEditFormViewModel viewModel)
        {
            try
            {
                this.Fish = this.fishRepository.Update(viewModel.Id, viewModel.Genus, viewModel.Species,
                                                       viewModel.Locales, viewModel.Description);
            }
            catch(ItemDoesNotExistException)
            {
                return new CrudResult {Message = "Item does not exist", Success = false};
            }
            catch (Exception)
            {
                return new CrudResult {Success = false, Message = "An error occured"};
            }

            return new CrudResult {Success = true, Message = string.Format("{0} has been updated", Fish.Name)};
        }
Esempio n. 5
0
        public Fish Add(int genusId, int speciesId, int localeId, string description)
        {
            var genus = this.dataContext.Genus.First(g => g.Id == genusId);

            var species = this.dataContext.Species.First(s => s.Id == speciesId);

            var locale = this.dataContext.Locales.First(l => l.Id == localeId);

            if (this.dataContext.Fish.Any(f => f.Genus.Id == genusId && f.Species.Id == speciesId && f.Locale.Id == localeId))
            {
                throw new ItemExistsException();
            }

            var fish = new Fish { Genus = genus, Species = species, Locale = locale, Description = description };

            fish = this.dataContext.Fish.Add(fish);

            this.dataContext.SaveChanges();

            return fish;
        }
Esempio n. 6
0
        public CrudResult CreateFish(FishEditFormViewModel viewModel)
        {
            try
            {
                this.Fish = this.fishRepository.Add(viewModel.Genus, viewModel.Species, viewModel.Locales,
                                                   viewModel.Description);
            }
            catch (ItemExistsException)
            {
                return new CrudResult {Success = false, Message = "Fish already exists in database"};
            }
            catch(Exception)
            {
                return new CrudResult { Success = false, Message = "An error occured" };
            }

            return new CrudResult
                       {
                           Success = true,
                           Message = string.Format("{0} added to database", Fish.Name)
                       };
        }
        public PhotoGalleryViewModel Build(Fish fish)
        {
            var viewModel = new PhotoGalleryViewModel { Name = fish.Name, Photos = fish.Photos.ToDtoList() };

            return viewModel;
        }
Esempio n. 8
0
 public bool PostFishUpdate(Fish fish, string url)
 {
     return this.Tweet("Updated", "fish", url, BuildHashTags(fish.Genus.GenusType.Name, fish.Locale.Lake.Name));
 }
Esempio n. 9
0
 public bool PostFishAddition(Fish newFish, string url)
 {
     return this.Tweet("New", "fish", url, BuildHashTags(newFish.Genus.GenusType.Name, newFish.Locale.Lake.Name));
 }
Esempio n. 10
0
 private string BuildAbsoulteUrl(Fish fish)
 {
     return UrlHelper.ToPublicUrl(new Uri(Url.Action("Index", "Fish", new { Area = string.Empty, fishName = fish.UrlName }), UriKind.Relative), this.Request);
 }