Пример #1
0
        public static MsCrmResult CreateOrUpdateAuthorityDocument(AuthorityDocument document, IOrganizationService service)
        {
            MsCrmResult returnValue = new MsCrmResult();

            try
            {
                Entity ent = new Entity("new_registrationdoc");

                if (document.Product != null)
                {
                    ent["new_productid"] = document.Product;
                }
                if (document.Contact != null)
                {
                    ent["new_authorizingpersonid"] = document.Contact;
                }
                if (document.StartDate != null)
                {
                    ent["new_startofauthority"] = document.StartDate;
                }
                if (document.EndDate != null)
                {
                    ent["new_endofauthority"] = document.EndDate;
                }
                if (document.Name != null)
                {
                    ent["new_name"] = document.Name;
                }
                ent["new_isimportauthoritydoc"] = true;

                if (document.AuthorityDocumentId.HasValue)
                {
                    ent.Id            = document.AuthorityDocumentId.Value;
                    returnValue.CrmId = document.AuthorityDocumentId.Value;
                    service.Update(ent);
                    ProductHelper.UpdateProductAuthorityDoc(document, service);
                    returnValue.Success = true;
                    returnValue.Result  = "Yetki Doküman kaydı başarıyla güncelleştirildi.";
                }
                else
                {
                    returnValue.CrmId   = service.Create(ent);
                    returnValue.Success = true;
                    returnValue.Result  = "Yetki Doküman kaydı başarıyla oluşturuldu.";
                }
            }
            catch (Exception ex)
            {
                returnValue.Success = false;
                returnValue.Result  = ex.Message;
            }
            return(returnValue);
        }
Пример #2
0
        private static MsCrmResultObject GetAuthorityDocument(Guid authorityId, SqlDataAccess sda)
        {
            MsCrmResultObject returnValue = new MsCrmResultObject();

            try
            {
                #region | SQL QUERY |

                string sqlQuery = @"SELECT 
                                        R.new_registrationdocId,
									    R.new_authorizingpersonid,
									    R.new_authorizingpersonidName,
									    P.ProductId,
									    P.Name,
									    R.new_startofauthority,
									    R.new_endofauthority,
									    R.new_name,
									    P.new_projectid,
									    P.new_projectidName,
									    P.new_blockidName,
									    P.new_homenumber
									FROM
									    new_registrationdoc AS R WITH(NOLOCK)
									JOIN Product AS P WITH(NOLOCK)
									    ON P.ProductId = R.new_productid
									WHERE
									    R.new_registrationdocId = @docid"                                    ;

                #endregion

                SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@docid", authorityId) };

                DataTable dt = sda.getDataTable(sqlQuery, parameters);

                if (dt.Rows.Count > 0)
                {
                    #region | FILL DOCUMENT INFO |
                    AuthorityDocument _document = new AuthorityDocument();
                    _document.AuthorityDocumentId = (Guid)dt.Rows[0]["new_registrationdocId"];
                    _document.Name = dt.Rows[0]["new_name"].ToString();

                    if (dt.Rows[0]["new_name"] != DBNull.Value)
                    {
                        _document.Name = dt.Rows[0]["new_name"].ToString();
                    }
                    if (dt.Rows[0]["ProductId"] != DBNull.Value)
                    {
                        _document.Product = new EntityReference()
                        {
                            Id = (Guid)dt.Rows[0]["ProductId"], Name = dt.Rows[0]["Name"].ToString(), LogicalName = "product"
                        };
                    }
                    if (dt.Rows[0]["new_projectid"] != DBNull.Value)
                    {
                        _document.Project = new EntityReference()
                        {
                            Id = (Guid)dt.Rows[0]["new_projectid"], Name = dt.Rows[0]["new_projectidName"].ToString(), LogicalName = "new_project"
                        };
                    }

                    if (dt.Rows[0]["new_authorizingpersonid"] != DBNull.Value)
                    {
                        _document.Contact = new EntityReference()
                        {
                            Id = (Guid)dt.Rows[0]["new_authorizingpersonid"], Name = dt.Rows[0]["new_authorizingpersonidName"].ToString(), LogicalName = "contact"
                        };
                    }
                    if (dt.Rows[0]["new_startofauthority"] != DBNull.Value)
                    {
                        _document.StartDate    = (DateTime)dt.Rows[0]["new_startofauthority"];
                        _document.StartDateStr = ((DateTime)dt.Rows[0]["new_startofauthority"]).ToLocalTime().ToShortDateString();
                    }

                    if (dt.Rows[0]["new_endofauthority"] != DBNull.Value)
                    {
                        _document.EndDate    = (DateTime)dt.Rows[0]["new_endofauthority"];
                        _document.EndDateStr = ((DateTime)dt.Rows[0]["new_endofauthority"]).ToLocalTime().ToShortDateString();
                    }


                    if (dt.Rows[0]["new_blockidName"] != DBNull.Value)
                    {
                        _document.BlockName = dt.Rows[0]["new_blockidName"].ToString();
                    }

                    if (dt.Rows[0]["new_homenumber"] != DBNull.Value)
                    {
                        _document.HomeNumber = dt.Rows[0]["new_homenumber"].ToString();
                    }

                    #endregion

                    returnValue.Success      = true;
                    returnValue.Result       = "Kayıt başarıyla alındı";
                    returnValue.ReturnObject = _document;
                }
            }
            catch (Exception ex)
            {
                returnValue.Success = false;
                returnValue.Result  = ex.Message;
            }
            return(returnValue);
        }
