Пример #1
0
        public FarmDto GetFarmById(int id)
        {
            var farm = _farmRepository.FindById(id);

            if (farm == null)
            {
                throw new Exception("Farm was not found");
            }

            return(Mapper.Map <Farm, FarmDto>(farm));
        }
        public void Update(int id, UpdateShareDto dto)
        {
            var share = _shareRepository.FindById(id);

            if (share == null)
            {
                throw new Exception("Share was not found");
            }

            if (dto.SerialNum != null)
            {
                share.SerialNum = dto.SerialNum;
            }

            if (dto.Percent != 0)
            {
                share.Percent = dto.Percent;
            }

            if (dto.Price != 0)
            {
                share.Price = dto.Price;
            }

            if (dto.TurbineId != 0 && share.Turbine != null && dto.TurbineId != share.Turbine.Id)
            {
                var turbine = _turbineRepository.FindById(dto.TurbineId);

                if (turbine != null)
                {
                    share.Turbine = turbine;
                }
            }

            if (dto.FarmId != 0 && share.Farm != null && dto.FarmId != share.Farm.Id)
            {
                var farm = _farmRepository.FindById(dto.TurbineId);

                if (farm != null)
                {
                    share.Farm = farm;
                }
            }

            if (dto.ShareHolderId != share.ShareHolder.Id)
            {
                var shareHolder = _shareHolderRepository.FindById(dto.ShareHolderId);

                if (shareHolder != null)
                {
                    share.ShareHolder = shareHolder;
                }
            }

            _shareRepository.Update(share);
        }
        public void Update(int id, UpdateTurbineDto dto)
        {
            var turbine = _turbineRepository.FindById(id);

            if (turbine == null)
            {
                throw new Exception("Turbine was not found");
            }

            if (dto.SerialNum != null)
            {
                turbine.SerialNum = dto.SerialNum;
            }

            if (dto.ProdMW > 0)
            {
                turbine.ProdMW = dto.ProdMW;
            }

            if (dto.Cost > 0)
            {
                turbine.Cost = dto.Cost;
            }

            if (dto.InstallCost > 0)
            {
                turbine.InstallCost = dto.InstallCost;
            }

            if (dto.InstallDate != DateTime.MinValue)
            {
                turbine.InstallDate = dto.InstallDate;
            }

            if (dto.LastServDate != DateTime.MinValue)
            {
                turbine.LastServDate = dto.LastServDate;
            }

            if (dto.NextServDate != DateTime.MinValue)
            {
                turbine.NextServDate = dto.NextServDate;
            }

            if (dto.LastYearServDate != DateTime.MinValue)
            {
                turbine.LastYearServDate = dto.LastYearServDate;
            }

            if (dto.NextYearServDate != DateTime.MinValue)
            {
                turbine.NextYearServDate = dto.NextYearServDate;
            }

            if (dto.TurbineTypeId != turbine.TurbineType.Id)
            {
                var turbineType = _turbineTypeRepository.FindById(dto.TurbineTypeId);

                if (turbineType != null)
                {
                    turbine.TurbineType = turbineType;
                }
            }

            if (dto.OperatorId != turbine.Operator.Id)
            {
                var operatorDbItem = _operatorRepository.FindById(dto.OperatorId);

                if (operatorDbItem != null)
                {
                    turbine.Operator = operatorDbItem;
                }
            }

            if (turbine.Farm != null && dto.FarmId != turbine.Farm.Id)
            {
                var farm = _farmRepository.FindById(dto.FarmId);

                if (farm != null)
                {
                    turbine.Farm = farm;
                }
            }

            if (dto.AddressId != turbine.Address.Id)
            {
                var address = _addressRepository.FindById(dto.AddressId);

                if (address != null)
                {
                    turbine.Address = address;
                }
            }

            if (turbine.Image != null && dto.ImageId != turbine.Image.Id)
            {
                var image = _appImageRepository.FindById(dto.ImageId);

                if (image != null)
                {
                    turbine.Image = image;
                }
            }

            _turbineRepository.Update(turbine);
        }