private async Task BuildPath() { List <CustomerGroupingDAO> CustomerGroupingDAOs = await DataContext.CustomerGrouping .Where(x => x.DeletedAt == null) .AsNoTracking().ToListAsync(); Queue <CustomerGroupingDAO> queue = new Queue <CustomerGroupingDAO>(); CustomerGroupingDAOs.ForEach(x => { if (!x.ParentId.HasValue) { x.Path = x.Id + "."; x.Level = 1; queue.Enqueue(x); } }); while (queue.Count > 0) { CustomerGroupingDAO Parent = queue.Dequeue(); foreach (CustomerGroupingDAO CustomerGroupingDAO in CustomerGroupingDAOs) { if (CustomerGroupingDAO.ParentId == Parent.Id) { CustomerGroupingDAO.Path = Parent.Path + CustomerGroupingDAO.Id + "."; CustomerGroupingDAO.Level = Parent.Level + 1; queue.Enqueue(CustomerGroupingDAO); } } } await DataContext.BulkMergeAsync(CustomerGroupingDAOs); }
public async Task <bool> BulkMerge(List <CustomerGrouping> CustomerGroupings) { List <CustomerGroupingDAO> CustomerGroupingDAOs = new List <CustomerGroupingDAO>(); foreach (CustomerGrouping CustomerGrouping in CustomerGroupings) { CustomerGroupingDAO CustomerGroupingDAO = new CustomerGroupingDAO(); CustomerGroupingDAO.Id = CustomerGrouping.Id; CustomerGroupingDAO.Code = CustomerGrouping.Code; CustomerGroupingDAO.Name = CustomerGrouping.Name; CustomerGroupingDAO.CustomerTypeId = CustomerGrouping.CustomerTypeId; CustomerGroupingDAO.ParentId = CustomerGrouping.ParentId; CustomerGroupingDAO.Path = CustomerGrouping.Path; CustomerGroupingDAO.Level = CustomerGrouping.Level; CustomerGroupingDAO.StatusId = CustomerGrouping.StatusId; CustomerGroupingDAO.Description = CustomerGrouping.Description; CustomerGroupingDAO.CreatedAt = StaticParams.DateTimeNow; CustomerGroupingDAO.UpdatedAt = StaticParams.DateTimeNow; CustomerGroupingDAOs.Add(CustomerGroupingDAO); } await DataContext.BulkMergeAsync(CustomerGroupingDAOs); await BuildPath(); return(true); }
public async Task <bool> Update(CustomerGrouping CustomerGrouping) { CustomerGroupingDAO CustomerGroupingDAO = DataContext.CustomerGrouping.Where(x => x.Id == CustomerGrouping.Id).FirstOrDefault(); if (CustomerGroupingDAO == null) { return(false); } CustomerGroupingDAO.Id = CustomerGrouping.Id; CustomerGroupingDAO.Code = CustomerGrouping.Code; CustomerGroupingDAO.Name = CustomerGrouping.Name; CustomerGroupingDAO.CustomerTypeId = CustomerGrouping.CustomerTypeId; CustomerGroupingDAO.ParentId = CustomerGrouping.ParentId; CustomerGroupingDAO.Path = CustomerGrouping.Path; CustomerGroupingDAO.Level = CustomerGrouping.Level; CustomerGroupingDAO.StatusId = CustomerGrouping.StatusId; CustomerGroupingDAO.Description = CustomerGrouping.Description; CustomerGroupingDAO.Path = ""; CustomerGroupingDAO.Level = 1; CustomerGroupingDAO.UpdatedAt = StaticParams.DateTimeNow; await DataContext.SaveChangesAsync(); await SaveReference(CustomerGrouping); await BuildPath(); return(true); }
public async Task <bool> Create(CustomerGrouping CustomerGrouping) { CustomerGroupingDAO CustomerGroupingDAO = new CustomerGroupingDAO(); CustomerGroupingDAO.Id = CustomerGrouping.Id; CustomerGroupingDAO.Code = CustomerGrouping.Code; CustomerGroupingDAO.Name = CustomerGrouping.Name; CustomerGroupingDAO.CustomerTypeId = CustomerGrouping.CustomerTypeId; CustomerGroupingDAO.ParentId = CustomerGrouping.ParentId; CustomerGroupingDAO.Path = CustomerGrouping.Path; CustomerGroupingDAO.Level = CustomerGrouping.Level; CustomerGroupingDAO.StatusId = CustomerGrouping.StatusId; CustomerGroupingDAO.Description = CustomerGrouping.Description; CustomerGroupingDAO.Path = ""; CustomerGroupingDAO.Level = 1; CustomerGroupingDAO.CreatedAt = StaticParams.DateTimeNow; CustomerGroupingDAO.UpdatedAt = StaticParams.DateTimeNow; DataContext.CustomerGrouping.Add(CustomerGroupingDAO); await DataContext.SaveChangesAsync(); CustomerGrouping.Id = CustomerGroupingDAO.Id; await SaveReference(CustomerGrouping); await BuildPath(); return(true); }
public async Task <bool> Delete(CustomerGrouping CustomerGrouping) { CustomerGroupingDAO CustomerGroupingDAO = await DataContext.CustomerGrouping.Where(x => x.Id == CustomerGrouping.Id).FirstOrDefaultAsync(); DataContext.CustomerGrouping.Remove(CustomerGroupingDAO); await DataContext.SaveChangesAsync(); return(true); }
public async Task <bool> Update(CustomerGrouping CustomerGrouping) { CustomerGroupingDAO CustomerGroupingDAO = DataContext.CustomerGrouping.Where(x => x.Id == CustomerGrouping.Id).FirstOrDefault(); CustomerGroupingDAO.Id = CustomerGrouping.Id; CustomerGroupingDAO.Name = CustomerGrouping.Name; await DataContext.SaveChangesAsync(); return(true); }
public async Task <bool> Create(CustomerGrouping CustomerGrouping) { CustomerGroupingDAO CustomerGroupingDAO = new CustomerGroupingDAO(); CustomerGroupingDAO.Id = CustomerGrouping.Id; CustomerGroupingDAO.Name = CustomerGrouping.Name; await DataContext.CustomerGrouping.AddAsync(CustomerGroupingDAO); await DataContext.SaveChangesAsync(); CustomerGrouping.Id = CustomerGroupingDAO.Id; return(true); }
public async Task <bool> Delete(CustomerGrouping CustomerGrouping) { CustomerGroupingDAO CustomerGroupingDAO = await DataContext.CustomerGrouping.Where(x => x.Id == CustomerGrouping.Id).FirstOrDefaultAsync(); await DataContext.CustomerGrouping.Where(x => x.Path.StartsWith(CustomerGroupingDAO.Id + ".")).UpdateFromQueryAsync(x => new CustomerGroupingDAO { DeletedAt = StaticParams.DateTimeNow, UpdatedAt = StaticParams.DateTimeNow }); await DataContext.CustomerGrouping.Where(x => x.Id == CustomerGrouping.Id).UpdateFromQueryAsync(x => new CustomerGroupingDAO { DeletedAt = StaticParams.DateTimeNow, UpdatedAt = StaticParams.DateTimeNow }); await BuildPath(); return(true); }