Beispiel #1
0
        //Save

        public bool SaveCurrencyconversion(CurrencyConversionModel objCurcov)
        {
            string Query   = string.Empty;
            bool   isSaved = true;

            try
            {
                DBParameterCollection paramCollection = new DBParameterCollection();

                paramCollection.Add(new DBParameter("@CurrencyDate", objCurcov.Date, System.Data.DbType.Date));
                paramCollection.Add(new DBParameter("@CreatedBy", "Admin"));

                System.Data.IDataReader dr =
                    _dbHelper.ExecuteDataReader("spInsertCurrencyConversion", _dbHelper.GetConnObject(), paramCollection, System.Data.CommandType.StoredProcedure);
                int id = 0;
                dr.Read();
                id = Convert.ToInt32(dr[0]);
                SaveCurrencyConDetails(objCurcov.CurrenyDetails, id);
                isSaved = true;
            }
            catch (Exception ex)
            {
                isSaved = false;
                throw ex;
            }

            return(isSaved);
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (dtDate.Text.Equals(string.Empty))
            {
                MessageBox.Show("Date can not be blank!");
                return;
            }
            CurrencyConversionModel objcurconv = new CurrencyConversionModel();

            objcurconv.Date = Convert.ToDateTime(dtDate.Text.Trim());
            CurrencyConversionDetailsModel        objCurrency;
            List <CurrencyConversionDetailsModel> lstCurrency = new List <CurrencyConversionDetailsModel>();

            for (int i = 0; i < dvgCurrencyConvDetails.DataRowCount; i++)
            {
                DataRow row = dvgCurrencyConvDetails.GetDataRow(i);

                objCurrency              = new CurrencyConversionDetailsModel();
                objCurrency.Currency     = row["Currency"].ToString();
                objCurrency.StandardRate = Convert.ToDecimal(row["TandardRate"].ToString());
                objCurrency.SellingRate  = Convert.ToDecimal(row["SellingRate"].ToString());
                objCurrency.BuyingRate   = Convert.ToDecimal(row["BuyingRate"].ToString());
                lstCurrency.Add(objCurrency);
            }
            objcurconv.CurrenyDetails = lstCurrency;

            bool isSuccess = objConBal.SaveCurrencyconversion(objcurconv);

            if (isSuccess)
            {
                MessageBox.Show("Saved Successfully!");
                ClearFormValues();
                Con_Id = 0;
            }
        }
        //Save

        public bool SaveCurrencyconversion(CurrencyConversionModel objCurcov)
        {
            string Query   = string.Empty;
            bool   isSaved = true;

            try
            {
                DBParameterCollection paramCollection = new DBParameterCollection();

                paramCollection.Add(new DBParameter("@Date", objCurcov.Date));


                Query = "INSERT INTO CurrencyConversion(`Date`) " +
                        "VALUES(@Date)";

                if (_dbHelper.ExecuteNonQuery(Query, paramCollection) > 0)
                {
                    isSaved = true;
                }
            }
            catch (Exception ex)
            {
                isSaved = false;
                throw ex;
            }

            return(isSaved);
        }
        public CurrencyConversionModel CalculateAmountForCurrencyConversion(CurrencyConversionModel currencyConversionModel)
        {
            CurrencyRecord firstDesiredCurrency  = GetDesiredCurrency(currencyConversionModel.FirstCurrency, currencyConversionModel.Date);
            CurrencyRecord secondDesiredCurrency = GetDesiredCurrency(currencyConversionModel.SecondCurrency, currencyConversionModel.Date);

            currencyConversionModel.AmountSecondCurrency = currencyConversionModel.AmountFirstCurrency * firstDesiredCurrency.Close / secondDesiredCurrency.Close;
            return(currencyConversionModel);
        }
        public async Task <CurrencyConversionModel> GetCurrencyConversionById(int currencyConversionId)
        {
            CurrencyConversionModel currencyConversionModel = null;

            IList <CurrencyConversionModel> currencyConversionModelList = await GetCurrencyConversionList(currencyConversionId, 0);

            if (null != currencyConversionModelList && currencyConversionModelList.Any())
            {
                currencyConversionModel = currencyConversionModelList.FirstOrDefault();
            }

            return(currencyConversionModel); // returns.
        }
        public async Task <bool> UpdateCurrencyConversion(CurrencyConversionModel currencyConversionModel)
        {
            bool isUpdated = false;

            // get record.
            Currencyconversion currencyConversion = await GetByIdAsync(w => w.ConversionId == currencyConversionModel.ConversionId);

            if (null != currencyConversion)
            {
                // assign values.
                currencyConversion.EffectiveDateTime = currencyConversionModel.EffectiveDateTime;
                currencyConversion.ExchangeRate      = currencyConversionModel.ExchangeRate;
                isUpdated = await Update(currencyConversion);
            }

            return(isUpdated); // returns.
        }
        public async Task <CurrencyConversionModel> GetExchangeRateByCurrencyId(int currencyId, DateTime invoiceDate)
        {
            CurrencyConversionModel currencyConversionModel = null;

            // create query.
            if (await Any(w => w.CurrencyId == currencyId && w.EffectiveDateTime <= invoiceDate))
            {
                Currencyconversion currencyConversion =
                    await GetQueryByCondition(w => w.CurrencyId == currencyId && w.EffectiveDateTime <= invoiceDate)
                    .Include(w => w.Currency).Include(w => w.Company).Include(w => w.PreparedByUser)
                    .OrderByDescending(w => w.EffectiveDateTime).FirstOrDefaultAsync();

                currencyConversionModel = await AssignValueToModel(currencyConversion);
            }

            return(currencyConversionModel); // returns.
        }
        private async Task <CurrencyConversionModel> AssignValueToModel(Currencyconversion currencyConversion)
        {
            return(await Task.Run(() =>
            {
                CurrencyConversionModel currencyConversionModel = new CurrencyConversionModel();
                currencyConversionModel.ConversionId = currencyConversion.ConversionId;
                currencyConversionModel.CompanyId = currencyConversion.CompanyId;
                currencyConversionModel.CurrencyId = currencyConversion.CurrencyId;
                currencyConversionModel.EffectiveDateTime = currencyConversion.EffectiveDateTime;
                currencyConversionModel.ExchangeRate = currencyConversion.ExchangeRate;
                // ###
                currencyConversionModel.CompanyName = currencyConversion.Company.CompanyName;
                currencyConversionModel.CurrencyName = currencyConversion.Currency.CurrencyName;
                currencyConversionModel.PreparedByName = currencyConversion.PreparedByUser.UserName;

                return currencyConversionModel;
            }));
        }
        public async Task <int> CreateCurrencyConversion(CurrencyConversionModel currencyConversionModel)
        {
            int currencyConversionId = 0;

            // assign values.
            Currencyconversion currencyConversion = new Currencyconversion();

            currencyConversion.ConversionId      = currencyConversionModel.ConversionId;
            currencyConversion.CompanyId         = currencyConversionModel.CompanyId;
            currencyConversion.CurrencyId        = currencyConversionModel.CurrencyId;
            currencyConversion.EffectiveDateTime = currencyConversionModel.EffectiveDateTime;
            currencyConversion.ExchangeRate      = currencyConversionModel.ExchangeRate;
            await Create(currencyConversion);

            currencyConversionId = currencyConversion.ConversionId;

            return(currencyConversionId); // returns.
        }
        public async Task <JsonResult> GetExchangeRateByCurrencyId(int currencyId, DateTime invoiceDate)
        {
            JsonData <JsonStatus> data = new JsonData <JsonStatus>(new JsonStatus());

            CurrencyConversionModel currencyConversionModel = await
                                                              _currencyConversion.GetExchangeRateByCurrencyId(currencyId, invoiceDate);

            if (null != currencyConversionModel)
            {
                data.Result.Status = true;
                data.Result.Data   = currencyConversionModel.ExchangeRate;
            }
            else
            {
                data.Result.Data = "0";
            }

            return(Json(data)); // returns.
        }
        public IActionResult ShowResultCurrencyConversion(CurrencyConversionModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("FormOfCurrencyConversion", model));
            }
            if (!_currencyNameChecker.CheckingIfCurrencyNamesAreDifferent(model.FirstCurrency, model.SecondCurrency))
            {
                ViewBag.ResultChekingCurrencyNameInConversion = "Currencies name must different";
                return(View("FormOfCurrencyConversion", model));
            }
            if (!_dateChecker.CheckingIfDateExistsForTwoCurrencies(model.Date, model.FirstCurrency, model.SecondCurrency))
            {
                ViewBag.DateRangeForConversion = _dateRange.GetDateRangeTwoCurrencies(model.FirstCurrency, model.SecondCurrency);

                return(View("FormOfCurrencyConversion", model));
            }
            return(View(_currencyConversionService.CalculateAmountForCurrencyConversion(model)));
        }
