/// <summary> /// Save the currency (new or edited) /// </summary> /// <param name="model">The currency details (model)</param> /// <returns></returns> // POST: /Administration/CurrencySave public ActionResult CurrencySave(MODEL.Currency model) { try { bool ismodelValid = ModelState.IsValid; if (!ismodelValid) { ismodelValid = IsModelValidForMultilineTextbox("Description", model.Description, 25); if (ismodelValid) { model.Description = model.Description.Replace("\r\n", "\n"); } } if (ismodelValid) { //Get user id int? userId = Session.GetUserId(); CurrencyService currencyService = new CurrencyService(); //CurrencyVO currencyVO = new CurrencyVO(model, userId); CurrencyVO currencyVO = model.Transpose(userId); currencyService.SaveCurrency(currencyVO); return(new HttpStatusCodeResult(200)); } else { throw new ApplicationException(String.Format(Constants.CANNOT_SAVE, Constants.CURRENCY)); } } catch (Exception e) { return(new HttpStatusCodeAndErrorResult(500, e.Message)); } }
/// <summary> /// Save Currency Details /// </summary> /// <param name="currencyVO">Value Object currencyVO</param> /// <returns></returns> public void SaveCurrency(CurrencyVO currencyVO) { Currency currency = null; if (currencyVO.CurrencyID == 0) { //create new currency currency = new Currency(); currency.CreationDate = DateTime.Now; currency.CreatedBy = currencyVO.CreatedByUserId; } else { //get currency for update currency = mdbDataContext.Currencies.SingleOrDefault(c => c.ID == currencyVO.CurrencyID); currency.LastUpdatedDate = DateTime.Now; currency.LastUpdatedBy = currencyVO.LastUpdatedByUserId; } //Create or update currency details currency.CurrencyName = currencyVO.CurrencyName; currency.Description = currencyVO.Description.Trim().Replace("\r\n", "\n"); currency.ExchangeRate = currencyVO.ExchangeRate; currency.IsActive = currencyVO.IsActive; if (currencyVO.CurrencyID == 0) { //If new currency mdbDataContext.Currencies.InsertOnSubmit(currency); } mdbDataContext.SubmitChanges(); }
/// <summary> /// Transpose currency value object to model object /// </summary> /// <param name="currency">Currency value objet</param> public Currency(CurrencyVO currency) { ID = currency.CurrencyID; CurrencyId = currency.CurrencyID; CurrencyName = currency.CurrencyName; Description = currency.Description; ExchangeRate = currency.ExchangeRate; IsActive = currency.IsActive; }
/// <summary> /// Check whether currency is associated with contract /// </summary> /// <param name="currency">currency object</param> /// <returns></returns> private void IsCurrencyAssociatedWithContract(CurrencyVO currency) { int count = currencyDAL.IsCurrencyAssociatedWithContract(currency); if (count > 0) { throw new ApplicationException(Constants.CURRENCY_CANNOT_BE_INACTIVE); } }
public AmountVO(string currency, string amount) { Currency = new CurrencyVO() { Code = currency }; if (!string.IsNullOrEmpty(amount)) { Value = Convert.ToDecimal(amount, CultureInfo.InvariantCulture); } }
/// <summary> /// Delete selected currency /// </summary> /// <param name="CurrencyId">CurrencyId </param> /// <returns></returns> //public void DeleteCurrency(List<int> Ids) //{ // foreach (var id in Ids) // { // if (id != 0) // { // Currency deleteCurrency = new Currency(); // deleteCurrency = mdbDataContext.Currencies.SingleOrDefault(c => c.ID == id); // deleteCurrency.IsActive = true; // mdbDataContext.SubmitChanges(); // } // } //} /// <summary> /// Get currency details by currency name /// </summary> /// <param name="currencyVO">currency value object</param> /// <returns>return currency details</returns> public CurrencyVO GetCurrencyByName(string currencyName) { Currency currency = mdbDataContext.Currencies.Where(cur => cur.CurrencyName.Equals(currencyName)).SingleOrDefault(); CurrencyVO currencyVO = null; if (currency != null) { currencyVO = new CurrencyVO(currency); } return(currencyVO); }
/// <summary> /// Get Currency Details by Id /// </summary> /// <param name="Id"> Currency ID</param> /// <returns>Currency Details</returns> public CurrencyVO GetCurrencyById(int Id) { Currency currency = new Currency(); currency = mdbDataContext.Currencies.SingleOrDefault(c => c.ID == Id); CurrencyVO currencyVO = null; if (currency != null) { currencyVO = new CurrencyVO(currency); } return(currencyVO); }
/// <summary> /// Transposer the model object to value object /// </summary> /// <param name="currency"></param> /// <returns></returns> public CurrencyVO Transpose(int?userId) { CurrencyVO currencyVO = new CurrencyVO(); currencyVO.CurrencyID = this.ID; currencyVO.CurrencyName = this.CurrencyName; currencyVO.Description = this.Description.Trim().Replace("\r\n", "\n"); currencyVO.ExchangeRate = this.ExchangeRate; currencyVO.IsActive = this.IsActive; currencyVO.CreatedByUserId = userId; currencyVO.LastUpdatedByUserId = userId; return(currencyVO); }
/// <summary> /// Save currency details /// </summary> /// <param name="currency">The currency object (new or edited)</param> /// <returns></returns> public void SaveCurrency(CurrencyVO currency) { if (!string.IsNullOrEmpty(currency.CurrencyName)) { if (!currency.IsActive) { IsCurrencyAssociatedWithContract(currency); } CurrencyVO currencyExist = currencyDAL.GetCurrencyByName(currency.CurrencyName); //Check whether currency already exist or not if (currencyExist != null && currency.CurrencyID != currencyExist.CurrencyID) { throw new ApplicationException(Constants.CURRENCY_ALREADY_EXIST); } else { currencyDAL.SaveCurrency(currency); } } }
/// <summary> /// Edit currency detail /// </summary> /// <param name="id">The selected currency id</param> /// <returns>The currency index details view</returns> // GET: /Administration/CurrencyEdit public ActionResult CurrencyEdit(int id) { MODEL.Currency currency = null; try { CurrencyService currencyService = new CurrencyService(); //Get currency details CurrencyVO currencyVO = currencyService.GetCurrencyById(id); if (currencyVO == null) { ModelState.AddModelError("", String.Format(Constants.ITEM_NOT_FOUND, Constants.CURRENCY)); } else { currency = new MODEL.Currency(currencyVO); } } catch (Exception e) { ModelState.AddModelError("", e.Message); } return(PartialView("CurrencyDetails", currency)); }
/// <summary> /// Check whether currency is associated with contract /// </summary> /// <param name="currency">currency object</param> /// <returns></returns> public int IsCurrencyAssociatedWithContract(CurrencyVO currency) { int count = mdbDataContext.Contracts.Count(c => c.CurrencyID == currency.CurrencyID && !c.IsDeleted); return(count); }