Пример #1
0
        public async Task <Subsystem> UpdateAsync(Subsystem entity)
        {
            Guard.Against <ArgumentNullException>(entity == null, nameof(entity));

            // ReSharper disable once PossibleNullReferenceException
            if (entity.Id <= 0)
            {
                ProcessMessage.Success = false;
                ProcessMessage.AddErrorMessage($"Can not update Subsystem with id {entity.Id}", true);
                return(null);
            }

            try
            {
                // make sure the record exists in data source
                DataContext.Subsystems.Update(entity);
                await DataContext.SaveAsync();

                return(LookupRepo.GetEntity <Subsystem>(entity.Id));
            }
            catch (Exception ex)
            {
                ProcessMessage.WrapException(ex);
                return(null);
            }
        }
Пример #2
0
        public HmmNote Add(HmmNote entity)
        {
            Guard.Against <ArgumentNullException>(entity == null, nameof(entity));

            try
            {
                // check if need apply default catalog
                // ReSharper disable once PossibleNullReferenceException
                var catalog = PropertyChecking(entity.Catalog);
                entity.Catalog = catalog ?? throw new Exception("Cannot find default note catalog.");

                entity.CreateDate       = DateTimeProvider.UtcNow;
                entity.LastModifiedDate = DateTimeProvider.UtcNow;
                var savedAuthor = DataContext.Authors.Find(entity.Author.Id);
                if (savedAuthor != null)
                {
                    entity.Author = savedAuthor;
                }

                var savedCat = DataContext.Catalogs.Find(entity.Catalog.Id);
                if (savedCat != null)
                {
                    entity.Catalog = savedCat;
                }
                DataContext.Notes.Add(entity);
                DataContext.Save();
                return(entity);
            }
            catch (Exception ex)
            {
                ProcessMessage.WrapException(ex);
                return(null);
            }
        }
Пример #3
0
        public Author Update(Author entity)
        {
            Guard.Against <ArgumentNullException>(entity == null, nameof(entity));

            try
            {
                // ReSharper disable once PossibleNullReferenceException
                if (entity.Id == Guid.Empty)
                {
                    ProcessMessage.Success = false;
                    ProcessMessage.AddErrorMessage($"Can not update author with id {entity.Id}");
                    return(null);
                }

                _dataContext.Authors.Update(entity);
                Flush();
                var updateAuthor = _lookupRepo.GetEntity <Author>(entity.Id);
                return(updateAuthor);
            }
            catch (DataSourceException ex)
            {
                ProcessMessage.WrapException(ex);
                return(null);
            }
        }
Пример #4
0
        public NoteRender Update(NoteRender entity)
        {
            Guard.Against <ArgumentNullException>(entity == null, nameof(entity));

            // ReSharper disable once PossibleNullReferenceException
            if (entity.Id <= 0)
            {
                ProcessMessage.Success = false;
                ProcessMessage.AddErrorMessage($"Can not update NoteRender with id {entity.Id}", true);
                return(null);
            }

            try
            {
                // make sure the record exists in data source
                DataContext.Renders.Update(entity);
                DataContext.Save();
                return(LookupRepo.GetEntity <NoteRender>(entity.Id));
            }
            catch (Exception ex)
            {
                ProcessMessage.WrapException(ex);
                return(null);
            }
        }
Пример #5
0
        public async Task <HmmNote> UpdateAsync(HmmNote entity)
        {
            Guard.Against <ArgumentNullException>(entity == null, nameof(entity));

            try
            {
                // check if need apply default catalog
                // ReSharper disable once PossibleNullReferenceException
                var catalog = PropertyChecking(entity.Catalog);
                entity.Catalog = catalog ?? throw new Exception("Cannot find default note catalog.");

                entity.LastModifiedDate = DateTimeProvider.UtcNow;
                DataContext.Notes.Update(entity);
                await DataContext.SaveAsync();

                var savedRec = LookupRepo.GetEntity <HmmNote>(entity.Id);

                return(savedRec);
            }
            catch (Exception ex)
            {
                ProcessMessage.WrapException(ex);
                return(null);
            }
        }
Пример #6
0
        public Subsystem Add(Subsystem entity)
        {
            Guard.Against <ArgumentNullException>(entity == null, nameof(entity));

            try
            {
                // ReSharper disable once PossibleNullReferenceException
                if (entity.DefaultAuthor != null && DataContext.Authors.Any(u => u.Id == entity.DefaultAuthor.Id))
                {
                    DataContext.Authors.Attach(entity.DefaultAuthor);
                }
                foreach (var cat in entity.NoteCatalogs)
                {
                    if (DataContext.Catalogs.Any(c => c.Id == cat.Id))
                    {
                        DataContext.Catalogs.Attach(cat);
                    }

                    if (DataContext.Renders.Any(r => r.Id == cat.Render.Id))
                    {
                        DataContext.Renders.Attach(cat.Render);
                    }
                }
                DataContext.Subsystems.Add(entity);

                DataContext.Save();
                return(entity);
            }
            catch (Exception ex)
            {
                ProcessMessage.WrapException(ex);
                return(null);
            }
        }
