示例#1
0
        private Clash UpdateClash(Clash clash, UpdateClashModel model, bool applyGlobally)
        {
            clash.Description = model.Description;
            clash.ParentExternalidentifier    = model.ParentExternalidentifier;
            clash.DefaultPeakExposureCount    = model.DefaultPeakExposureCount;
            clash.DefaultOffPeakExposureCount = model.DefaultOffPeakExposureCount;

            if (!applyGlobally)
            {
                clash.Differences = model.Differences;
            }

            return(clash);
        }
示例#2
0
        public IHttpActionResult Put(Guid id, [FromBody] UpdateClashModel command, bool applyGlobally = false)
        {
            if (!ModelState.IsValid || id == default || command == null)
            {
                return(this.Error().InvalidParameters());
            }

            var clash = _clashRepository.Get(id);

            if (clash == null)
            {
                return(NotFound());
            }

            var updateResult = ValidateAndSaveClash(clash, command, applyGlobally);

            return(updateResult.Success
                ? Ok(clash)
                : this.Error().BadRequest(updateResult.Message));
        }
示例#3
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());
        }