internal void AddNumberingPool(NumberingPool np, bool isReserved) { np.CreatedOn = DateTime.Now; np.ModifiedOn = np.CreatedOn; if (isReserved) { np.Status = NumberingStatus.Reserved; } else { np.Status = NumberingStatus.Free; } //np.Rond = np.GetRondType(); context.NumberingPools.Add(np); context.SaveChanges(); }
internal void EditNumberingPool(NumberingPool np) { var originalNp = context.NumberingPools.Find(np.Id); originalNp.Prefix = np.Prefix; originalNp.Area = np.Area; originalNp.ChargingCase = np.ChargingCase; originalNp.Direction = np.Direction; originalNp.IsFloat = np.IsFloat; originalNp.IsKeshvari = np.IsKeshvari; originalNp.Link = np.Link; originalNp.Max = np.Max; originalNp.Min = np.Min; originalNp.ModifiedOn = DateTime.Now; originalNp.NumberType = np.NumberType; originalNp.Owner = np.Owner; originalNp.Remark = np.Remark; originalNp.SecondaryArea = np.SecondaryArea; originalNp.SecondaryMax = np.SecondaryMax; originalNp.SecondaryMin = np.SecondaryMin; originalNp.Username = np.Username; //track.Property(x => x.CreatedOn).IsModified = false; context.SaveChanges(); }
internal bool InsertFreeCodes(InsertNumberingPool freeCode, string user, out string error, out int addNo) { List <string> prefixesToAdd = new List <string>(); List <string> prefixesToChange = new List <string>(); addNo = 0; for (int i = freeCode.From; i < freeCode.To + 1; i++) { var overlaps = PrefixValidationSearch(i.ToString()); if (overlaps.Count() == 0) { prefixesToAdd.Add(i.ToString()); } else if (overlaps.Count() == 1 && overlaps.First().Prefix == i.ToString() && freeCode.NotDefined) { prefixesToChange.Add(i.ToString()); } else if (overlaps.Count() > 0 && freeCode.NotDefined) { continue; } else { error = $"Overlap: {string.Join(", ", overlaps.Select(x => x.Prefix))}"; return(false); } } var crmCodes = CrmCodes .Where(x => prefixesToAdd.Contains(x.Code) || prefixesToChange.Contains(x.Code)).ToArray(); List <NumberingPool> npToAdd = new List <NumberingPool>(); addNo = prefixesToAdd.Count; foreach (var prefix in prefixesToAdd) { var newPrefix = new NumberingPool() { Abb = null, IsFloat = false, SecondaryArea = freeCode.Area, Remark = "", Area = freeCode.Area, SubscriberName = null, CreatedOn = DateTime.Now, ModifiedOn = DateTime.Now, ExpireDate = new DateTime(2300, 1, 1), IsKeshvari = false, Min = freeCode.Min, Max = freeCode.Max, SecondaryMax = freeCode.Max, SecondaryMin = freeCode.Min, Owner = "TCT", NumberType = freeCode.NumberType, Status = freeCode.IsReserved ? NumberingStatus.Reserved : NumberingStatus.Free, Username = user, ChargingCase = freeCode.ChargingCase, Prefix = prefix, Link = freeCode.Link, Direction = null, }; //newPrefix.Rond = newPrefix.GetRondType(); npToAdd.Add(newPrefix); } var npToChange = context.NumberingPools .Where(x => prefixesToChange.Contains(x.Prefix)).ToArray(); foreach (var p in npToChange) { p.SecondaryMin = freeCode.Min; p.SecondaryMax = freeCode.Max; p.SecondaryArea = freeCode.Area; p.Username = user; } if (freeCode.NotDefined) { foreach (var np in npToAdd) { var q = crmCodes.Where(x => x.Code == np.Prefix).ToArray(); if (q.Count() == 1) { np.Status = NumberingStatus.Reserved; np.Area = q.First().Area; } } foreach (var np in npToChange) { var q = crmCodes.Where(x => x.Code == np.Prefix).ToArray(); if (q.Count() == 1) { if (np.Status == NumberingStatus.Free) { np.Status = NumberingStatus.Reserved; } np.Area = q.First().Area; } } } context.NumberingPools.AddRange(npToAdd); context.SaveChanges(); error = ""; return(true); }