private async Task <DomainDb> CreateDomainDbAsync(DomainDb domain) { context.Domains.Add(domain); await context.SaveChangesAsync().ConfigureAwait(false); return(context.Domains.FirstOrDefault(x => x.DomainURL == domain.DomainURL)); }
public async Task <Result <DomainDb> > DeleteAsync(DomainDb domainDb) { try { context.Domains.Remove(domainDb); await context.SaveChangesAsync().ConfigureAwait(false); return(Result <DomainDb> .Ok(domainDb)); } catch (DbUpdateConcurrencyException e) { return(Result <DomainDb> .Fail <DomainDb>($"Domain not deleted. {e.Message}")); } catch (DbEntityValidationException e) { return(Result <DomainDb> .Fail <DomainDb>($"Invalid domain. {e.Message}")); } }
public async Task <Result <DomainDb> > UpdateAsync(DomainDb domainDb) { try { if (domainDb == null) { throw new ArgumentNullException("domain"); } context.Entry(domainDb).State = EntityState.Modified; await context.SaveChangesAsync().ConfigureAwait(false); return(Result <CourseDb> .Ok(domainDb)); } catch (DbUpdateConcurrencyException e) { return((Result <DomainDb>) Result <DomainDb> .Fail <DomainDb>($"Cannot save domain. {e.Message}")); } catch (DbEntityValidationException e) { return((Result <DomainDb>) Result <DomainDb> .Fail <DomainDb>($"Invalid domain. {e.Message}")); } }
public async Task <Result <DomainDb> > AddAsync(DomainDb domain) { try { context.Domains.Add(domain); await context.SaveChangesAsync().ConfigureAwait(false); return(Result <DomainDb> .Ok(domain)); } catch (DbUpdateConcurrencyException e) { return((Result <DomainDb>) Result <DomainDb> .Fail <DomainDb>($"Cannot save domain. {e.Message}")); } catch (DbUpdateException e) { return((Result <DomainDb>) Result <DomainDb> .Fail <DomainDb>($"Cannot save domain. Duplicate field. {e.Message}")); } catch (DbEntityValidationException e) { return((Result <DomainDb>) Result <DomainDb> .Fail <DomainDb>($"Invalid domain. {e.Message}")); } }