Ejemplo n.º 1
0
        public async Task <IActionResult> UpdateAsync(long id, AgreementDTO agreementDTO)
        {
            var existing = await _unitOfWork.Agreements.GetByIdAsync(id);

            if (existing == null)
            {
                return(NotFound($"Agreement {id} could not be found."));
            }

            var workPeriods = await _unitOfWork.WorkPeriods.FindAsync(w => w.AgreementId == id);

            if (workPeriods.ToList().Count != 0)
            {
                return(BadRequest("Can not change agreement as one or more work periods depend on it. Please create a new one."));
            }

            var agreementModel = _mapper.Map <Agreement>(agreementDTO);
            await _unitOfWork.Agreements.UpdateAsync(id, agreementModel);

            await _unitOfWork.CompleteAsync();

            agreementDTO = _mapper.Map <AgreementDTO>(existing);

            return(Ok(agreementDTO));
        }
Ejemplo n.º 2
0
 public async Task <ActionResult <AgreementDTO> > UpdateAsync([FromBody] AgreementDTO model)
 {
     try
     {
         return(Ok(await agreementService.UpdateAsync(model)));
     }
     catch (NotFoundException e)
     {
         return(NotFound(new { Id = model.Id, e.Message }));
     }
     catch (ValidationException e)
     {
         return(BadRequest(e.ValidationErrors));
     }
 }
Ejemplo n.º 3
0
        public async Task <IActionResult> CreateAsync([FromBody] AgreementDTO agreementDTO)
        {
            if (agreementDTO == null)
            {
                return(BadRequest());
            }

            var agreementModel = _mapper.Map <Agreement>(agreementDTO);
            await _unitOfWork.Agreements.AddAsync(agreementModel);

            await _unitOfWork.CompleteAsync();

            agreementDTO = _mapper.Map <AgreementDTO>(agreementModel);

            return(CreatedAtRoute("GetAgreement", new { id = agreementDTO.Id }, agreementDTO));
        }
        public int CreateAgreement(AgreementDTO agreement)
        {
            var customer = customerRepository.GetNameByPersonalId(agreement.PersonaId);

            if (customer == null)
            {
                return(0);
            }
            if (!Enum.GetNames(typeof(BaseRateCodeEnum)).Contains(agreement.Code))
            {
                return(0);
            }
            customer.Agreements.Add(new Agreement
            {
                Margin       = agreement.Margin,
                Amount       = agreement.Amount,
                Duration     = agreement.Duration,
                BaseRateCode = agreement.Code,
            });
            customerRepository.UpdateCustomer(customer);
            return(customerRepository.Save());
        }
