Esempio n. 1
0
        public void Update(PastureDto dto)
        {
            using (var db = new DbContext())
            {
                Entities.Pasture pasture = db.Pasture.Single(x => x.Id == dto.Id);

                pasture.Section     = dto.Section;
                pasture.District    = dto.District;
                pasture.Forestry    = dto.Forestry;
                pasture.Description = dto.Description;
                pasture.CreatedDate = dto.CreatedDate;
                pasture.RemovedDate = dto.RemovedDate;

                db.SaveChanges();
            }
        }
Esempio n. 2
0
        public void Insert(PastureDto dto)
        {
            var entity = new Entities.Pasture
            {
                Section     = dto.Section,
                District    = dto.District,
                Forestry    = dto.Forestry,
                Description = dto.Description,
                CreatedDate = dto.CreatedDate,
                RemovedDate = dto.RemovedDate
            };

            using (var db = new DbContext())
            {
                db.Pasture.Add(entity);
                db.SaveChanges();
            }
        }
Esempio n. 3
0
        public void AddPasture(PastureViewModel model, int marketingYearId)
        {
            if (model.Section <= 0 || model.District <= 0 || String.IsNullOrWhiteSpace(model.Forestry))
            {
                throw new Exception("Wystąpił nieznany błąd podczas dodawania paśnika.");
            }

            var dto = new PastureDto
            {
                Section     = model.Section,
                District    = model.District,
                Forestry    = model.Forestry,
                Description = model.Description,
                CreatedDate = model.CreatedDate,
                RemovedDate = model.RemovedDate
            };

            _pastureDao.Insert(dto);
        }
Esempio n. 4
0
        private IList <PastureDto> ToDtos(IList <Entities.Pasture> entityList)
        {
            var dtos = new List <PastureDto>();

            foreach (Entities.Pasture entity in entityList)
            {
                var dto = new PastureDto
                {
                    Id          = entity.Id,
                    Section     = entity.Section,
                    District    = entity.District,
                    Forestry    = entity.Forestry,
                    Description = entity.Description,
                    CreatedDate = entity.CreatedDate,
                    RemovedDate = entity.RemovedDate
                };
                dtos.Add(dto);
            }
            return(dtos);
        }