public bool Update(SaleBillViewModel entity)
        {
            var saleBill           = entity.MapToSaleBill();
            var newSaleBillDetails = new List <SaleBillDetail>();

            foreach (var item in entity.SaleBillDetailViewModels)
            {
                var purchaseBillDetail = item.MapToSaleBillDetail();
                purchaseBillDetail.SaleBillId = saleBill.SaleBillId;
                newSaleBillDetails.Add(purchaseBillDetail);
            }
            _saleBillRepository.Update(saleBill);
            var oldSaleBillDetails = _saleBillDetailRepository.FindAll(pd => pd.SaleBillId == entity.SaleBillId);

            if (oldSaleBillDetails != null)
            {
                var deleteSaleBillDetails = oldSaleBillDetails.Where(op => !newSaleBillDetails.Any(p => p.Id == op.Id));
                var addSaleBillDetails    = newSaleBillDetails.Where(p => !oldSaleBillDetails.Any(op => op.Id == p.Id));
                var updateSaleBillDetails = newSaleBillDetails.Where(p => oldSaleBillDetails.Any(op => op.Id == p.Id));
                _saleBillDetailRepository.DeleteRange(deleteSaleBillDetails);
                _saleBillDetailRepository.AddRange(addSaleBillDetails);
                _saleBillDetailRepository.UpdateRange(updateSaleBillDetails);
            }
            return(true);
        }
        public bool Add(SaleBillViewModel entity)
        {
            if (entity == null)
            {
                return(false);
            }
            var saleBill = entity.MapToSaleBill();

            saleBill.SaleBillId  = IdUtilities.GenerateByTimeSpan();
            saleBill.CreatedDate = DateTime.Now;
            saleBill.StaffId     = StaffGlobal.CurrentStaff.StaffId;
            _saleBillRepository.Add(saleBill);
            foreach (var item in entity.SaleBillDetailViewModels)
            {
                var saleBillDetail = item.MapToSaleBillDetail();
                saleBillDetail.SaleBillId = saleBill.SaleBillId;
                _saleBillDetailRepository.Add(saleBillDetail);
            }
            return(true);
        }