Ejemplo n.º 5
0
        protected override void Seed(DatabaseContext context)
        {
            // Here you can seed your core data if you have any.
            var baseTariff = new TariffDTO()
            {
                Name  = "base Tariff",
                Price = 4.0
            };
            var dayTariff = new TariffDTO()
            {
                Name  = "Day Tariff",
                Price = 4.2
            };
            var nightTariff = new TariffDTO()
            {
                Name  = "Night Tariff",
                Price = 4.2
            };

            context.TariffDTOs.Add(baseTariff);
            context.TariffDTOs.Add(dayTariff);
            context.TariffDTOs.Add(nightTariff);

            var meterType = new MeterTypeDTO()
            {
                ManufacturerName     = "Meteor",
                ModelName            = "Signal 01",
                CalibrationIntervals = 10
            };

            var fistAgreement = new AgreementDTO()
            {
                Name    = "First",
                Number  = "01-01-2018",
                BegDate = new DateTime(2018, 3, 1),
                EndDate = new DateTime(2020, 3, 1),
                Deleted = false
            };

            var secondAgr = new AgreementDTO()
            {
                Name    = "Second (deleted)",
                Number  = "01-01-2018",
                BegDate = new DateTime(2018, 3, 1),
                EndDate = new DateTime(2020, 3, 1),
                Deleted = true
            };

            context.AgreementDTOs.Add(fistAgreement);
            context.AgreementDTOs.Add(secondAgr);

            var unitHouse = new UnitDTO()
            {
                Name   = "House",
                Adress = "Moscow 1"
            };

            var unitStore = new UnitDTO()
            {
                Name   = "Store",
                Adress = "Novgorod 1"
            };

            context.UnitDTOs.Add(unitHouse);
            context.UnitDTOs.Add(unitStore);
            context.LinkObjectsDTOs.Add(new LinkObjectsDTO()
            {
                Owner     = fistAgreement,
                Childen   = unitHouse,
                BeginDate = new DateTime(2018, 1, 1),
                EndDate   = new DateTime(2079, 1, 1),
                Factore   = 1.0,
            });
            context.LinkObjectsDTOs.Add(new LinkObjectsDTO()
            {
                Owner     = fistAgreement,
                Childen   = unitStore,
                BeginDate = new DateTime(2018, 1, 1),
                EndDate   = new DateTime(2079, 1, 1),
                Factore   = 0.5
            });

            var tariffGroupHouse = new TariffGroupDTO()
            {
                Name   = "Base Tariff House",
                Tariff = baseTariff
            };
            var tariffGroupStore = new TariffGroupDTO()
            {
                Name   = "Base Tariff Store",
                Tariff = baseTariff
            };

            context.TariffGroupDTOs.Add(tariffGroupHouse);
            context.TariffGroupDTOs.Add(tariffGroupStore);
            context.LinkObjectsDTOs.Add(new LinkObjectsDTO()
            {
                Owner     = unitHouse,
                Childen   = tariffGroupHouse,
                BeginDate = new DateTime(2018, 1, 1),
                EndDate   = new DateTime(2079, 1, 1),
                Factore   = 1.0
            });
            context.LinkObjectsDTOs.Add(new LinkObjectsDTO()
            {
                Owner     = unitStore,
                Childen   = tariffGroupStore,
                BeginDate = new DateTime(2018, 1, 1),
                EndDate   = new DateTime(2079, 1, 1),
                Factore   = 1.0
            });

            var channelHouse = new ChannelDTO()
            {
                Name           = "Base Channel",
                VoltageLevelId = 0
            };

            context.ChannelDTOs.Add(channelHouse);
            context.LinkObjectsDTOs.Add(new LinkObjectsDTO()
            {
                Owner     = tariffGroupHouse,
                Childen   = channelHouse,
                BeginDate = new DateTime(2018, 1, 1),
                EndDate   = new DateTime(2079, 1, 1),
                Factore   = 1.0
            });

            var consFlowStore = new ConstantFlowDTO()
            {
                Name           = "Signal system",
                VoltageLevelId = 0,
                Сonsumption    = 10.0
            };

            context.ConstantFlowDTOs.Add(consFlowStore);
            context.LinkObjectsDTOs.Add(new LinkObjectsDTO()
            {
                Owner     = tariffGroupStore,
                Childen   = consFlowStore,
                BeginDate = new DateTime(2018, 1, 1),
                EndDate   = new DateTime(2079, 1, 1),
                Factore   = 1.0
            });

            var meterHouse = new MeterDTO()
            {
                Name         = "ground flow",
                CountScale   = 6,
                PublicNumber = "34785",
                SerialNumber = "2016-04-23-02-2349"
            };

            context.MeterDTOs.Add(meterHouse);
            context.LinkObjectsDTOs.Add(new LinkObjectsDTO()
            {
                Owner     = channelHouse,
                Childen   = meterHouse,
                BeginDate = new DateTime(2018, 1, 1),
                EndDate   = new DateTime(2079, 1, 1),
                Factore   = 1.0
            });

            var scaleHouse = new MeterScaleDTO()
            {
                Name        = "All day",
                Dimension   = 6,
                ZoneOfDayId = 0
            };

            context.MeterScaleDTOs.Add(scaleHouse);
            context.LinkObjectsDTOs.Add(new LinkObjectsDTO()
            {
                Owner     = meterHouse,
                Childen   = scaleHouse,
                BeginDate = new DateTime(2018, 1, 1),
                EndDate   = new DateTime(2079, 1, 1),
                Factore   = 1.0
            });

            context.IndicationDocumentDTOs.Add(new Models.Documents.IndicationDocumentDTO()
            {
                CreateDate  = new DateTime(2018, 1, 1),
                ReceiptDate = new DateTime(2018, 1, 1),
                Meter       = meterHouse,
                Scale       = scaleHouse,
                Indication  = 1012
            });

            context.IndicationDocumentDTOs.Add(new Models.Documents.IndicationDocumentDTO()
            {
                CreateDate  = new DateTime(2018, 2, 1),
                ReceiptDate = new DateTime(2018, 2, 1),
                Meter       = meterHouse,
                Scale       = scaleHouse,
                Indication  = 1057
            });

            context.IndicationDocumentDTOs.Add(new Models.Documents.IndicationDocumentDTO()
            {
                CreateDate  = new DateTime(2018, 3, 1),
                ReceiptDate = new DateTime(2018, 3, 1),
                Meter       = meterHouse,
                Scale       = scaleHouse,
                Indication  = 1135
            });

            context.IndicationDocumentDTOs.Add(new Models.Documents.IndicationDocumentDTO()
            {
                CreateDate  = new DateTime(2018, 4, 1),
                ReceiptDate = new DateTime(2018, 4, 1),
                Meter       = meterHouse,
                Scale       = scaleHouse,
                Indication  = 1208
            });
        }