Beispiel #12
0
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            if (Date.Text.Equals(string.Empty))
            {
                MessageBox.Show("Date can not be blank!");
                return;
            }

            CurrencyConversionModel objcurconv = new CurrencyConversionModel();

            objcurconv.Date = Convert.ToDateTime(Date.Text.Trim());

            bool isSuccess = objCurcov.SaveCurrencyconversion(objcurconv);

            if (isSuccess)
            {
                MessageBox.Show("Saved Successfully!");
            }
        }
Beispiel #13
0
        public async Task <IActionResult> ShowResultCurrencyConversion(CurrencyConversionModel model)
        {
            ViewData["currencyCodes"] = await _currenciesSelectList.GetCurrencyCodes(User.Identity.Name);

            if (!ModelState.IsValid)
            {
                return(View("FormOfCurrencyConversion", model));
            }
            if (!_currencyNameChecker.AreDifferent(model.FirstCurrency, model.SecondCurrency))
            {
                ViewBag.NameErrorInfo = "Currencies name must different";
                return(View("FormOfCurrencyConversion", model));
            }
            if (!(await _dateChecker.CheckIfDateExistsForTwoCurrencies(model.Date, model.FirstCurrency, model.SecondCurrency)))
            {
                ViewBag.CommonDateRangeInfo = await _dateRange.GetCommonDateRangeForTwoCurrencies(model.FirstCurrency, model.SecondCurrency);

                return(View("FormOfCurrencyConversion", model));
            }
            return(View(await _currencyConversionService.CalculateCurrencyConversionAmount(model)));
        }
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            CurrencyConversionModel objcurconv = new CurrencyConversionModel();

            objcurconv.Date = Convert.ToDateTime(dtDate.Text.Trim());
            CurrencyConversionDetailsModel        objCurrency;
            List <CurrencyConversionDetailsModel> lstCurrency = new List <CurrencyConversionDetailsModel>();

            for (int i = 0; i < dvgCurrencyConvDetails.DataRowCount; i++)
            {
                DataRow row = dvgCurrencyConvDetails.GetDataRow(i);

                objCurrency              = new CurrencyConversionDetailsModel();
                objCurrency.Currency     = row["Currency"].ToString();
                objCurrency.StandardRate = Convert.ToDecimal(row["TandardRate"].ToString());
                objCurrency.SellingRate  = Convert.ToDecimal(row["SellingRate"].ToString());
                objCurrency.BuyingRate   = Convert.ToDecimal(row["BuyingRate"].ToString());
                if (Con_Id != 0)
                {
                    objCurrency.id       = Convert.ToInt32(row["id"].ToString() == string.Empty?"0":row["id"].ToString());
                    objCurrency.ParentId = Convert.ToInt32(row["ParentId"].ToString() == string.Empty?"0": row["ParentId"].ToString());
                }
                lstCurrency.Add(objCurrency);
            }
            objcurconv.CurrenyDetails = lstCurrency;
            objcurconv.CcID           = Con_Id;
            bool isSuccess = objConBal.UpdateCurrencyconversion(objcurconv);

            if (isSuccess)
            {
                MessageBox.Show("Update Successfully!");
                ClearFormValues();
                Con_Id = 0;
                Administration.List.CurrencyconversionList frmList = new Administration.List.CurrencyconversionList();
                frmList.StartPosition = FormStartPosition.CenterScreen;

                frmList.ShowDialog();
                FillCurrencyConversionInfo();
            }
        }
