private async Task <PeoplesBussines> GetItemsAsync(int index) { var pe = new PeoplesBussines(); try { if (ColName == 0) { return(null); } var name = GetValue(ColName, index); //بدون نام درج نشود if (cmbDuplicateName.SelectedIndex == 0) { if (string.IsNullOrEmpty(name)) { return(null); } } //نام تکراری درج نشه if (cmbDuplicateName.SelectedIndex == 1) { if (!string.IsNullOrEmpty(name)) { var checkName = await TafsilBussines.CheckNameAsync(name); if (!checkName) { return(null); } pe.Name = name; } } pe.Guid = Guid.NewGuid(); if (string.IsNullOrEmpty(pe.Name)) { pe.Name = GetValue(ColName, index); } var code = GetValue(ColCode, index); //بدون کد درج نشه if (cmbDuplicateCode.SelectedIndex == 0) { if (string.IsNullOrEmpty(code)) { return(null); } } //کد تکراری درج نشه if (cmbDuplicateCode.SelectedIndex == 1) { if (!string.IsNullOrEmpty(code)) { var tf = await TafsilBussines.GetAsync(pe.Guid); var checkCode = await tf.CheckCodeAsync(pe.Guid, code); if (!checkCode) { return(null); } pe.Code = code; } } //پیشنهاد کد جدید در صورت خالی بودن یا تکراری بودن if (cmbDuplicateCode.SelectedIndex == 2) { var newCode = await TafsilBussines.NextCodeAsync(HesabType.Customer); var tf = await TafsilBussines.GetAsync(pe.Guid); if (string.IsNullOrEmpty(code) || !await tf.CheckCodeAsync(pe.Guid, code)) { pe.Code = newCode; } else { pe.Code = code; } } var grp = GetValue(ColGroup, index); if (string.IsNullOrEmpty(grp)) { pe.GroupGuid = (Guid)cmbWithoutGroup.SelectedValue; } else { var group = PeopleGroupBussines.Get(grp); if (group == null) { var g = new PeopleGroupBussines() { Guid = Guid.NewGuid(), Name = grp, ParentGuid = Guid.Empty }; await g.SaveAsync(); pe.GroupGuid = g.Guid; } else { pe.GroupGuid = group.Guid; } } var acc = (decimal)0; var x = GetValue(ColAccount, index); acc = x.RemoveNoNumbers("").ParseToDecimal(); if (x.Contains("??") | x.Contains("-")) { acc = -acc; } pe.Account = acc; pe.AccountFirst = acc; pe.NationalCode = GetValue(ColNationalCode, index); pe.IdCode = GetValue(ColIdCode, index); pe.FatherName = GetValue(ColFatherName, index); pe.PlaceBirth = GetValue(ColPlaceB, index); pe.DateBirth = GetValue(ColDateB, index); pe.IssuedFrom = GetValue(ColIssued, index); pe.Address = GetValue(ColAddress, index); pe.PostalCode = GetValue(ColPostalCode, index); pe.TellList = new List <PhoneBookBussines>(); if (!string.IsNullOrEmpty(GetValue(ColTell1, index))) { pe.TellList.Add(new PhoneBookBussines() { Guid = Guid.NewGuid(), Name = pe.Name, ParentGuid = pe.Guid, Group = EnPhoneBookGroup.Peoples, Tell = GetValue(ColTell1, index) }); } if (!string.IsNullOrEmpty(GetValue(ColTell3, index))) { pe.TellList.Add(new PhoneBookBussines() { Guid = Guid.NewGuid(), Name = pe.Name, ParentGuid = pe.Guid, Group = EnPhoneBookGroup.Peoples, Tell = GetValue(ColTell3, index) }); } if (!string.IsNullOrEmpty(GetValue(ColTell4, index))) { pe.TellList.Add(new PhoneBookBussines() { Guid = Guid.NewGuid(), Name = pe.Name, ParentGuid = pe.Guid, Group = EnPhoneBookGroup.Peoples, Tell = GetValue(ColTell4, index) }); } if (!string.IsNullOrEmpty(GetValue(ColTell2, index))) { pe.TellList.Add(new PhoneBookBussines() { Guid = Guid.NewGuid(), Name = pe.Name, ParentGuid = pe.Guid, Group = EnPhoneBookGroup.Peoples, Tell = GetValue(ColTell2, index) }); } } catch (Exception ex) { WebErrorLog.ErrorInstence.StartErrorLog(ex); } return(pe); }