Beispiel #1
0
        public async Task CreateAsync(TE entity)
        {
            if (entity.GetType().GetProperty("CreatedOn") != null)
            {
                entity.GetType().GetProperty("CreatedOn").SetValue(entity, DateTime.Now);
            }

            if (entity.GetType().GetProperty("ModifiedOn") != null)
            {
                entity.GetType().GetProperty("ModifiedOn").SetValue(entity, DateTime.Now);
            }

            if (entity.GetType().GetProperty("CreatedBy") != null)
            {
                entity.GetType().GetProperty("CreatedBy").SetValue(entity, Environment.UserName);
            }

            if (entity.GetType().GetProperty("ModifiedBy") != null)
            {
                entity.GetType().GetProperty("ModifiedBy").SetValue(entity, Environment.UserName);
            }

            if (entity.GetType().GetProperty("DeletionStateCode") != null)
            {
                entity.GetType().GetProperty("DeletionStateCode").SetValue(entity, 0);
            }

            await Entities.AddAsync(entity);
        }
Beispiel #2
0
        public virtual async Task <ApiActionResult> CreateEntityAsync(T entity, object userId)
        {
            try
            {
                if (entity == null)
                {
                    return(await ApiActionResult.FailedAsync("Entity can not be null."));
                }
                var trySetCreatedBy   = entity.TrySetPropertyValueByPropertyName("CreatedBy", userId);
                var trySetCreatedDate = entity.TrySetPropertyValueByPropertyName("CreatedDate", DateTime.Now);
                if (!trySetCreatedBy)
                {
                    //=>Log
                }
                if (!trySetCreatedDate)
                {
                    //=>Log
                }

                await Entities.AddAsync(entity);

                var result = await SaveChangesAsync();

                if (result == 1)
                {
                    return(await ApiActionResult.SuccessAsync());
                }

                return(await ApiActionResult.FailedAsync("Create Entity Error."));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public virtual async Task <TEntity> AddAsync(TEntity entity)
        {
            await Entities.AddAsync(entity);

            _context.SaveChanges();
            redisCash.Set(entity.Id.ToString(), entity);
            return(entity);
        }
Beispiel #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task <TEntity> Add(TEntity entity)
        {
            CheckContext();
            await Entities.AddAsync(entity);

            Save();
            return(entity);
        }
Beispiel #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public Task InsertAsync(TEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            return(Entities.AddAsync(entity));
        }
        public ValueTask <EntityEntry <TEntity> > InsertEntryAsync(TEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            return(Entities.AddAsync(entity));
        }
Beispiel #7
0
        public async Task InsertAsync(T entity, bool saveChanges = true)
        {
            await Entities.AddAsync(entity);

            if (saveChanges)
            {
                await DbContext.SaveChangesAsync();
            }
        }
        public virtual Task Add(T entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            return(Entities.AddAsync(entity));
        }
Beispiel #9
0
 /// <summary>
 /// Insert entity
 /// </summary
 /// <param name="entity">Entity</param>
 public virtual async Task InsertAsync(T entity)
 {
     if (entity == null)
     {
         throw new ArgumentNullException(nameof(entity));
     }
     entity.Id = Guid.NewGuid();
     await Entities.AddAsync(entity);
 }
Beispiel #10
0
        /// <summary>
        /// 新增一条记录
        /// </summary>
        /// <param name="entity">实体</param>
        /// <param name="ignoreNullValues"></param>
        /// <param name="cancellationToken">取消异步令牌</param>
        /// <returns>代理的实体</returns>
        public virtual async Task <EntityEntry <TEntity> > InsertAsync(TEntity entity, bool?ignoreNullValues = null, CancellationToken cancellationToken = default)
        {
            var entityEntry = await Entities.AddAsync(entity, cancellationToken);

            // 忽略空值
            IgnoreNullValues(ref entity, ignoreNullValues);

            return(entityEntry);
        }
Beispiel #11
0
        public async Task InsertRangeAsync(IEnumerable <TEntity> entities)
        {
            foreach (var entity in entities)
            {
                await Entities.AddAsync(entity);
            }

            await DbContext.SaveChangesAsync();
        }
        public virtual async Task InsertAsync(TEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            await Entities.AddAsync(entity);
        }
Beispiel #13
0
        /// <summary>
        /// Insert a new entity into the repository
        /// </summary>
        /// <param name="entity"></param>
        public virtual async Task InsertAsync(T entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            await Entities.AddAsync(entity);

            await _db.SaveChangesAsync();
        }
Beispiel #14
0
        public async Task InsertAsync(TEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }
            await Entities.AddAsync(entity);

            await _context.SaveChangesAsync();
        }
