public TenderQuantityTable SaveQuantityTableBulkItems(long tableId, List <TenderQuantityItemDTO> lst, string tableName) { Name = string.IsNullOrEmpty(tableName) ? "اسم الجدول" : tableName; var lastIndex = QuantitiyItemsJson.TenderQuantityTableItems.Count != 0 ? QuantitiyItemsJson.TenderQuantityTableItems.Max(D => D.ItemNumber) : 0; foreach (var item in lst) { byte[] gb = Guid.NewGuid().ToByteArray(); long IId = BitConverter.ToInt64(gb, 0); var idExsit = QuantitiyItemsJson.TenderQuantityTableItems.Any(x => x.Id == IId); while (idExsit) { gb = Guid.NewGuid().ToByteArray(); IId = BitConverter.ToInt64(gb, 0); idExsit = QuantitiyItemsJson.TenderQuantityTableItems.Any(x => x.Id == IId); } QuantitiyItemsJson.TenderQuantityTableItems.Add(new TenderQuantityTableItem(IId, item.ColumnId, item.TenderFormHeaderId, item.TemplateId, item.ColumnName, item.Value, item.ItemNumber + lastIndex)); } if (tableId == 0) { EntityCreated(); QuantitiyItemsJson.SetAddedState(); } else { EntityUpdated(); QuantitiyItemsJson.SetUpdateState(); } return(this); }
public TenderQuantityTable SaveQuantityTableItems(long tableId, List <TenderQuantityItemDTO> lst, long currentItemId, out long itemId) { itemId = 0; bool ItemExists = QuantitiyItemsJson != null && QuantitiyItemsJson.TenderQuantityTableItems != null && QuantitiyItemsJson.TenderQuantityTableItems.Any(a => a.ItemNumber == currentItemId); var lastIndex = QuantitiyItemsJson.TenderQuantityTableItems.Any() ? QuantitiyItemsJson.TenderQuantityTableItems.Max(a => a.ItemNumber) : 0; foreach (var item in lst) { if (!ItemExists) { byte[] gb = Guid.NewGuid().ToByteArray(); long IId = BitConverter.ToInt64(gb, 0); var idExsit = QuantitiyItemsJson.TenderQuantityTableItems.Any(x => x.Id == IId); while (idExsit) { gb = Guid.NewGuid().ToByteArray(); IId = BitConverter.ToInt64(gb, 0); idExsit = QuantitiyItemsJson.TenderQuantityTableItems.Any(x => x.Id == IId); } QuantitiyItemsJson.TenderQuantityTableItems.Add(new TenderQuantityTableItem(IId, item.ColumnId, item.TenderFormHeaderId, item.TemplateId, item.ColumnName, item.Value, lastIndex + 1)); itemId = lastIndex + 1; } else { TenderQuantityTableItem QItem; if (item.Id != 0) { QItem = QuantitiyItemsJson.TenderQuantityTableItems.FirstOrDefault(q => q.Id == item.Id); } else { QItem = QuantitiyItemsJson.TenderQuantityTableItems.FirstOrDefault(q => q.ItemNumber == item.ItemNumber && q.ColumnId == item.ColumnId && q.TenderFormHeaderId == item.TenderFormHeaderId); } if (QItem != null) { QItem.UpdateItems(item.ColumnId, item.TenderFormHeaderId, item.TemplateId, item.ColumnName, item.Value, currentItemId); } } } if (tableId == 0) { EntityCreated(); QuantitiyItemsJson.SetAddedState(); } else { EntityUpdated(); QuantitiyItemsJson.SetUpdateState(); } return(this); }
public void SetAddedState() { Id = 0; QuantitiyItemsJson.SetAddedState(); EntityCreated(); }