public void Approve(EndOfShift oldEntity)
        {
            var entity = _endOfShiftRepository.GetById(oldEntity.EndOfShiftId);

            if (entity == null)
            {
                return;
            }
            entity.IsApproved = true;
            _endOfShiftRepository.Update(entity);
            DateTime fromDatetime = new DateTime(entity.CreatedDate.Year, entity.CreatedDate.Month, entity.CreatedDate.Day, entity.From, 0, 0);
            DateTime toDatetime   = new DateTime(entity.CreatedDate.Year, entity.CreatedDate.Month, entity.CreatedDate.Day, entity.To, 0, 0);

            var listSaleBill = _saleBillRepository.GetAll().Where(s => !s.IsAprroved &&
                                                                  s.CreatedDate >= fromDatetime && s.CreatedDate <= toDatetime).ToList();

            //foreach (var item in listSaleBill)
            //{
            //    item.IsAprroved = true;
            //    _saleBillRepository.Update(item);
            //}

            for (int i = 0; i < listSaleBill.Count(); i++)
            {
                listSaleBill[i].IsAprroved = true;
                _saleBillRepository.Update(listSaleBill[i]);
            }
        }
        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);
        }