public async Task<LocalIssue> CreateOrUpdateIssueAsync(LocalIssue issue)
        {
            using (context = new SqliteContext(BaseConnstr))
            {
                var existed = context.Issue
                    .AsNoTracking()
                    .Include(i => i.Row)
                    .Include(i => i.Column)
                    .FirstOrDefault(iss => iss.Id == issue.Id);
                mapper.Map(issue, existed);

                if (existed == null)
                {
                    var newiss = mapper.Map<SqliteIssue>(issue);
                    context.Attach(newiss.Row);
                    context.Attach(newiss.Column);

                    await context.AddAsync(newiss);
                    await context.SaveChangesAsync();
                    context.Update(newiss.Column);
                    context.Update(newiss.Row);
                    await context.SaveChangesAsync();
                    return mapper.Map<LocalIssue>(newiss);
                }

                context.Update(existed);
                await context.SaveChangesAsync();
                return issue;
            }
        }
Esempio n. 2
0
        public async Task <ColumnInfo> CreateOrUpdateColumnAsync(ColumnInfo column)
        {
            using (context = new SqliteContext(BaseConnstr))
            {
                if (column.Id == 0 || context.Column.AsNoTracking()
                    .FirstOrDefault(c => c.Id == column.Id) == null)
                {
                    context.Attach(column.Board);
                    await context.AddAsync(column);
                }

                else
                {
                    context.Update(column);
                }
                await context.SaveChangesAsync();

                return(column);
            }
        }
Esempio n. 3
0
        public async Task <RowInfo> CreateOrUpdateRowAsync(RowInfo row)
        {
            using (context = new SqliteContext(BaseConnstr))
            {
                if (row.Id == 0 || context.Row.AsNoTracking()
                    .FirstOrDefault(c => c.Id == row.Id) == null)
                {
                    context.Attach(row.Board);
                    await context.AddAsync(row);
                }

                else
                {
                    context.Update(row);
                }
                await context.SaveChangesAsync();

                return(row);
            }
        }