Beispiel #15
0
        //Get List of Currency Conversions
        public List <CurrencyConversionModel> GetCurrencyConversionbyId(int id)
        {
            List <CurrencyConversionModel> lstCurrCon = new List <CurrencyConversionModel>();
            CurrencyConversionModel        objCurrCon;
            string Query = "SELECT * FROM `currencyconversion` WHERE `CC_Id`=" + id;

            System.Data.IDataReader dr = _dbHelper.ExecuteDataReader(Query, _dbHelper.GetConnObject());

            while (dr.Read())
            {
                objCurrCon = new CurrencyConversionModel();

                objCurrCon.CcID = Convert.ToInt32(dr["CC_Id"]);
                objCurrCon.Date = Convert.ToDateTime(dr["Date"].ToString());

                //SELECT Currency Conversion Details
                string CurrQuery = "SELECT * FROM `currencyconversiondetails` WHERE `CC_Id`=" + id;
                System.Data.IDataReader drConn = _dbHelper.ExecuteDataReader(CurrQuery, _dbHelper.GetConnObject());

                objCurrCon.CurrenyDetails = new List <CurrencyConversionDetailsModel>();
                CurrencyConversionDetailsModel objCurrency;

                while (drConn.Read())
                {
                    objCurrency = new CurrencyConversionDetailsModel();

                    objCurrency.id           = Convert.ToInt32(drConn["Currency_Id"]);
                    objCurrency.ParentId     = Convert.ToInt32(drConn["CC_Id"]);
                    objCurrency.StandardRate = Convert.ToDecimal(drConn["TandardRate"]);
                    objCurrency.SellingRate  = Convert.ToDecimal(drConn["SellingRate"]);
                    objCurrency.BuyingRate   = Convert.ToDecimal(drConn["BuyingRate"]);
                    objCurrency.Currency     = drConn["Currency"].ToString();
                    objCurrCon.CurrenyDetails.Add(objCurrency);
                }

                lstCurrCon.Add(objCurrCon);
            }
            return(lstCurrCon);
        }
