Ejemplo n.º 1
0
        public (bool Success, string Message) ValidateAndSaveClash(Clash clash, UpdateClashModel model, bool applyGlobally)
        {
            if (clash is null)
            {
                throw new ArgumentException("Clash, which is being updated, cannot be null", nameof(clash));
            }

            if (applyGlobally)
            {
                clash.Differences = new List <ClashDifference>(0);
            }

            var clashToValidate = (Clash)clash.Clone();

            clashToValidate = UpdateClash(clashToValidate, model, applyGlobally);

            var allClashes = _clashRepository.GetAll();

            var validationResult = ValidateClashDifferencesForSave(clashToValidate, allClashes);

            if (!validationResult.Successful)
            {
                return(Failure(validationResult.Message));
            }

            clash = UpdateClash(clash, model, applyGlobally);;

            // validate clash new values
            //Removing current clash from all clashes while validate
            Validation(new List <Clash> {
                clash
            }, allClashes?.Where(c => c.Uid != clash.Uid).ToList());

            _clashRepository.Add(clash);
            _clashRepository.SaveChanges();

            return(Success());
        }