private async Task <bool> CurrencyVMExists(int id) { if (id == 0) { return(false); } CurrencyVM currencyVM = new CurrencyVM(); HttpClient client = _helperAPI.InitializeClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token")); HttpResponseMessage res = await client.GetAsync("api/Currencies/" + id); if (res.IsSuccessStatusCode) { var result = res.Content.ReadAsStringAsync().Result; currencyVM = JsonConvert.DeserializeObject <CurrencyVM>(result); } if (currencyVM == null) { return(false); } return(true); //return _context.CurrencyVM.Any(e => e.CurrencyId == id); }
public Task <int> InsertAsync(CurrencyVM entity) { return(Task.Run <int>(() => { Currency cur = new Currency() { AddedBy = entity.AddedBy, AddedOn = entity.AddedOn, CURRENCY_AR_NAME = entity.CURRENCY_AR_NAME, CURRENCY_CODE = entity.CURRENCY_CODE, CURRENCY_EN_NAME = entity.CURRENCY_EN_NAME, CURRENCY_FIXED_RATE = entity.CURRENCY_FIXED_RATE, CURRENCY_ID = entity.CURRENCY_ID, CURRENCY_RATE = entity.CURRENCY_RATE, CURRENCY_SUB_AR_NAME = entity.CURRENCY_SUB_AR_NAME, CURRENCY_SUB_EN_NAME = entity.CURRENCY_SUB_EN_NAME, CURRENCY_SYMBOL_AR_NAME = entity.CURRENCY_SYMBOL_AR_NAME, CURRENCY_SYMBOL_EN_NAME = entity.CURRENCY_SYMBOL_EN_NAME, Disable = entity.Disable, SUB_TO_CURRENCY_TRANS = entity.SUB_TO_CURRENCY_TRANS, UpdatedBy = entity.UpdatedBy, updatedOn = entity.updatedOn, DefaultCurrency = entity.DefaultCurrency }; currencyRepo.Add(cur); int id = cur.CURRENCY_ID; return id; })); }
public bool Delete(CurrencyVM entity) { Currency cur = new Currency() { AddedBy = entity.AddedBy, AddedOn = entity.AddedOn, CURRENCY_AR_NAME = entity.CURRENCY_AR_NAME, CURRENCY_CODE = entity.CURRENCY_CODE, CURRENCY_EN_NAME = entity.CURRENCY_EN_NAME, CURRENCY_FIXED_RATE = entity.CURRENCY_FIXED_RATE, CURRENCY_ID = entity.CURRENCY_ID, CURRENCY_RATE = entity.CURRENCY_RATE, CURRENCY_SUB_AR_NAME = entity.CURRENCY_SUB_AR_NAME, CURRENCY_SUB_EN_NAME = entity.CURRENCY_SUB_EN_NAME, CURRENCY_SYMBOL_AR_NAME = entity.CURRENCY_SYMBOL_AR_NAME, CURRENCY_SYMBOL_EN_NAME = entity.CURRENCY_SYMBOL_EN_NAME, Disable = entity.Disable, SUB_TO_CURRENCY_TRANS = entity.SUB_TO_CURRENCY_TRANS, UpdatedBy = entity.UpdatedBy, updatedOn = entity.updatedOn }; currencyRepo.Delete(cur, entity.CURRENCY_ID); return(true); }
public async Task <ActionResult <CurrencyVM> > UpdateCurrency(int id, CurrencyVM currencyVM) { try { if (id != currencyVM.Currency.Id) { return(BadRequest("Currency ID mismatch")); } // Add custom model validation error Currency currency = await currencyRepository.GetCurrencyByname(currencyVM.Currency); if (currency != null) { ModelState.AddModelError("Name", $"Currency name: {currencyVM.Currency.Name} already in use"); return(BadRequest(ModelState)); } var currencyToUpdate = await currencyRepository.GetCurrency(id); if (currencyToUpdate == null) { return(NotFound($"Currency with Id = {id} not found")); } await currencyRepository.UpdateCurrency(currencyVM); return(CreatedAtAction(nameof(GetCurrency), new { id = currencyVM.Currency.Id }, currencyVM)); } catch (DbUpdateException Ex) { return(StatusCode(StatusCodes.Status500InternalServerError, Ex.InnerException.Message)); } }
public async Task <ActionResult <CurrencyVM> > CreateCurrency(CurrencyVM currencyVM) { try { if (currencyVM == null) { return(BadRequest()); } // Add custom model validation error Currency currency = await currencyRepository.GetCurrencyByname(currencyVM.Currency); if (currency != null) { ModelState.AddModelError("Name", $"Currency name: {currencyVM.Currency.Name} already in use"); return(BadRequest(ModelState)); } currencyVM = await currencyRepository.CreateCurrency(currencyVM); return(CreatedAtAction(nameof(GetCurrency), new { id = currencyVM.Currency.Id }, currencyVM)); } catch (DbUpdateException Ex) { return(StatusCode(StatusCodes.Status500InternalServerError, Ex.InnerException.Message)); } }
public List <CurrencyVM> GetAllCurrencies() { try { var currencyData = unitOfWork.TblCurrencyRepository.Get().ToList(); List <CurrencyVM> currencyList = new List <CurrencyVM>(); foreach (var currency in currencyData) { CurrencyVM currencyVM = new CurrencyVM(); currencyVM.CurrencyID = currency.CurrencyID; currencyVM.CountryID = currency.CountryID; currencyVM.CurrencyName = currency.CurrencyName; currencyVM.CurrencyCode = currency.CurrencyCode; currencyVM.BUID = (int)currency.BUID; currencyList.Add(currencyVM); } return(currencyList); } catch (Exception ex) { throw; } }
public string AddCurrency(CurrencyVM currency) { string currencyId = string.Empty; SqlParameter[] parameters = { new SqlParameter { ParameterName = "@Code", Value = currency.Code }, new SqlParameter { ParameterName = "@Name", Value = currency.Name }, new SqlParameter { ParameterName = "@Description", Value = currency.Description }, new SqlParameter { ParameterName = "@ConversionRate", Value = currency.ConversionRate }, new SqlParameter { ParameterName = "@CurrencySymbol", Value = currency.CurrencySymbol }, new SqlParameter { ParameterName = "@IsActive", Value = currency.IsActive }, new SqlParameter { ParameterName = "@CreatedBy", Value = currency.CreatedBy } }; currencyId = Convert.ToString(DALHelper.ExecuteScalar("AddCurrency", parameters)); return(currencyId); }
public Task <bool> DeleteAsync(CurrencyVM entity) { return(Task.Run <bool>(() => { Currency cur = new Currency() { AddedBy = entity.AddedBy, AddedOn = entity.AddedOn, CURRENCY_AR_NAME = entity.CURRENCY_AR_NAME, CURRENCY_CODE = entity.CURRENCY_CODE, CURRENCY_EN_NAME = entity.CURRENCY_EN_NAME, CURRENCY_FIXED_RATE = entity.CURRENCY_FIXED_RATE, CURRENCY_ID = entity.CURRENCY_ID, CURRENCY_RATE = entity.CURRENCY_RATE, CURRENCY_SUB_AR_NAME = entity.CURRENCY_SUB_AR_NAME, CURRENCY_SUB_EN_NAME = entity.CURRENCY_SUB_EN_NAME, CURRENCY_SYMBOL_AR_NAME = entity.CURRENCY_SYMBOL_AR_NAME, CURRENCY_SYMBOL_EN_NAME = entity.CURRENCY_SYMBOL_EN_NAME, Disable = entity.Disable, SUB_TO_CURRENCY_TRANS = entity.SUB_TO_CURRENCY_TRANS, UpdatedBy = entity.UpdatedBy, updatedOn = entity.updatedOn, DefaultCurrency = entity.DefaultCurrency }; currencyRepo.Delete(cur, entity.CURRENCY_ID); return true; })); }
public Task <List <CurrencyVM> > GetSearchResultAsync(CurrencyVM entity, int pageNum, int pageSize) { return(Task.Run(() => { int rowCount; var q = from ent in currencyRepo.GetPaged <int>(pageNum, pageSize, p => p.CURRENCY_ID, false, out rowCount).Where(x => x.CURRENCY_CODE.Contains(entity.CURRENCY_CODE)) select new CurrencyVM { AddedBy = ent.AddedBy, AddedOn = ent.AddedOn, CURRENCY_AR_NAME = ent.CURRENCY_AR_NAME, CURRENCY_CODE = ent.CURRENCY_CODE, CURRENCY_EN_NAME = ent.CURRENCY_EN_NAME, CURRENCY_FIXED_RATE = ent.CURRENCY_FIXED_RATE, CURRENCY_ID = ent.CURRENCY_ID, CURRENCY_RATE = ent.CURRENCY_RATE, CURRENCY_SUB_AR_NAME = ent.CURRENCY_SUB_AR_NAME, CURRENCY_SUB_EN_NAME = ent.CURRENCY_SUB_EN_NAME, CURRENCY_SYMBOL_AR_NAME = ent.CURRENCY_SYMBOL_AR_NAME, CURRENCY_SYMBOL_EN_NAME = ent.CURRENCY_SYMBOL_EN_NAME, Disable = ent.Disable, SUB_TO_CURRENCY_TRANS = ent.SUB_TO_CURRENCY_TRANS, UpdatedBy = ent.UpdatedBy, updatedOn = ent.updatedOn, DefaultCurrency = entity.DefaultCurrency }; return q.ToList(); })); }
public async Task <IHttpActionResult> update([FromBody] CurrencyVM entity) { var result = await currencyService.UpdateAsync(entity); await LogData(entity.CURRENCY_CODE, entity.CURRENCY_ID.ToString()); return(Ok(result)); }
public CurrencyVM GetCurrencyByCurrencyCode(string code) { Currency currency = currencyRepository.GetSingle(code); CurrencyVM currencyVM = new CurrencyVM(); Mapper.Map(currency, currencyVM); return(currencyVM); }
public async Task <CurrencyVM> GetCurrency(int id) { CurrencyVM currencyVM = new CurrencyVM(); currencyVM.Currency = await appDbContext.Currencys.FirstOrDefaultAsync(e => e.Id == id); return(currencyVM); }
public async Task <CurrencyVM> CreateCurrency(CurrencyVM currencyVM) { var result = await appDbContext.Currencys.AddAsync(currencyVM.Currency); await appDbContext.SaveChangesAsync(); currencyVM.Currency = result.Entity; return(currencyVM); }
// GET: Currency/Details/5 public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } CurrencyVM currencyVM = new CurrencyVM(); HttpClient client = _helperAPI.InitializeClient(); var contentType = new MediaTypeWithQualityHeaderValue("application/json"); client.DefaultRequestHeaders.Accept.Add(contentType); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token")); //var content = new StringContent(JsonConvert.SerializeObject(id), Encoding.UTF8, "application/json"); HttpResponseMessage currencyVMRes = await client.GetAsync("api/Currencies/" + id); if (currencyVMRes.StatusCode == HttpStatusCode.Unauthorized) { ViewBag.Message = "Unauthorized!"; } //Checking the response is successful or not which is sent using HttpClient if (currencyVMRes.IsSuccessStatusCode) { //Storing the response details recieved from web api var result = currencyVMRes.Content.ReadAsStringAsync().Result; //Deserializing the response recieved from web api and storing into the Role list currencyVM = JsonConvert.DeserializeObject <CurrencyVM>(result); } if (currencyVM == null) { return(NotFound()); } return(View(currencyVM)); //if (id == null) //{ // return NotFound(); //} //var currencyVM = await _context.CurrencyVM // .FirstOrDefaultAsync(m => m.CurrencyId == id); //if (currencyVM == null) //{ // return NotFound(); //} //return View(currencyVM); }
public IActionResult CurrencyMaster(CurrencyVM model, int?page) { int pageNumber = page ?? 1; int PageSize = _GeneralService.GetGeneralSettings().PageSize; model.CurrencyList = _CurrencyService.AllCurrenciesList().ToPagedList(pageNumber, PageSize); // We used Currency.ID on view, so it will send null value to Currency.ID // We need to convert null to zero so below line of code is used. model.Currency.ID = Convert.ToInt32(model.Currency.ID); // we do not use Currency.ID on view (which basically used by update function) // than above line of code is not required. // FOR INSERT if (model.Currency.ID == 0) { // Need to remove modeal state of ID else it will give model state invalid error ModelState.Remove("Currency.ID"); // this is because we used hidden field Currency.ID on view, // if we do not use this on view than above line is not required if (ModelState.IsValid) { Currency curr = new Currency { Symbol = model.Currency.Symbol }; model.Currency = _CurrencyService.AddCurrency(curr); TempData["Error"] = "Details Added Successfully."; return(RedirectToAction("CurrencyMaster", new { page = page })); } else { return(View(model)); } } else { // FOR UPDATE if (ModelState.IsValid) { model.Currency = _CurrencyService.UpdateCurrency(model.Currency); TempData["Error"] = "Details Updated Successfully."; return(RedirectToAction("CurrencyMaster", new { page = page })); } else { return(View(model)); } } }
public async Task <IHttpActionResult> add([FromBody] CurrencyVM entity) { var result = await currencyService.InsertAsync(entity); await LogData(entity.CURRENCY_CODE, result.ToString()); if (result != 0) { return(Ok(true)); } return(Ok(false)); }
private async Task <CurrencyVM> CheckDeserialize(HttpResponseWrapper <CurrencyVM> httpResponseWrapper) { CurrencyVM currencyVM = new CurrencyVM(); if (httpResponseWrapper.Success) { currencyVM = await Deserialize <CurrencyVM>(httpResponseWrapper.HttpResponseMessage, defaultJsonSerializerOptions); } else { currencyVM.Exception = await httpResponseWrapper.GetBody(); } return(currencyVM); }
public ActionResult Edit(Guid id) { var currency = currencyRepository.GetCurrencyInfoById(id); CurrencyVM model = new CurrencyVM(); if (currency != null && currency.Count > 0) { model = currency[0]; return(View(model)); } return(RedirectToAction("List")); }
public CurrencyVM GetCurrencyByID(int currencyID) { try { var currencyData = unitOfWork.TblCurrencyRepository.GetByID(currencyID); CurrencyVM currencyVM = new CurrencyVM(); currencyVM.CurrencyID = currencyData.CurrencyID; currencyVM.CountryID = currencyData.CountryID; currencyVM.CurrencyName = currencyData.CurrencyName; currencyVM.CurrencyCode = currencyData.CurrencyCode; return(currencyVM); } catch (Exception ex) { throw; } }
public async Task <IHttpActionResult> delete([FromBody] CurrencyVM entity) { var q1 = billMasterService.getByCurrency(entity.CURRENCY_ID); var q = entryMasterService.getByCurrency(entity.CURRENCY_ID); var q2 = bankService.getByCurrency(entity.CURRENCY_ID); if (q.Count == 0 && q1.Count == 0 && q2.Count == 0) { var result = await currencyService.DeleteAsync(entity); await LogData(entity.CURRENCY_CODE, entity.CURRENCY_ID.ToString()); return(Ok(result)); } else { return(Ok(false)); } //return Ok(await currencyService.DeleteAsync(entity)); }
public async Task <CurrencyVM> UpdateCurrency(CurrencyVM currencyVM) { Currency result = await appDbContext.Currencys .FirstOrDefaultAsync(e => e.Id == currencyVM.Currency.Id); if (result != null) { appDbContext.Entry(result).State = EntityState.Detached; result = mapper.Map(currencyVM.Currency, result); appDbContext.Entry(result).State = EntityState.Modified; await appDbContext.SaveChangesAsync(); return(new CurrencyVM { Currency = result }); } return(null); }
public ActionResult Edit(CurrencyVM v) { CurrencyMaster c = new CurrencyMaster(); c.CurrencyID = v.CurrencyID; c.CurrencyName = v.CurrencyName; c.Symbol = v.Symbol; c.NoOfDecimals = v.NoOfDecimals; c.CountryID = v.CountryID; c.StatusBaseCurrency = v.StatusBaseCurrency; c.MonetaryUnit = v.MonetaryUnit; if (ModelState.IsValid) { db.Entry(c).State = EntityState.Modified; db.SaveChanges(); TempData["SuccessMsg"] = "You have successfully Updated Currency."; return(RedirectToAction("Index")); } return(View()); }
public ActionResult Create(CurrencyVM v) { if (ModelState.IsValid) { CurrencyMaster ob = new CurrencyMaster(); int max = (from d in db.CurrencyMasters orderby d.CurrencyID descending select d.CurrencyID).FirstOrDefault(); if (max == null) { ob.CurrencyID = 1; ob.CurrencyName = v.CurrencyName; ob.Symbol = v.Symbol; ob.NoOfDecimals = v.NoOfDecimals; ob.CountryID = v.CountryID; ob.StatusBaseCurrency = v.StatusBaseCurrency; ob.MonetaryUnit = v.MonetaryUnit; } else { ob.CurrencyID = max + 1; ob.CurrencyName = v.CurrencyName; ob.Symbol = v.Symbol; ob.NoOfDecimals = v.NoOfDecimals; ob.CountryID = v.CountryID; ob.StatusBaseCurrency = v.StatusBaseCurrency; ob.MonetaryUnit = v.MonetaryUnit; } db.CurrencyMasters.Add(ob); db.SaveChanges(); TempData["SuccessMsg"] = "You have successfully added Currency."; return(RedirectToAction("Index")); } return(View()); }
// GET: Currency/Delete/5 public async Task <IActionResult> Delete(int?id) { if (id == null) { return(NotFound()); } CurrencyVM currencyVM = new CurrencyVM(); HttpClient client = _helperAPI.InitializeClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token")); HttpResponseMessage res = await client.GetAsync("api/Currencies/" + id); if (res.IsSuccessStatusCode) { var result = res.Content.ReadAsStringAsync().Result; currencyVM = JsonConvert.DeserializeObject <CurrencyVM>(result); } if (currencyVM == null) { return(NotFound()); } return(View(currencyVM)); //if (id == null) //{ // return NotFound(); //} //var currencyVM = await _context.CurrencyVM // .FirstOrDefaultAsync(m => m.CurrencyId == id); //if (currencyVM == null) //{ // return NotFound(); //} //return View(currencyVM); }
public CurrencyVM GetCurrencyByCountryID(int countryID) { try { var currencyData = unitOfWork.TblCurrencyRepository.Get(x => x.CountryID == countryID).FirstOrDefault(); CurrencyVM currencyVM = new CurrencyVM(); if (currencyData != null) { currencyVM.CurrencyID = currencyData.CurrencyID; currencyVM.CountryID = currencyData.CountryID; currencyVM.CurrencyName = currencyData.CurrencyName; currencyVM.CurrencyCode = currencyData.CurrencyCode; } return(currencyVM); } catch (Exception ex) { throw; } }
public ActionResult Edit(int id) { CurrencyVM c = new CurrencyVM(); ViewBag.country = db.CountryMasters.ToList(); var data = (from d in db.CurrencyMasters where d.CurrencyID == id select d).FirstOrDefault(); if (data == null) { return(HttpNotFound()); } else { c.CurrencyID = data.CurrencyID; c.CurrencyName = data.CurrencyName; c.Symbol = data.Symbol; c.NoOfDecimals = data.NoOfDecimals.Value; c.CountryID = data.CountryID.Value; c.StatusBaseCurrency = data.StatusBaseCurrency.Value; c.MonetaryUnit = data.MonetaryUnit; } return(View(c)); }
public ActionResult Index() { List <CurrencyVM> lst = new List <CurrencyVM>(); var data = db.CurrencyMasters.ToList(); foreach (var item in data) { CurrencyVM c = new CurrencyVM(); c.CurrencyID = item.CurrencyID; c.CurrencyName = item.CurrencyName; c.Symbol = item.Symbol; c.NoOfDecimals = item.NoOfDecimals.Value; c.CountryID = item.CountryID.Value; c.MonetaryUnit = item.MonetaryUnit; c.StatusBaseCurrency = item.StatusBaseCurrency.Value; lst.Add(c); } return(View(lst)); }
public async Task <IActionResult> Create([Bind("CurrencyId,CurrencyName,CurrencySymbol,Description,IsActive,DateAdded,DateUpdated")] CurrencyVM currencyVM) { if (ModelState.IsValid) { HttpClient client = _helperAPI.InitializeClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token")); var content = new StringContent(JsonConvert.SerializeObject(currencyVM), Encoding.UTF8, "application/json"); //Task has been cancelled exception occured here, and Api method never hits while debugging HttpResponseMessage res = client.PostAsync("api/Currencies", content).Result; if (res.IsSuccessStatusCode) { return(RedirectToAction("Index")); } } return(View(currencyVM)); //if (ModelState.IsValid) //{ // _context.Add(currencyVM); // await _context.SaveChangesAsync(); // return RedirectToAction(nameof(Index)); //} //return View(currencyVM); }
/// <summary> /// This method is used to get curreny information by id. /// </summary> /// <param name="currencyId">The currency id.</param> /// <returns>CurrencyVM Object</returns> public static CurrencyVM GetCurrencyInfoById(Guid currencyId) { var currencyInfo = new CurrencyVM(); if (System.Web.HttpContext.Current.Application["CurrencyInfo"] == null) { CurrencyRepository currencyRepository = new CurrencyRepository(); var currencyInfoDetail = currencyRepository.GetCurrencyInfo(); System.Web.HttpContext.Current.Application["CurrencyInfo"] = currencyInfoDetail; } if (System.Web.HttpContext.Current.Application["CurrencyInfo"] != null) { var currencyInfoList = (List <CurrencyVM>)System.Web.HttpContext.Current.Application["CurrencyInfo"]; if (currencyInfoList != null && currencyInfoList.Count > 0) { currencyInfo = currencyInfoList.Where(m => m.Id == currencyId).FirstOrDefault(); } } return(currencyInfo); }
public IActionResult CurrencyMaster(string msg, int?page, int ID) { // For Using Paging we installed X.PagedList.Mvc.Core package. // For more details see link : https://github.com/dncuug/X.PagedList // Using X.PagedList; Namespace is need to call for the usage. int pageNumber = page ?? 1; ViewBag.MsgShow = msg; CurrencyVM model = new CurrencyVM(); model.CurrencyList = _CurrencyService.AllCurrenciesList().ToPagedList(pageNumber, PageSize); if (ID != 0) { var data = _CurrencyService.GetCurrencyByID(ID); Currency Curr = new Currency { ID = data.ID, Symbol = data.Symbol }; model.Currency = Curr; } return(View(model)); }