Ejemplo n.º 1
0
        public async Task <Result> InsertAdviceScope(AdviceScope model)
        {
            var validator = new AdviceScopeValidator(true);
            var result    = validator.Validate(model).GetResult();

            if (!result.Success)
            {
                return(result);
            }

            var entity = MapAdviceScopeModelToEntity(model);
            await _context.AdviceScope.AddAsync(entity);

            await _context.SaveChangesAsync();

            model.Id   = entity.Id;
            result.Tag = model;

            return(result);
        }
Ejemplo n.º 2
0
        public async Task <Result> UpdateAdviceScope(AdviceScope model)
        {
            var validator = new AdviceScopeValidator(false);
            var result    = validator.Validate(model).GetResult();

            if (!result.Success)
            {
                return(result);
            }

            var entity = await _context.AdviceScope.FindAsync(model.Id);

            if (entity == null)
            {
                return(new Result());
            }

            entity = MapAdviceScopeModelToEntity(model, entity);
            await _context.SaveChangesAsync();

            return(result);
        }