public void ValidateUpdateModel(UpdateShareDto dto)
        {
            if (dto.TurbineId != 0 && dto.FarmId != 0)
            {
                throw new Exception(_exceptionMsgShareShouldBelongToTurbineOrFarm);
            }

            ValidatePrice(dto.Price);
        }
        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 Put(int id, [FromBody] UpdateShareDto dto)
 {
     _shareService.ValidateUpdateModel(dto);
     _shareService.Update(id, dto);
 }