예제 #1
0
        public virtual List <string> Create(List <T> entities)
        {
            using (new TimeMonitor(GetPrefix(entities.Select(o => o.Id).ToList())))
            {
                try
                {
                    foreach (var entity in entities)
                    {
                        entity.Created = DateTime.Now;
                        if (this.GetContext() != null)
                        {
                            entity.CreatedBy = this.GetContext().UserId;
                        }
                    }

                    var ids = collection.AddEntitiesAsync(entities).Result;

                    if (!entities.IsEmpty() && string.IsNullOrEmpty(entities[0].Id))
                    {
                        for (int i = 0; i < entities.Count; i++)
                        {
                            entities[i].Id = ids[i];
                        }
                    }

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

                    LogInformation("Create", string.Join(",", ids));

                    return(ids);
                }
                catch (Exception ex)
                {
                    LogException(ex);
                    return(new List <string>());
                }
            }
        }
예제 #2
0
파일: BaseService.cs 프로젝트: wiiee/core
        public virtual List <string> Create(List <T> entities)
        {
            using (new TimeMonitor(GetPrefix(entities.Select(o => o.Id).ToList())))
            {
                try
                {
                    foreach (var entity in entities)
                    {
                        if (typeof(T) != typeof(HistoryService))
                        {
                            ProcessHistory(HistoryType.Create, entity.Id, JsonConvert.SerializeObject(entity), this.GetContext().UserId);
                        }
                    }

                    var ids = collection.AddEntitiesAsync(entities).Result;

                    if (!entities.IsEmpty() && string.IsNullOrEmpty(entities[0].Id))
                    {
                        for (int i = 0; i < entities.Count; i++)
                        {
                            entities[i].Id = ids[i];
                        }
                    }

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

                    LogInformation("Create", string.Join(",", ids));

                    return(ids);
                }
                catch (Exception ex)
                {
                    LogException(ex);
                    return(new List <string>());
                }
            }
        }