Пример #3
0
        public static MsCrmResultObject MakeAuthorityDocSearch(Guid?projectId, DateTime?startDate, DateTime?endDate, IOrganizationService service, SqlDataAccess sda)
        {
            MsCrmResultObject returnValue = new MsCrmResultObject();

            try
            {
                SqlParameter[] parameters = null;
                #region | SQL QUERY |
                string query = @"SELECT 
									R.new_registrationdocId
                                FROM
	                                new_registrationdoc R WITH (NOLOCK)
									JOIN Product as P WITH(NOLOCK)
									ON 
									P.ProductId = R.new_productid
                                WHERE
	                                P.StateCode = 0"    ;

                if (projectId.HasValue)
                {
                    query += @"	AND
	                            P.new_projectid = '{0}'"    ;
                    query  = string.Format(query, projectId.Value);
                }
                else
                {
                    OrganizationServiceContext orgServiceContext = new OrganizationServiceContext(service);

                    var linqQuery = (from a in orgServiceContext.CreateQuery("new_project")
                                     where
                                     ((OptionSetValue)a["statecode"]).Value == 0
                                     select new
                    {
                        Id = a.Id
                    }).ToList();
                    if (linqQuery != null && linqQuery.Count > 0)
                    {
                        query += @"	AND
	                            P.new_projectid IN("    ;

                        for (int i = 0; i < linqQuery.Count; i++)
                        {
                            if (i != linqQuery.Count - 1)
                            {
                                query += "'" + linqQuery[i].Id + "',";
                            }
                            else
                            {
                                query += "'" + linqQuery[i].Id + "'";
                            }
                        }
                        query += ")";
                    }
                }

                if (startDate.HasValue)
                {
                    query     += @"	AND
	                                    R.new_startofauthority >= @minValue"    ;
                    parameters = new SqlParameter[] { new SqlParameter("@minValue", startDate.Value) };
                }
                else if (endDate.HasValue)
                {
                    query     += @"	AND
	                                    R.new_endofauthority <= @maxValue"    ;
                    parameters = new SqlParameter[] { new SqlParameter("@maxValue", endDate.Value) };
                }

                #endregion

                DataTable dt = null;
                if (parameters == null)
                {
                    dt = sda.getDataTable(query);
                }
                else
                {
                    dt = sda.getDataTable(query, parameters);
                }


                if (dt != null && dt.Rows.Count > 0)
                {
                    #region | GET PRODUCTS |
                    List <AuthorityDocument> returnList = new List <AuthorityDocument>();

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        AuthorityDocument doc = (AuthorityDocument)GetAuthorityDocument((Guid)dt.Rows[i]["new_registrationdocId"], sda).ReturnObject;
                        returnList.Add(doc);
                    }
                    #endregion

                    returnValue.Success      = true;
                    returnValue.ReturnObject = returnList;
                }
                else
                {
                    returnValue.Success = false;
                    returnValue.Result  = "Aradığınız kriterlere ait konut bulunmamaktadır!";
                }
            }
            catch (Exception ex)
            {
                returnValue.Success = false;
                returnValue.Result  = ex.Message;
            }

            return(returnValue);
        }