Ejemplo n.º 1
0
        public static MsCrmResult SendMailSecondHandToApproval(Product secondHandProduct, Entity _secondHand, UserTypes type, SqlDataAccess sda, IOrganizationService service)
        {
            MsCrmResult returnValue = new MsCrmResult();

            try
            {
                #region | SEND INFORMATIONS |
                string projectName = secondHandProduct.Project != null ? secondHandProduct.Project.Name : string.Empty;
                string blockName   = secondHandProduct.Block != null ? secondHandProduct.Block.Name : string.Empty;
                string floorNumber = secondHandProduct.FloorNumber != null?secondHandProduct.FloorNumber.ToString() : string.Empty;

                string generalhomeType = secondHandProduct.GeneralHomeType != null ? secondHandProduct.GeneralHomeType.Name : string.Empty;
                string homeType        = secondHandProduct.HomeType != null ? secondHandProduct.HomeType.Name : string.Empty;
                string net             = secondHandProduct.Net != null ? ((decimal)secondHandProduct.Net).ToString("N0", CultureInfo.CurrentCulture) : string.Empty;
                string brut            = secondHandProduct.Brut != null ? ((decimal)secondHandProduct.Brut).ToString("N0", CultureInfo.CurrentCulture) : string.Empty;
                string productAmount   = secondHandProduct.PaymentOfHire.HasValue ? secondHandProduct.PaymentOfHire.Value.ToString("N2") : string.Empty;
                string rentalAmount    = _secondHand.GetAttributeValue <Money>("new_salesfee") != null?_secondHand.GetAttributeValue <Money>("new_salesfee").Value.ToString("N2") : string.Empty;

                string currencyName = _secondHand.GetAttributeValue <EntityReference>("transactioncurrencyid") != null ? (_secondHand.GetAttributeValue <EntityReference>("transactioncurrencyid")).Name : string.Empty;
                #endregion

                #region | GET CURRENCY |
                string            exchangeRate   = string.Empty;
                Guid              currencyId     = (_secondHand.GetAttributeValue <EntityReference>("transactioncurrencyid")).Id;
                MsCrmResultObject currencyResult = CurrencyHelper.GetExchangeRateByCurrency(DateTime.Now, currencyId, sda);
                if (currencyResult.Success)
                {
                    ExchangeRate rate = (ExchangeRate)currencyResult.ReturnObject;
                    exchangeRate = ((decimal)rate.SaleRate).ToString("N0", CultureInfo.CurrentCulture);
                }
                #endregion

                string body = "<table>";
                body += "<tr><td>Proje : </td><td>" + projectName + "</td></tr>";
                body += "<tr><td>Blok : </td><td>" + blockName + "</td></tr>";
                body += "<tr><td>Kat : </td><td>" + floorNumber + "</td></tr>";
                body += "<tr><td>Daire No : </td><td>" + secondHandProduct.HomeNumber + "</td></tr>";
                body += "<tr><td>Tip : </td><td>" + generalhomeType + "</td></tr>";
                body += "<tr><td>Daire Tipi : </td><td>" + homeType + "</td></tr>";
                body += "<tr><td>Konut Satış Fiyatı Fiyatı : </td><td>" + productAmount + "</td></tr>";
                body += "<tr><td>Satılmak İstenen Fiyat : </td><td>" + rentalAmount + "</td></tr>";
                body += "<tr><td>Net m2 : </td><td>" + net + "</td></tr>";
                body += "<tr><td>Brüt m2 : </td><td>" + brut + "</td></tr>";
                body += "<tr><td>Para Birimi : </td><td>" + currencyName + "</td></tr>";
                body += "<tr><td>Güncel Kur : </td><td>" + exchangeRate + "</td></tr>";
                body += "</table>";
                body += "<br/>";
                body += "<br/>";
                body += "<a href='{0}' target='_blank'>Kiralamayı onaylamak/reddetmek için lütfen tıklayınız.</a>";

                string url = "http://fenix.centralproperty.com.tr/index.aspx?page=secondhandconfirm&name=secondhandid&pageid=" + _secondHand.Id;
                body = string.Format(body, url);

                //MsCrmResultObject managerResult = SystemUserHelper.GetSalesManager(sda);
                MsCrmResultObject managerResult = SystemUserHelper.GetUsersByUserTypes(type, sda);

                if (managerResult != null && managerResult.Success)
                {
                    Entity fromParty = new Entity("activityparty");
                    fromParty["partyid"] = _secondHand.GetAttributeValue <EntityReference>("ownerid");
                    Entity[] fromPartyColl = new Entity[] { fromParty };

                    #region | SET TO |

                    List <SystemUser> returnList  = (List <SystemUser>)managerResult.ReturnObject;
                    Entity[]          toPartyColl = new Entity[returnList.Count];
                    for (int i = 0; i < returnList.Count; i++)
                    {
                        Entity toParty = new Entity("activityparty");
                        toParty["partyid"] = new EntityReference("systemuser", returnList[i].SystemUserId);
                        toPartyColl[i]     = toParty;
                    }
                    #endregion
                    Annotation  anno       = null;
                    MsCrmResult mailResult = GeneralHelper.SendMail(_secondHand.Id, "new_resalerecord", fromPartyColl, toPartyColl, "2.El Satış Onayı", body, anno, service);
                    returnValue = mailResult;
                }
                else
                {
                    returnValue.Success = false;
                    returnValue.Result  = managerResult.Result;
                }
            }
            catch (Exception ex)
            {
                returnValue.Success = false;
                returnValue.Result  = ex.Message;
            }
            return(returnValue);
        }