public override bool Update(IConnectionHandler connectionHandler, DataStructure.EnterpriseNode obj) { if ((obj.LegalEnterpriseNode != null && obj.RealEnterpriseNode != null) || (obj.LegalEnterpriseNode == null && obj.RealEnterpriseNode == null)) { throw new KnownException("نوع شخص (حقیقی/حقوقی) قابل شناسایی نمی باشد."); } var id = obj.Id; if (id.Equals(Guid.Empty)) { id = Guid.NewGuid(); } obj.Id = id; if (obj.LegalEnterpriseNode != null) { obj.LegalEnterpriseNode.Id = id; if (!new LegalEnterpriseNodeBO().Update(connectionHandler, obj.LegalEnterpriseNode)) { throw new KnownException("خطا در ثبت اطلاعات شخص حقوقی"); } } if (obj.RealEnterpriseNode != null) { obj.RealEnterpriseNode.Id = id; if (!new RealEnterpriseNodeBO().Update(connectionHandler, obj.RealEnterpriseNode)) { throw new KnownException("خطا در ثبت اطلاعات شخص حقیقی"); } } return(base.Update(connectionHandler, obj)); }
public override bool Insert(IConnectionHandler connectionHandler, DataStructure.EnterpriseNode obj) { if ((obj.LegalEnterpriseNode != null && obj.RealEnterpriseNode != null) || (obj.LegalEnterpriseNode == null && obj.RealEnterpriseNode == null)) { throw new KnownException("نوع شخص (حقیقی/حقوقی) قابل شناسایی نمی باشد."); } var id = obj.Id; BOUtility.GetGuidForId(ref id); obj.Id = id; if (obj.LegalEnterpriseNode != null) { obj.EnterpriseNodeTypeId = (int)Enums.EnterpriseNodeType.LegalEnterPriseNode; } if (obj.RealEnterpriseNode != null) { obj.EnterpriseNodeTypeId = (int)Enums.EnterpriseNodeType.RealEnterPriseNode; } if (!base.Insert(connectionHandler, obj)) { throw new KnownException("خطا در ثبت اطلاعات شخص"); } if (obj.LegalEnterpriseNode != null) { obj.LegalEnterpriseNode.Id = id; if (!new LegalEnterpriseNodeBO().Insert(connectionHandler, obj.LegalEnterpriseNode)) { throw new KnownException("خطا در ثبت اطلاعات شخص حقوقی"); } } if (obj.RealEnterpriseNode != null) { obj.RealEnterpriseNode.Id = id; if (!new RealEnterpriseNodeBO().Insert(connectionHandler, obj.RealEnterpriseNode)) { throw new KnownException("خطا در ثبت اطلاعات شخص حقیقی"); } } return(true); }
public static string Title(this DataStructure.EnterpriseNode enterprise) { var result = string.Empty; if (enterprise == null) { return(result); } if (enterprise.PrefixTitleId.HasValue) { if (enterprise.PrefixTitle == null) { enterprise.PrefixTitle = new PrefixTitleFacade().Get(enterprise.PrefixTitleId); } result += enterprise.PrefixTitle.Title + " "; } switch (enterprise.EnterpriseNodeTypeId) { case (int)Enums.EnterpriseNodeType.RealEnterPriseNode: if (enterprise.RealEnterpriseNode == null) { enterprise.RealEnterpriseNode = new RealEnterpriseNodeFacade().Get(enterprise.Id); } if (enterprise.RealEnterpriseNode != null) { result += enterprise.RealEnterpriseNode.FirstName + " " + enterprise.RealEnterpriseNode.LastName; } break; case (int)Enums.EnterpriseNodeType.LegalEnterPriseNode: if (enterprise.LegalEnterpriseNode == null) { enterprise.LegalEnterpriseNode = new LegalEnterpriseNodeFacade().Get(enterprise.Id); } if (enterprise.LegalEnterpriseNode != null) { result += enterprise.LegalEnterpriseNode.Title; } break; } return(result); }
public SqlCommand Search(DataStructure.EnterpriseNode obj) { SqlCommand q = new SqlCommand(); string query = string.Empty; string whereCluase = ""; if (obj.EnterpriseNodeTypeId == (int)Enums.EnterpriseNodeType.RealEnterPriseNode || obj.RealEnterpriseNode != null) { query = string.Format("SELECT EnterpriseNode.EnterpriseNode.* FROM EnterpriseNode.EnterpriseNode INNER JOIN " + " EnterpriseNode.RealEnterpriseNode ON EnterpriseNode.EnterpriseNode.Id = EnterpriseNode.RealEnterpriseNode.Id "); if (!string.IsNullOrEmpty(obj.RealEnterpriseNode.FirstName)) { q.Parameters.Add(new SqlParameter("@FNAME", obj.RealEnterpriseNode.FirstName)); whereCluase += "EnterpriseNode.RealEnterpriseNode.FirstName LIKE N'%@FNAME%' OR "; } if (!string.IsNullOrEmpty(obj.RealEnterpriseNode.LastName)) { q.Parameters.Add(new SqlParameter("@LNAME", obj.RealEnterpriseNode.LastName)); whereCluase += "EnterpriseNode.RealEnterpriseNode.LastName LIKE N'%@LNAME%' OR "; } if (!string.IsNullOrEmpty(obj.RealEnterpriseNode.NationalCode)) { q.Parameters.Add(new SqlParameter("@NationalCode", obj.RealEnterpriseNode.NationalCode)); whereCluase += "EnterpriseNode.RealEnterpriseNode.NationalCode LIKE '%@NationalCode%' OR "; } if (!string.IsNullOrEmpty(obj.RealEnterpriseNode.IDNumber)) { q.Parameters.Add(new SqlParameter("@IDNumber", obj.RealEnterpriseNode.IDNumber)); whereCluase += "EnterpriseNode.RealEnterpriseNode.IDNumber LIKE '%@IDNumber%' OR "; } } if (obj.EnterpriseNodeTypeId == (int)Enums.EnterpriseNodeType.LegalEnterPriseNode || obj.LegalEnterpriseNode != null) { query = string.Format("SELECT EnterpriseNode.EnterpriseNode.* FROM EnterpriseNode.EnterpriseNode INNER JOIN " + " EnterpriseNode.LegalEnterpriseNode ON EnterpriseNode.EnterpriseNode.Id = EnterpriseNode.LegalEnterpriseNode.Id "); if (!string.IsNullOrEmpty(obj.LegalEnterpriseNode.Title)) { q.Parameters.Add(new SqlParameter("@TITLE", obj.LegalEnterpriseNode.Title)); whereCluase += "EnterpriseNode.LegalEnterpriseNode.Title LIKE N'%@TITLE%' OR "; } if (!string.IsNullOrEmpty(obj.LegalEnterpriseNode.RegisterNo)) { q.Parameters.Add(new SqlParameter("@RegisterNo", obj.LegalEnterpriseNode.RegisterNo)); whereCluase += "EnterpriseNode.LegalEnterpriseNode.RegisterNo LIKE '%@RegisterNo%' OR "; } if (!string.IsNullOrEmpty(obj.LegalEnterpriseNode.NationalId)) { q.Parameters.Add(new SqlParameter("@NationalId", obj.LegalEnterpriseNode.NationalId)); whereCluase += "EnterpriseNode.LegalEnterpriseNode.NationalId LIKE '%@NationalId%' OR "; } } if (!string.IsNullOrEmpty(obj.Address)) { q.Parameters.Add(new SqlParameter("@Address", obj.Address)); whereCluase += "EnterpriseNode.[Address] LIKE '%@Address%' OR "; } if (!string.IsNullOrEmpty(obj.Website)) { q.Parameters.Add(new SqlParameter("@Website", obj.Website)); whereCluase += "EnterpriseNode.Website LIKE '%@Website%' OR "; } if (!string.IsNullOrEmpty(obj.Cellphone)) { q.Parameters.Add(new SqlParameter("@Cellphone", obj.Cellphone)); whereCluase += "EnterpriseNode.Cellphone LIKE '%@Cellphone%' OR "; } if (!string.IsNullOrEmpty(obj.Tel)) { q.Parameters.Add(new SqlParameter("@Tel", obj.Tel)); whereCluase += "EnterpriseNode.Tel LIKE '%@Tel%' OR "; } if (!string.IsNullOrEmpty(whereCluase)) { whereCluase = whereCluase.Substring(0, whereCluase.Length - 3); q.CommandText = string.Format("{0} WHERE {1} ", query, whereCluase); } return(q); }
public bool Insert(IConnectionHandler connectionHandler, IConnectionHandler filemanagerconnection, DataStructure.EnterpriseNode obj, HttpPostedFileBase file) { if (file != null) { obj.PictureId = FileManagerComponent.Instance.FileTransactionalFacade(filemanagerconnection).Insert(file, new File() { MaxSize = 200 }); } if (!this.Insert(connectionHandler, obj)) { throw new KnownException("خطا در ثبت اطلاعات شخص"); } return(true); }
public List <DataStructure.EnterpriseNode> Search(IConnectionHandler connectionHandler, DataStructure.EnterpriseNode filter) { var da = new EnterpriseNodeDA(connectionHandler); return(da.Search(filter)); }
public bool Delete(IConnectionHandler connectionHandler, IConnectionHandler filemanagerconnection, DataStructure.EnterpriseNode enterpriseNode) { if (enterpriseNode == null) { return(false); } if (!base.Delete(connectionHandler, enterpriseNode.Id)) { throw new KnownException("خطا در حذف اطلاعات شخص"); } if (enterpriseNode.PictureId.HasValue) { if (!FileManagerComponent.Instance.FileTransactionalFacade(filemanagerconnection).Delete(enterpriseNode.PictureId)) { throw new Exception("خطایی در حذف عکس وجود دارد"); } } return(true); }
public bool Update(IConnectionHandler connectionHandler, IConnectionHandler filemanagerconnection, DataStructure.EnterpriseNode obj, HttpPostedFileBase file) { if (file != null) { if (obj.PictureId.HasValue) { if (!FileManagerComponent.Instance.FileTransactionalFacade(filemanagerconnection).Update(file, (Guid)obj.PictureId, new File() { MaxSize = 200 })) { throw new Exception("خطایی در ویرایش عکس وجود دارد"); } } else { obj.PictureId = FileManagerComponent.Instance.FileTransactionalFacade(filemanagerconnection).Insert(file); } } if (obj.PictureId != null) { return(this.Update(connectionHandler, obj)); } if (!this.Update(connectionHandler, obj)) { return(false); } var oldobj = this.Get(connectionHandler, obj.Id); return(!oldobj.PictureId.HasValue || FileManagerComponent.Instance.FileFacade.Delete(oldobj.PictureId)); }