コード例 #1
0
        public virtual string Create(T entity)
        {
            using (new TimeMonitor(entity.Id))
            {
                try
                {
                    entity.Created = DateTime.Now;
                    if (this.GetContext() != null)
                    {
                        entity.CreatedBy = this.GetContext().UserId;
                    }

                    var id = collection.AddEntityAsync(entity).Result;

                    entity.Id = id;

                    if (IsCacheReady())
                    {
                        cache.Set(entity);
                    }

                    LogInformation("Create", entity.Id);

                    return(id);
                }
                catch (Exception ex)
                {
                    LogException(ex);
                    return(string.Empty);
                }
            }
        }
コード例 #2
0
ファイル: BaseService.cs プロジェクト: wiiee/core
        public virtual string Create(T entity)
        {
            using (new TimeMonitor(entity.Id))
            {
                try
                {
                    if (typeof(T) != typeof(History))
                    {
                        ProcessHistory(HistoryType.Create, entity.Id, JsonConvert.SerializeObject(entity), this.GetContext().UserId);
                    }

                    var id = collection.AddEntityAsync(entity).Result;

                    entity.Id = id;

                    if (this.GetContext().IsUseCache&& IsCacheReady())
                    {
                        cache.Set(entity);
                    }

                    LogInformation("Create", entity.Id);

                    return(id);
                }
                catch (Exception ex)
                {
                    LogException(ex);
                    return(string.Empty);
                }
            }
        }