public static MsCrmResultObject ConvertCurrency(Guid sourceCurrencyId, decimal sourceValue, Guid targetCurrencyId, DateTime exchangeDate, SqlDataAccess sda) { MsCrmResultObject returnValue = new MsCrmResultObject(); returnValue.ReturnObject = sourceValue; MsCrmResultObject resultRates = CurrencyHelper.GetExchangeRate(exchangeDate, sda); if (resultRates.Success) { List <ExchangeRate> lstRates = (List <ExchangeRate>)resultRates.ReturnObject; if (sourceCurrencyId != targetCurrencyId) { if (sourceCurrencyId == Globals.CurrencyIdTL) //TL'den Dövize ise { decimal targetRate = lstRates.Find(x => x.Currency.Id == targetCurrencyId).SaleRate; returnValue.ReturnObject = sourceValue / targetRate; returnValue.Success = true; } else if (targetCurrencyId == Globals.CurrencyIdTL) //Döziden TL'ye ise { decimal sourceRate = lstRates.Find(x => x.Currency.Id == sourceCurrencyId).SaleRate; returnValue.ReturnObject = sourceValue * sourceRate; returnValue.Success = true; } else //Dövizden dövize ise { decimal sourceRate = lstRates.Find(x => x.Currency.Id == sourceCurrencyId).SaleRate; decimal targetRate = lstRates.Find(x => x.Currency.Id == targetCurrencyId).SaleRate; returnValue.ReturnObject = sourceValue * (sourceRate / targetRate); returnValue.Success = true; } } else { returnValue.Success = true; returnValue.Result = "Aynı para birimi."; } } return(returnValue); }
public static MsCrmResult SendMailRentalToApproval(Product rentalProduct, Entity _rental, UserTypes type, SqlDataAccess sda, IOrganizationService service) { MsCrmResult returnValue = new MsCrmResult(); try { #region | SEND INFORMATIONS | string projectName = rentalProduct.Project != null ? rentalProduct.Project.Name : string.Empty; string blockName = rentalProduct.Block != null ? rentalProduct.Block.Name : string.Empty; string floorNumber = rentalProduct.FloorNumber != null?rentalProduct.FloorNumber.ToString() : string.Empty; string generalhomeType = rentalProduct.GeneralHomeType != null ? rentalProduct.GeneralHomeType.Name : string.Empty; string homeType = rentalProduct.HomeType != null ? rentalProduct.HomeType.Name : string.Empty; string net = rentalProduct.Net != null ? ((decimal)rentalProduct.Net).ToString("N0", CultureInfo.CurrentCulture) : string.Empty; string brut = rentalProduct.Brut != null ? ((decimal)rentalProduct.Brut).ToString("N0", CultureInfo.CurrentCulture) : string.Empty; string productAmount = rentalProduct.PaymentOfHire.HasValue ? rentalProduct.PaymentOfHire.Value.ToString("N2") : string.Empty; string rentalAmount = _rental.GetAttributeValue <Money>("new_rentalfee") != null?_rental.GetAttributeValue <Money>("new_rentalfee").Value.ToString("N2") : string.Empty; string currencyName = _rental.GetAttributeValue <EntityReference>("transactioncurrencyid") != null ? (_rental.GetAttributeValue <EntityReference>("transactioncurrencyid")).Name : string.Empty; #endregion #region | GET CURRENCY | string exchangeRate = string.Empty; Guid currencyId = (_rental.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>" + rentalProduct.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 Kiralama Fiyatı : </td><td>" + productAmount + "</td></tr>"; body += "<tr><td>Kiralamak İ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=rentalconfirm&name=rentalid&pageid=" + _rental.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"] = _rental.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(_rental.Id, "new_rentalrecord", fromPartyColl, toPartyColl, "Kiralama 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); }