Exemplo n.º 1
0
        public AddResult Add(string name, int lakeId, string userName)
        {
            if (this.dataContext.GenusTypes.Any(g => g.Name == name))
            {
                return AddResult.AlreadyExists;
            }

            var lake = this.dataContext.Lakes.First(l => l.Id == lakeId);

            var genusType = new GenusType { Name = name.Trim(), Lake = lake };

            try
            {
                this.dataContext.GenusTypes.Add(genusType);

                this.dataContext.SaveChanges();
            }
            catch (Exception)
            {
                return AddResult.Failure;
            }

            this.logger.LogAdd(genusType, userName);

            return AddResult.Success;
        }
Exemplo n.º 2
0
        public static GenusTypeDto Build(GenusType genusType)
        {
            var genera = new List<GenusDto>();

            genusType.Genus.ToList().ForEach(t => genera.Add(Build(t)));

            return new GenusTypeDto { Genera = genera, Id = genusType.Id, Name = genusType.Name, Description = genusType.Description, NumberOfGenera = genusType.Genus.Count, Lake = new LakeDto { Id = genusType.Lake.Id, Name = genusType.Lake.Name } };
        }
Exemplo n.º 3
0
        public HeaderViewModel Build(GenusType genusType)
        {
            var viewModel = new HeaderViewModel { SelectedGenusTypeId = genusType.Id, SelectedLakeId = genusType.Lake.Id, GenusTypes = this.genusTypeRepository.GetFromLake(genusType.Lake.Id).ToDtoList(), Lakes = this.lakeRepository.GetAll().ToDtoList() };

            return viewModel;
        }
Exemplo n.º 4
0
 public GenusTypeDto Build(GenusType genusType)
 {
     return new GenusTypeDto { Id = genusType.Id, Name = genusType.Name };
 }