예제 #1
0
        public async Task <Result> InsertLicenseCategory(LicenseCategory model)
        {
            var validator = new LicenseCategoryValidator(true);
            var result    = validator.Validate(model).GetResult();

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

            var entity = MapLicenseCategoryModelToEntity(model);
            await _context.LicenseCategory.AddAsync(entity);

            await _context.SaveChangesAsync();

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

            return(result);
        }
예제 #2
0
        public async Task <Result> UpdateLicenseCategory(LicenseCategory model)
        {
            var validator = new LicenseCategoryValidator(false);
            var result    = validator.Validate(model).GetResult();

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

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

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

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

            return(result);
        }