Esempio n. 1
0
        public long Update(DispatchModel model)
        {
            TblDispatch obj = _mapper.Map <DispatchModel, TblDispatch>(model);
            List <TblDispatchDetail> dispatchDetailModel = _repositoryDetail.GetAll().Where(m => m.DispatchId == obj.DispatchId).ToList();

            List <long> originalSlittingId = dispatchDetailModel.Select(m => m.SlittingId).ToList();
            List <long> currentSlitingId   = model.checkedSlittingId.Split(',').Select(long.Parse).ToList();
            List <long> deleteSlittingId   = originalSlittingId.Except(currentSlitingId).ToList();
            List <long> insertSlittingId   = currentSlitingId.Except(originalSlittingId).ToList();

            foreach (long deleteId in deleteSlittingId)
            {
                TblDispatchDetail objModel = dispatchDetailModel.FirstOrDefault(m => m.SlittingId == deleteId);
                if (objModel != null)
                {
                    _repositoryDetail.Delete(objModel.DispatchDetailId);
                }
            }

            foreach (long insertingId in insertSlittingId)
            {
                TblDispatchDetail objInsertModel = new TblDispatchDetail
                {
                    DispatchId = obj.DispatchId,
                    SlittingId = insertingId
                };
                _repositoryDetail.Insert(objInsertModel);
            }
            _repository.Update(obj);
            return(obj.DispatchId);
        }
Esempio n. 2
0
        public long Insert(DispatchModel model)
        {
            TblDispatch obj = _mapper.Map <DispatchModel, TblDispatch>(model);

            obj.IsInvoiceGenerated = false;
            obj.IsFinalize         = false;
            obj.Day        = model.DispatchDate.Day;
            obj.Month      = model.DispatchDate.Month;
            obj.Year       = model.DispatchDate.Year;
            obj.DispatchNo = "";
            obj.SequenceNo = 0;

            List <long> slittingIdList = model.checkedSlittingId.Split(',').Select(long.Parse).ToList();

            foreach (long slittingId in slittingIdList)
            {
                obj.TblDispatchDetail.Add(new TblDispatchDetail
                {
                    SlittingId = slittingId
                });
            }

            _repository.Insert(obj);
            return(obj.DispatchId);
        }
Esempio n. 3
0
        public DispatchModel GetById(long id)
        {
            TblDispatch obj = _repository.GetById(id);

            return(obj == null ? new DispatchModel() : Map(obj));
        }
Esempio n. 4
0
 private DispatchModel Map(TblDispatch unit)
 {
     return(_mapper.Map <DispatchModel>(unit));
 }