Beispiel #16
0
        public async void CurrencyConversionService_is_conversion_correct()
        {
            //Arange
            CurrencyConversionService testService             = CreateCurrencyConversionService();
            CurrencyConversionModel   currencyConversionModel = new CurrencyConversionModel();

            currencyConversionModel.FirstCurrency       = _firstCurrencyName;
            currencyConversionModel.SecondCurrency      = _secondCurrencyName;
            currencyConversionModel.AmountFirstCurrency = 10;
            currencyConversionModel.Date = _commonDate;
            float expectedResult = currencyConversionModel.AmountFirstCurrency * _firstCurrencyCloseValue / _secondCurrencyCloseValue;
            bool  resultFlag     = false;

            //Act
            currencyConversionModel = await testService.CalculateCurrencyConversionAmount(currencyConversionModel);

            if (currencyConversionModel.AmountSecondCurrency == expectedResult)
            {
                resultFlag = true;
            }

            //Asert
            Assert.True(resultFlag);
        }
Beispiel #17
0
        public async Task <CurrencyConversionModel> CalculateCurrencyConversionAmount(CurrencyConversionModel currencyConversionModel)
        {
            CurrencyRecord firstDesiredCurrency = await GetDesiredCurrency(currencyConversionModel.FirstCurrency, currencyConversionModel.Date);

            CurrencyRecord secondDesiredCurrency = await GetDesiredCurrency(currencyConversionModel.SecondCurrency, currencyConversionModel.Date);

            currencyConversionModel.AmountSecondCurrency = currencyConversionModel.AmountFirstCurrency * firstDesiredCurrency.Close / secondDesiredCurrency.Close;

            return(currencyConversionModel);
        }
