Beispiel #1
0
        public async Task <ComplaintCode> UpdateComplaintCodeByIDAsync(
            Guid Id, ComplaintCode complaintCodeForm, CancellationToken ct)
        {
            ComplaintCodeEntity entity = await _dbContext.ComplaintCodes.SingleOrDefaultAsync(i => i.Id == Id, ct);

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

            // Return if provided name is not valid
            if (entity.GroupCode != complaintCodeForm.GroupCode || entity.Code != complaintCodeForm.Code)
            {
                return(null);
            }

            entity = Mapper.Map <ComplaintCodeEntity>(complaintCodeForm);
            _dbContext.ComplaintCodes.Update(entity);
            var updated = await _dbContext.SaveChangesAsync(ct);

            if (updated < 1)
            {
                throw new InvalidOperationException("Something went wrong and could not update the provided complaint code.");
            }
            return(Mapper.Map <ComplaintCode>(entity));
        }
Beispiel #2
0
        public async Task <ComplaintCode> GetComplaintCodeByCodeAsync(string code, CancellationToken ct)
        {
            ComplaintCodeEntity entity = await _dbContext.ComplaintCodes.SingleOrDefaultAsync(c => c.Code.Equals(code), ct);

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

            return(Mapper.Map <ComplaintCode>(entity));
        }
Beispiel #3
0
        public async Task <Guid> CreateComplaintCodeAsync(ComplaintCode complaintCodeForm, CancellationToken ct)
        {
            var id = Guid.NewGuid();

            ComplaintCodeEntity entity = Mapper.Map <ComplaintCodeEntity>(complaintCodeForm);

            entity.Id = id;

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

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

            return(id);
        }