Пример #7
0
        public NoteCatalog Update(NoteCatalog entity)
        {
            Guard.Against <ArgumentNullException>(entity == null, nameof(entity));

            // ReSharper disable once PossibleNullReferenceException
            if (entity.Id <= 0)
            {
                ProcessMessage.Success = false;
                ProcessMessage.AddErrorMessage($"Can not update NoteCatalog with id {entity.Id}", true);
                return(null);
            }

            try
            {
                // check if need apply default render
                var          render  = PropertyChecking(entity.Render);
                const string message = "Cannot find default note render.";
                ProcessMessage.Success = false;
                ProcessMessage.AddErrorMessage(message, true);
                entity.Render = render ?? throw new DataSourceException(message);

                DataContext.Catalogs.Update(entity);
                DataContext.Save();
                return(LookupRepo.GetEntity <NoteCatalog>(entity.Id));
            }
            catch (Exception ex)
            {
                ProcessMessage.WrapException(ex);
                return(null);
            }
        }
Пример #8
0
 public NoteRender GetEntity(int id)
 {
     try
     {
         return(DataContext.Renders.Find(id));
     }
     catch (Exception e)
     {
         ProcessMessage.WrapException(e);
         return(null);
     }
 }
Пример #9
0
 public Author GetEntity(Guid id)
 {
     try
     {
         return(_dataContext.Authors.Find(id));
     }
     catch (Exception e)
     {
         ProcessMessage.WrapException(e);
         return(null);
     }
 }
Пример #10
0
 public Subsystem GetEntity(int id)
 {
     try
     {
         return(DataContext.Subsystems.Find(id));
     }
     catch (Exception e)
     {
         ProcessMessage.WrapException(e);
         return(null);
     }
 }
Пример #11
0
        public async Task <NoteRender> GetEntityAsync(int id)
        {
            try
            {
                var render = await DataContext.Renders.FindAsync(id);

                return(render);
            }
            catch (Exception e)
            {
                ProcessMessage.WrapException(e);
                return(null);
            }
        }
Пример #12
0
        public async Task <NoteCatalog> GetEntityAsync(int id)
        {
            try
            {
                var catalog = await DataContext.Catalogs.FindAsync(id);

                return(catalog);
            }
            catch (Exception e)
            {
                ProcessMessage.WrapException(e);
                return(null);
            }
        }
Пример #13
0
        public async Task <HmmNote> GetEntityAsync(int id)
        {
            try
            {
                var note = await DataContext.Notes.FindAsync(id);

                return(note);
            }
            catch (Exception e)
            {
                ProcessMessage.WrapException(e);
                return(null);
            }
        }
Пример #14
0
        public async Task <Author> GetEntityAsync(Guid id)
        {
            try
            {
                var author = await _dataContext.Authors.FindAsync(id);

                return(author);
            }
            catch (Exception e)
            {
                ProcessMessage.WrapException(e);
                return(null);
            }
        }
Пример #15
0
        public async Task <Subsystem> GetEntityAsync(int id)
        {
            try
            {
                var system = await DataContext.Subsystems.FindAsync(id);

                return(system);
            }
            catch (Exception e)
            {
                ProcessMessage.WrapException(e);
                return(null);
            }
        }
Пример #16
0
        public NoteRender Add(NoteRender entity)
        {
            Guard.Against <ArgumentNullException>(entity == null, nameof(entity));

            try
            {
                // ReSharper disable once AssignNullToNotNullAttribute
                DataContext.Renders.Add(entity);
                DataContext.Save();
                return(entity);
            }
            catch (Exception ex)
            {
                ProcessMessage.WrapException(ex);
                return(null);
            }
        }
Пример #17
0
        public bool Delete(NoteCatalog entity)
        {
            Guard.Against <ArgumentNullException>(entity == null, nameof(entity));

            try
            {
                // ReSharper disable once AssignNullToNotNullAttribute
                DataContext.Catalogs.Remove(entity);
                DataContext.Save();
                return(true);
            }
            catch (Exception ex)
            {
                ProcessMessage.WrapException(ex);
                return(false);
            }
        }
Пример #18
0
        public Author Add(Author entity)
        {
            Guard.Against <ArgumentNullException>(entity == null, nameof(entity));

            try
            {
                // ReSharper disable once AssignNullToNotNullAttribute
                _dataContext.Authors.Add(entity);
                Flush();
                return(entity);
            }
            catch (DataSourceException ex)
            {
                ProcessMessage.WrapException(ex);
                return(null);
            }
        }
Пример #19
0
        public async Task <bool> DeleteAsync(NoteRender entity)
        {
            Guard.Against <ArgumentNullException>(entity == null, nameof(entity));

            try
            {
                // ReSharper disable once AssignNullToNotNullAttribute
                DataContext.Renders.Remove(entity);
                await DataContext.SaveAsync();

                return(true);
            }
            catch (Exception ex)
            {
                ProcessMessage.WrapException(ex);
                return(false);
            }
        }
Пример #20
0
        public async Task <NoteCatalog> AddAsync(NoteCatalog entity)
        {
            Guard.Against <ArgumentNullException>(entity == null, nameof(entity));

            try
            {
                // ReSharper disable once AssignNullToNotNullAttribute
                DataContext.Catalogs.Add(entity);
                await DataContext.SaveAsync();

                return(entity);
            }
            catch (Exception ex)
            {
                ProcessMessage.WrapException(ex);
                return(null);
            }
        }