示例#1
0
        public void Update(CostPlanDto dto)
        {
            using (var db = new DbContext())
            {
                Entities.CostPlan costPlan = db.CostPlan.Single(x => x.MarketingYearId == dto.MarketingYearId && x.Type == dto.Type);

                costPlan.Cost = dto.Cost;

                db.SaveChanges();
            }
        }
示例#2
0
        public void Insert(CostPlanDto dto)
        {
            var entity = new Entities.CostPlan
            {
                Type            = dto.Type,
                Cost            = dto.Cost,
                MarketingYearId = dto.MarketingYearId
            };

            using (var db = new DbContext())
            {
                db.CostPlan.Add(entity);
                db.SaveChanges();
            }
        }
示例#3
0
        public void UpdateCostPlan(CostPlanViewModel model, int marketingYearId)
        {
            if (model.Type <= 0)
            {
                throw new Exception("Nie można edytować planu kosztów koła łowieckiego");
            }

            var dto = new CostPlanDto
            {
                Type            = model.Type,
                Cost            = model.Cost,
                MarketingYearId = marketingYearId
            };

            _costPlanDao.Update(dto);
        }
示例#4
0
        private IList <CostPlanDto> ToDtos(IList <Entities.CostPlan> costPlanList)
        {
            var costPlanDtos = new List <CostPlanDto>();

            foreach (Entities.CostPlan costPlan in costPlanList)
            {
                var costPlanDto = new CostPlanDto
                {
                    Id              = costPlan.Id,
                    Type            = costPlan.Type,
                    Cost            = costPlan.Cost,
                    MarketingYearId = costPlan.MarketingYearId
                };
                costPlanDtos.Add(costPlanDto);
            }
            return(costPlanDtos);
        }
示例#5
0
        public void AddCostPlan(CostPlanViewModel model, int marketingYearId)
        {
            if (model.Type == 0)
            {
                throw new Exception("Nie można dodać planu kosztów koła łowieckiego");
            }

            IList <CostPlanDto> existingEquipmentPlanDtos = _costPlanDao.GetByMarketingYear(marketingYearId);

            if (existingEquipmentPlanDtos.Any(x => x.Type == model.Type))
            {
                throw new Exception($"Plan {GetCostTypeName(model.Type)} już istnieje! Proszę użyć opcji edycji istniejącego już planu.");
            }

            var dto = new CostPlanDto
            {
                Type            = model.Type,
                Cost            = model.Cost,
                MarketingYearId = marketingYearId
            };

            _costPlanDao.Insert(dto);
        }