public GroupSupplier AddandGetSupplierID(Supplier entry, string parrentgroup) { GroupSupplier groupSuppler = new GroupSupplier(); Users user = entry.User; SubSupplier subSupplier = entry.SubSupplier; if (user == null || subSupplier == null) { groupSuppler = null; } int idUser = -1; user.SetCreate(); groupSuppler = new GroupSupplier { GroupName = entry.SupplierName, ParentGroup = int.Parse(parrentgroup) }; try { using (IUnitOfWork uow = new UnitOfWork()) { idUser = uow.UsersRepository.AddAndGetID(user); if (idUser < 0) { return(null); } entry.SetCreate(); entry.GroupId = uow.SupplierRepository.AddGroup(groupSuppler); if (entry.GroupId < 0) { return(null); } groupSuppler.GroupId = entry.GroupId; entry.SupplierId = uow.SupplierRepository.AddandGetSupplierID(entry); if (entry.SupplierId < 0) { return(null); } subSupplier.UserId = idUser; subSupplier.SetCreate(); subSupplier.SupplierId = entry.SupplierId; subSupplier.IsMain = true; subSupplier.IsActive = true; uow.SubSupplierRepository.Add(subSupplier); uow.Commit(); } } catch (Exception) { return(null); } return(groupSuppler); }
public int AddandGetSupplierID(Supplier entry) { Users user = entry.User; SubSupplier subSupplier = entry.SubSupplier; if (user == null || subSupplier == null) { return(-1); } int idUser = -1; user.SetCreate(); try { using (IUnitOfWork uow = new UnitOfWork()) { idUser = uow.UsersRepository.AddAndGetID(user); if (idUser < 0) { return(-1); } entry.SetCreate(); entry.SupplierId = uow.SupplierRepository.AddandGetSupplierID(entry); if (entry.SupplierId < 0) { return(-1); } subSupplier.UserId = idUser; subSupplier.SetCreate(); subSupplier.SupplierId = entry.SupplierId; subSupplier.IsMain = true; subSupplier.IsActive = true; uow.SubSupplierRepository.Add(subSupplier); uow.Commit(); } } catch (Exception) { return(-2); } return(entry.SupplierId); }
private SubSupplier SaveAccount(Users user) { int supplierId = string.IsNullOrWhiteSpace(txtsupplierId.Text) == false?Convert.ToInt32(txtsupplierId.Text) : 0; if (supplierId <= 0) { lblNotify1.SetText(UI.deputyhasnocompany, LabelNotify.EnumStatus.Failed); return(null); } if (ValidationUtility.IsTextAllowed(user.UserName) == false) { lblNotify1.SetText(UI.usernotallowspace, LabelNotify.EnumStatus.Failed); return(null); } user.Sex = rdNam.Checked == true ? true : false; user.SetCreate(); user.UserGroupId = (int)UserTypeFlag.Customer; m_Subsupplier = new SubSupplier(); CoverObjectUtility.GetAutoBindingData(groupSubsupplier, m_Subsupplier); if (user.UserId <= 0) { m_Subsupplier.SubSupplierId = 0; } m_Subsupplier.SubSupplierName = user.FullName; m_Subsupplier.IsActive = cbActive.Checked; m_Subsupplier.Email = user.Email; m_Subsupplier.Phone = user.Phone; m_Subsupplier.Address = user.Address; m_Subsupplier.Sex = user.Sex; m_Subsupplier.UserId = user.UserId; m_Subsupplier.SupplierId = supplierId; IList <SubSupplier> lstExistsDeputy = gridControl1.DataSource as IList <SubSupplier>; SubSupplier main = lstExistsDeputy != null?lstExistsDeputy.Where(p => p.IsMain == true && p.SubSupplierId != m_Subsupplier.SubSupplierId).FirstOrDefault() : null; if (main == null) { m_Subsupplier.IsMain = true; } else { m_Subsupplier.IsMain = false; } using (IUnitOfWork uow = new UnitOfWork()) { if (user.UserId <= 0) { uow.UsersRepository.Add(user); m_Subsupplier.SetCreate(); m_Subsupplier.UserId = user.UserId; m_Subsupplier.SubSupplierId = 0; uow.SubSupplierRepository.Add(m_Subsupplier); } else { uow.UsersRepository.Update(user); m_Subsupplier.SetModify(); uow.SubSupplierRepository.Update(m_Subsupplier); } uow.Commit(); } return(m_Subsupplier); }