public async Task <int> Create(SeverityRule model) { var severityRuleDto = model.ToDomainModel(); var generalRuleId = severityRuleDto.GeneralRuleId; if (!DoesGeneralRuleExists(generalRuleId)) { if (model.GeneralRule == null) { throw new ArgumentException(); } generalRuleId = await _generalRuleRepository.Create(model.GeneralRule); } severityRuleDto.GeneralRuleId = generalRuleId; var entity = await _db.SeverityLevelRule.AddAsync(severityRuleDto); await _db.SaveChangesAsync(); entity.State = EntityState.Detached; return(entity.Entity.SeverityLevelRuleId); }
public async Task <bool> Update(SeverityRule model) { try { var dto = model.ToDomainModel(); if (model.GeneralRule != null) { await _generalRuleRepository.Update(model.GeneralRule); } _db.SeverityLevelRule.Update(dto); await _db.SaveChangesAsync(); return(true); } catch { return(false); } }