Ejemplo n.º 1
0
        public void Update(List <InspectionViewModel> newInspection)
        {
            var inspections    = _inspectionRepository.GetAll().Where(x => x.ObjectI.Equals(newInspection[0].ObjectI));
            var maxLicenseCode = 0;

            if (inspections.Any())
            {
                maxLicenseCode = Convert.ToInt32(inspections.Max(x => x.InspectionC));
            }
            //xoa
            foreach (var inspection in inspections)
            {
                if (newInspection.Any(item => item.InspectionC == inspection.InspectionC && item.ObjectI == inspection.ObjectI) == false)
                {
                    _inspectionRepository.Delete(inspection);
                }
            }
            //update
            foreach (var item in newInspection)
            {
                if (item.InspectionC == -1)
                {
                    continue;
                }

                if (item.InspectionC == 0)
                {
                    var addItem = new Inspection_M()
                    {
                        DisplayLineNo = item.DisplayLineNo,
                        InspectionC   = ++maxLicenseCode,
                        InspectionN   = item.InspectionN,
                        NoticeNo      = item.NoticeNo,
                        ObjectI       = item.ObjectI
                    };
                    _inspectionRepository.Add(addItem);
                }
                else
                {
                    var updateInspection = inspections.FirstOrDefault(x => x.InspectionC == item.InspectionC && x.ObjectI == item.ObjectI);
                    if (updateInspection != null)
                    {
                        updateInspection.DisplayLineNo = item.DisplayLineNo;
                        updateInspection.InspectionN   = item.InspectionN;
                        updateInspection.NoticeNo      = item.NoticeNo;
                        _inspectionRepository.Update(updateInspection);
                    }
                }
            }
            SaveInspection();
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Put(Inspection inspection)
        {
            try
            {
                var response = await _repository.Update(inspection);

                if (response != 0)
                {
                    return(Ok("Updated successfully"));
                }
                else
                {
                    return(BadRequest("An error ocurred, contact IT Staff"));
                }
            }catch (Exception e)
            {
                //Log error
                Log.Error(e.Message);
                Log.Error(e.StackTrace);
                return(BadRequest("An error ocurred, contact IT Staff"));
            }
        }
Ejemplo n.º 3
0
        private void Save()
        {
            var iiList = new List <InspectionInspector>();

            foreach (var e in SelectedInspectors)
            {
                var ii = new InspectionInspector
                {
                    Employee    = _userRepository.Find(e.ID),
                    Inspection  = _inspectionRepository.Find(_inspection.ID),
                    LastUpdated = DateTime.Now
                };
                e.InspectionInspectors.Add(ii);
                _userRepository.Update(e);
                iiList.Add(ii);
            }
            _inspection.InspectionInspectors = iiList;

            _inspectionRepository.Update(_inspection);

            MessageBox.Show("De wijzigingen zijn opgeslagen!");
            _router.GoBack();
        }
        private void SaveAnswers()
        {
            var invalid = ControlList.FirstOrDefault(control => !control.IsValid);

            if (invalid != null)
            {
                MessageBox.Show($"De vraag \"{invalid.Question.Text}\" is niet geldig ingevuld!", "Fout", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            ControlList.ToList().ForEach(x =>
            {
                var answer        = x.GetAnswer();
                answer.Inspection = _inspection;
                answer.Employee   = Settings.CurrentUser;

                if (answer.Photo != null)
                {
                    answer.Photo.Inspection = _inspection;
                }

                _inspection.DateTimeDone = DateTime.Now;

                _inspection.Answers.Add(answer);
                x.Question.Answers.Add(answer);
            });

            if (!_inspectionRepository.Update(_inspection))
            {
                MessageBox.Show("Er ging iets fout, probeer het opnieuw!");
                return;
            }

            MessageBox.Show("De inspectie is opgeslagen.");
            _router.GoBack();
        }