Beispiel #15
0
        public virtual Task <EntityEntry <TEntity> > InsertAsync(TEntity entity, CancellationToken cancellationToken = default(CancellationToken))
        {
            DbSetCheck();

            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            return(Entities.AddAsync(entity, cancellationToken));
        }
Beispiel #16
0
        public virtual async Task <TEntity> AddAsync(TEntity entity, IUserContext userContext, CancellationToken ct = default)
        {
            return(await Task.Run(async() =>
            {
                OnAdd(entity, userContext);

                await Entities.AddAsync(entity, ct).ConfigureAwait(false);

                return entity;
            }, ct));
        }
Beispiel #17
0
        /// <summary>
        ///     Insert entities
        /// </summary>
        /// <param name="entities">Entities</param>
        public virtual async Task Insert(IEnumerable <T> entities)
        {
            if (entities == null)
            {
                throw new ArgumentNullException(nameof(entities));
            }

            foreach (var entity in entities)
            {
                await Entities.AddAsync(entity);
            }

            await _context.SaveChangesAsync();
        }
Beispiel #18
0
        public virtual async Task <int> InsertAsync(TEntity entity, bool isSaveChange = true, CancellationToken cancellationToken = default)
        {
            if (entity == null)
            {
                throw new ArgumentException($"{typeof(TEntity)} is Null");
            }

            await Entities.AddAsync(entity);

            if (isSaveChange)
            {
                return(await SaveChangesAsync(cancellationToken));
            }
            return(0);
        }
Beispiel #19
0
        /// <summary>
        /// Insert Async
        /// </summary>
        /// <param name="entity">Entity</param>
        /// <returns>Result</returns>
        public virtual async Task InsertAsync(T entity)
        {
            try
            {
                if (entity == null)
                {
                    throw new ArgumentNullException(nameof(entity));
                }

                await Entities.AddAsync(entity);
            }
            catch (Exception ex)
            {
                throw new Exception(GetFullErrorText(ex), ex);
            }
        }
        private async Task CreateAsync(IBudgetInfo budgetInfo, BudgetAccountModel budgetAccountModel)
        {
            NullGuard.NotNull(budgetInfo, nameof(budgetInfo))
            .NotNull(budgetAccountModel, nameof(budgetAccountModel));

            BudgetInfoModel budgetInfoModel = ModelConverter.Convert <IBudgetInfo, BudgetInfoModel>(budgetInfo);

            budgetInfoModel.BudgetAccountIdentifier = budgetAccountModel.BudgetAccountIdentifier;
            budgetInfoModel.BudgetAccount           = budgetAccountModel;

            EntityEntry <BudgetInfoModel> budgetInfoModelEntityEntry = await Entities.AddAsync(await OnCreateAsync(budgetInfo, budgetInfoModel));

            if (budgetAccountModel.BudgetInfos.Contains(budgetInfoModelEntityEntry.Entity) == false)
            {
                budgetAccountModel.BudgetInfos.Add(budgetInfoModelEntityEntry.Entity);
            }
        }
        private async Task CreateAsync(ICreditInfo creditInfo, AccountModel accountModel)
        {
            NullGuard.NotNull(creditInfo, nameof(creditInfo))
            .NotNull(accountModel, nameof(accountModel));

            CreditInfoModel creditInfoModel = ModelConverter.Convert <ICreditInfo, CreditInfoModel>(creditInfo);

            creditInfoModel.AccountIdentifier = accountModel.AccountIdentifier;
            creditInfoModel.Account           = accountModel;

            EntityEntry <CreditInfoModel> creditInfoModelEntityEntry = await Entities.AddAsync(await OnCreateAsync(creditInfo, creditInfoModel));

            if (accountModel.CreditInfos.Contains(creditInfoModelEntityEntry.Entity) == false)
            {
                accountModel.CreditInfos.Add(creditInfoModelEntityEntry.Entity);
            }
        }
Beispiel #22
0
        public override async Task <bool> HandleAsync(TagSaveCommand command, CancellationToken token)
        {
            if (command.Id == 0)
            {
                await Entities.AddAsync(MapTo <Tag>(command), token);
            }
            else
            {
                var tag = await Entities.FirstAsync(p => p.Id == command.Id, token);

                tag.Label = command.Label;

                Entities.Update(tag);
            }

            return(await Context.SaveChangesAsync(token) == 1);
        }
Beispiel #23
0
        public virtual async Task InsertAsync(TEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            try
            {
                await Entities.AddAsync(entity);

                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException exception)
            {
                throw new Exception(await GetFullErrorTextAndRollbackEntityChangesAsync(exception), exception);
            }
        }