Beispiel #18
0
        //UPDATE Currency Convresion
        public bool UpdateCurrencyconversion(CurrencyConversionModel objCurcov)
        {
            string Query    = string.Empty;
            bool   isUpdate = true;

            try
            {
                DBParameterCollection paramCollection = new DBParameterCollection();

                paramCollection.Add(new DBParameter("@CurrencyDate", objCurcov.Date, System.Data.DbType.Date));
                paramCollection.Add(new DBParameter("@ModifiedBy", "Admin"));
                paramCollection.Add(new DBParameter("@ParentId", objCurcov.CcID));

                System.Data.IDataReader dr =
                    _dbHelper.ExecuteDataReader("spUpdateCurrencyConversion", _dbHelper.GetConnObject(), paramCollection, System.Data.CommandType.StoredProcedure);

                List <CurrencyConversionDetailsModel> lstConn = new List <CurrencyConversionDetailsModel>();

                //UPDATE Currency Conversion Grid
                foreach (CurrencyConversionDetailsModel conver in objCurcov.CurrenyDetails)
                {
                    if (conver.id > 0)
                    {
                        paramCollection = new DBParameterCollection();

                        paramCollection.Add(new DBParameter("@ParentId", (conver.ParentId)));
                        paramCollection.Add(new DBParameter("@Currency", (conver.Currency)));
                        paramCollection.Add(new DBParameter("@TandardRate", conver.StandardRate, System.Data.DbType.Decimal));
                        paramCollection.Add(new DBParameter("@SellingRate", conver.SellingRate, System.Data.DbType.Decimal));
                        paramCollection.Add(new DBParameter("@BuyingRate", conver.BuyingRate, System.Data.DbType.Decimal));
                        paramCollection.Add(new DBParameter("@ModifiedBy", "Admin"));
                        paramCollection.Add(new DBParameter("@CurrencyId", conver.id));

                        System.Data.IDataReader drcurr =
                            _dbHelper.ExecuteDataReader("spUpdateCurrencyConversionDetails", _dbHelper.GetConnObject(), paramCollection, System.Data.CommandType.StoredProcedure);
                    }
                    else
                    {
                        paramCollection = new DBParameterCollection();

                        paramCollection.Add(new DBParameter("@ParentId", (objCurcov.CcID)));
                        paramCollection.Add(new DBParameter("@Currency", (conver.Currency)));
                        paramCollection.Add(new DBParameter("@TandardRate", conver.StandardRate, System.Data.DbType.Decimal));
                        paramCollection.Add(new DBParameter("@SellingRate", conver.SellingRate, System.Data.DbType.Decimal));
                        paramCollection.Add(new DBParameter("@BuyingRate", conver.BuyingRate, System.Data.DbType.Decimal));
                        paramCollection.Add(new DBParameter("@CreatedBy", "Admin"));
                        //paramCollection.Add(new DBParameter("@CreatedDate", DateTime.Now));

                        System.Data.IDataReader drcurr =
                            _dbHelper.ExecuteDataReader("spInsertCurrencyConversionDetails", _dbHelper.GetConnObject(), paramCollection, System.Data.CommandType.StoredProcedure);
                    }
                }
                isUpdate = true;
            }
            catch (Exception ex)
            {
                isUpdate = false;
                throw ex;
            }

            return(isUpdate);
        }