Пример #1
0
        public async Task <ValidationResult> UpdateAsync(int id, Picker picker, IEnumerable <PickerTopic> topics)
        {
            if (id <= 0)
            {
                return(new ValidationResult(false, new ValidationError("The activity is invalid")));
            }

            picker.SetId(id);

            if (!picker.IsValid())
            {
                return(new ValidationResult(false, picker.ValidationErrors));
            }

            if (!picker.AddTopics(topics))
            {
                return(new ValidationResult(false, picker.ValidationErrors));
            }

            var pickerWasUpdated = await _pickerRepository.UpdateAsync(picker);

            if (!pickerWasUpdated)
            {
                return(new ValidationResult(false, new ValidationError("The activity wasn't found")));
            }

            return(new ValidationResult(true));
        }
Пример #2
0
        public async Task <ValidationResult> CreateAsync(Picker picker, IEnumerable <PickerTopic> topics)
        {
            if (!picker.IsValid())
            {
                return(new ValidationResult(false, picker.ValidationErrors));
            }

            if (!picker.AddTopics(topics))
            {
                return(new ValidationResult(false, picker.ValidationErrors));
            }

            var createdPickerId = await _pickerRepository.CreateAsync(picker);

            if (createdPickerId <= 0)
            {
                return(new ValidationResult(false, new ValidationError("There was an error while creating the activity")));
            }

            return(new ValidationResult(true));
        }