コード例 #1
0
ファイル: EmailStore.cs プロジェクト: isabella232/azure-cef
        public async Task <Group> CreateOrUpdateGroupAsync(Group group)
        {
            using (var ctx = new EmailServiceDbEntities(this.connectionString))
            {
                var entity = await ctx.Groups.SingleOrDefaultAsync(
                    s => s.EngagementAccount == group.EngagementAccount &&
                    s.Name == group.Name);

                if (entity == null)
                {
                    entity      = new GroupEntity();
                    entity.Name = group.Name;
                    entity.EngagementAccount = group.EngagementAccount;
                    entity.Description       = group.Description;
                    entity.Properties        = JsonConvert.SerializeObject(group.Properties);
                    entity.Created           = entity.Modified = DateTime.UtcNow;

                    ctx.Groups.Add(entity);
                }
                else
                {
                    entity.Description = group.Description;
                    entity.Properties  = JsonConvert.SerializeObject(group.Properties);
                    entity.Modified    = DateTime.UtcNow;
                }

                await ctx.SaveChangesAsync();

                return(entity.ToModel());
            }
        }
コード例 #2
0
        public static Group ToModel(this GroupEntity entity)
        {
            var group = new Group();

            group.EngagementAccount = entity.EngagementAccount;
            group.Name        = entity.Name;
            group.Description = entity.Description;
            group.Properties  = JsonConvert.DeserializeObject <PropertyCollection <string> >(entity.Properties);

            return(group);
        }