Beispiel #24
0
        public virtual async Task <TEntity> AddAsync(TEntity entity, IUserContext userContext, CancellationToken ct = default)
        {
            return(await Task.Run(async() =>
            {
                try
                {
                    OnAdd(entity, userContext);

                    await Entities.AddAsync(entity, ct).ConfigureAwait(false);

                    return entity;
                }
                catch (Exception ex)
                {
                    throw new ServiceException("Erro", "Ocorreu um erro ao executar o serviço", ex);
                }
            }, ct));
        }
Beispiel #25
0
        /// <summary>
        /// ثبت یک آیتم در جدول مورد نظر
        /// </summary>
        /// <param name="model">مدلی که از سمت کلاینت در حال پاس دادن آن هستیم</param>
        /// <returns></returns>
        public async Task <SweetAlertExtenstion> AddAsync(SubProjectInsertViewModel model)
        {
            try
            {
                var entity = Mapper.Map <SubProject>(model);

                #region InsertFiles

                #region Book Or Sheet
                entity.BookOrSeet = await MFile.Save(model.BookOrSeetAddress, "Uploads/BookOrSeet");

                #endregion

                #region Book Cover
                if (model.BookCoverAddress != null)
                {
                    entity.BookCover = await MFile.Save(model.BookCoverAddress, "Uploads/BookCover");
                }
                #endregion

                #endregion

                if (entity.SubProjectType == DataLayer.SSOT.ProjectTypeSSOT.Book)
                {
                    //TODO check .PDF
                    //if (Path.GetExtension(entity.BookOrSeet).ToLower() == "pdf")
                    {
                        string    filePath  = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/" + entity.BookOrSeet);
                        PdfReader pdfReader = new PdfReader(filePath);
                        entity.BookPageNumber = pdfReader.NumberOfPages;
                    }
                }

                await Entities.AddAsync(entity);

                await DbContext.SaveChangesAsync();

                return(SweetAlertExtenstion.Ok());
            }
            catch (Exception e)
            {
                return(SweetAlertExtenstion.Error());
            }
        }
        /// <summary>
        /// Asynchronously insert entity
        /// </summary>
        /// <param name="entity">Entity</param>
        public virtual async Task InsertAsync(TEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            try
            {
                await Entities.AddAsync(entity);

                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException exception)
            {
                //ensure that the detailed error text is saved in the Log
                throw new Exception(GetFullErrorTextAndRollbackEntityChanges(exception), exception);
            }
        }
Beispiel #27
0
        public async Task InsertAsync(T model)
        {
            try
            {
                if (model == null)
                {
                    throw new ArgumentNullException("model");
                }
                else
                {
                    await Entities.AddAsync(model);

                    // await _context.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public override async Task <bool> HandleAsync(NestedCommentSaveCommand command, CancellationToken token)
        {
            if (command.Id == 0 && command.CommentId > 0)
            {
                await Entities.AddAsync(MapTo <NestedComment>(command), token);
            }
            else
            {
                var comment = await Entities.FirstOrDefaultAsync(p => p.Id == command.Id && p.CreatorId == command.CreatorId, token);

                if (comment == null)
                {
                    throw new Exception("Comment not found or you do not have permission to Edit");
                }

                comment.Text = command.Text;

                Entities.Update(comment);
            }
            return(await Context.SaveChangesAsync(token) == 1);
        }
Beispiel #29
0
        public async Task <int> InsertAsync(TEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            try
            {
                await Entities.AddAsync(entity);

                return(await Context.SaveChangesAsync());
            }
            catch (DbUpdateException exception)
            {
                //TODO: add logging
                //ensure that the detailed error text is saved in the Log
                //throw new Exception(GetFullErrorTextAndRollbackEntityChanges(exception), exception);
                return(0);
            }
        }
        internal async Task <IContact> CreateOrUpdateContactSupplementAsync(IContact contact, string existingExternalIdentifier = null)
        {
            NullGuard.NotNull(contact, nameof(contact));

            ContactSupplementModel contactSupplementModel = await ReadAsync(contact, existingExternalIdentifier);

            if (contactSupplementModel == null)
            {
                contactSupplementModel = ModelConverter.Convert <IContact, ContactSupplementModel>(contact);
                await Entities.AddAsync(await OnCreateAsync(contact, contactSupplementModel));

                await DbContext.SaveChangesAsync();

                return(await ApplyContactSupplementAsync(contact));
            }

            await OnUpdateAsync(contact, contactSupplementModel);

            await DbContext.SaveChangesAsync();

            return(await ApplyContactSupplementAsync(contact));
        }