示例#1
0
        public async Task <ProblemSolvingType> UpdateProblemSolvingTypeAsync(
            Guid Id, ProblemSolvingType problemSolvingTypeForm, CancellationToken ct)
        {
            ProblemSolvingTypeEntity entity = await _dbContext.ProblemSolvingTypes.SingleOrDefaultAsync(i => i.Id == Id, ct);

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

            // Return if provided name is not valid
            if (!entity.Tag.Equals(problemSolvingTypeForm.Tag, StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }

            entity = Mapper.Map <ProblemSolvingTypeEntity>(problemSolvingTypeForm);
            _dbContext.ProblemSolvingTypes.Update(entity);
            var updated = await _dbContext.SaveChangesAsync(ct);

            if (updated < 1)
            {
                throw new InvalidOperationException("Could not update the problem solving type (8d type)");
            }
            return(Mapper.Map <ProblemSolvingType>(entity));
        }
示例#2
0
        public async Task <Guid> CreateProblemSolvingTypeAsync(ProblemSolvingType problemSolvingTypeForm, CancellationToken ct)
        {
            var id = Guid.NewGuid();

            ProblemSolvingTypeEntity entity = Mapper.Map <ProblemSolvingTypeEntity>(problemSolvingTypeForm);

            entity.Id = id;

            var newObj  = _dbContext.ProblemSolvingTypes.Add(entity);
            var created = await _dbContext.SaveChangesAsync(ct);

            if (created < 1)
            {
                throw new InvalidOperationException("Could not create the requested object");
            }

            return(id);
        }