public BranchCashDto Update(BranchCashUpdateDto dto)
        {
            BranchCashDto branchCashDto = null;

            try
            {
                _unitOfWork.CreateTransaction();

                var branchCash = _unitOfWork.GenericRepository <BranchCash>().GetById(dto.Id);
                if (branchCash != null)
                {
                    branchCash.InitialBalance = dto.InitialBalance;
                    branchCash.Total          = dto.Total;
                    branchCash.ModifiedBy     = _appSession.GetUserName();
                    if (dto.IsMainCoin == true && branchCash.IsMainCoin == false)
                    {
                        branchCash.IsMainCoin = true;

                        var otherBranchCashsWithMainCoin = _unitOfWork.GenericRepository <BranchCash>().FindBy(x => x.Id != dto.Id && x.IsMainCoin == true);

                        if (otherBranchCashsWithMainCoin.Any())
                        {
                            foreach (var otherBranchCashWithMainCoin in otherBranchCashsWithMainCoin)
                            {
                                otherBranchCashWithMainCoin.IsMainCoin = false;
                            }
                        }
                    }
                    else if (dto.IsMainCoin == false && branchCash.IsMainCoin == true)
                    {
                        branchCash.IsMainCoin = false;
                    }
                }

                _unitOfWork.GenericRepository <BranchCash>().Update(branchCash);
                _unitOfWork.Save();

                _unitOfWork.Commit();

                branchCashDto = Mapper.Map <BranchCash, BranchCashDto>(branchCash);
            }
            catch (Exception ex)
            {
                Tracing.SaveException(ex);
                _unitOfWork.Rollback();
            }
            return(branchCashDto);
        }
        public BranchCashUpdateDto GetForEdit(int id)
        {
            BranchCashUpdateDto branchCashDto = null;

            try
            {
                var branchCash = _unitOfWork.GenericRepository <BranchCash>().GetById(id);
                if (branchCash != null)
                {
                    branchCashDto = Mapper.Map <BranchCash, BranchCashUpdateDto>(branchCash);
                }
            }
            catch (Exception ex)
            {
                Tracing.SaveException(ex);
            }

            return(branchCashDto);
        }