예제 #1
0
        public async Task <SmartHomeValidationResult> CreateAsync(long sensorId, double voltage, DateTime measurementDateTime)
        {
            if (!(await sensorRepository.AnyWithBatteryPowerSourceAsync(sensorId)))
            {
                return(SmartHomeValidationResult.Failed(new SmartHomeValidation(
                                                            nameof(sensorId), $"There is no sensor with id {sensorId} with battery power source.")));
            }

            await batteryMeasurementRepository.AddAsync(sensorId, voltage, measurementDateTime);

            return(SmartHomeValidationResult.Success);
        }
예제 #2
0
        private SmartHomeValidationResult Validate(ChangePasswordModel model)
        {
            var errors = new List <SmartHomeValidation>();

            if (string.Equals(model.OldPassword, model.NewPassword))
            {
                errors.Add(new SmartHomeValidation(nameof(model.NewPassword),
                                                   "Old password cannot be same as the new password."));
            }

            return(SmartHomeValidationResult.Failed(errors));
        }
예제 #3
0
        public async Task <ServiceResult <long> > CreateAsync(PermissionModel model)
        {
            if (model.Id > 0)
            {
                throw new ArgumentException(nameof(model.Id), "Invalid model Id.");
            }

            if (await repository.GetByNameAsync(model.Name !) != null)
            {
                var errors = SmartHomeValidationResult.Failed(
                    new SmartHomeValidation(nameof(model.Name),
                                            $"Permission named {model.Name} already exists in the database."));

                return(new ServiceResult <long>(default, errors));
예제 #4
0
        private async Task <SmartHomeValidationResult> ValidateAsync(CreateUserModel model)
        {
            var identityErrors = new List <SmartHomeValidation>();

            if (await repository.GetUserByNameAsync(model.UserName !) != null)
            {
                identityErrors.Add(new SmartHomeValidation(nameof(model.UserName),
                                                           $"User with name {model.UserName} already exists."));
            }

            if (await repository.GetUserByEmailAsync(model.Email !) != null)
            {
                identityErrors.Add(new SmartHomeValidation(nameof(model.Email),
                                                           $"User with email {model.Email} already exists."));
            }

            return(SmartHomeValidationResult.Failed(identityErrors));
        }