public ActionResult Create(Exchange_Rate model) { try { ViewBag.country = dbcontext.Currency.ToList().Select(m => new { Code = m.Code + "------[" + m.Name + ']', ID = m.ID }); if (ModelState.IsValid) { Exchange_Rate record = new Exchange_Rate(); record.CurrencyID = model.CurrencyID; record.Currency = dbcontext.Currency.FirstOrDefault(m => m.ID == model.CurrencyID); record.Year = model.Year; record.months = model.months; dbcontext.Exchange_Rate.Add(record); dbcontext.SaveChanges(); //=================================check for alert================================== var get_result_check = HR.Controllers.check.check_alert("exchange rate", HR.Models.user.Action.Create, HR.Models.user.type_field.form); if (get_result_check != null) { var inbox = new Models.user.Alert_inbox { send_from_user_id = User.Identity.Name, send_to_user_id = get_result_check.send_to_ID_user, title = get_result_check.Subject, Subject = get_result_check.Message }; if (get_result_check.until != null) { if (get_result_check.until.Value.Year != 0001) { inbox.until = get_result_check.until; } } ApplicationDbContext dbcontext = new ApplicationDbContext(); dbcontext.Alert_inbox.Add(inbox); dbcontext.SaveChanges(); } //=================================================================================== return(RedirectToAction("Index")); } else { return(View(model)); } } catch (DbUpdateException) { TempData["Message"] = HR.Resource.Basic.thiscodeIsalreadyexists; return(View(model)); } catch (Exception e) { return(View(model)); } }
public ActionResult Create() { ViewBag.country = dbcontext.Currency.ToList().Select(m => new { Code = m.Code + "------[" + m.Name + ']', ID = m.ID }); var model = new Exchange_Rate() { Year = 1990, months = new List <months>() }; DateTime now = DateTime.Now; for (int i = 0; i < 12; i++) { model.months.Add(new months { Name = now.ToString("MMM"), value = 0 }); now = now.AddMonths(1); } return(View(model)); }
public int SaveExcel(string path) { XlsFile myFile = new XlsFile(path); myFile.ActiveSheet = 1; int rowCount = myFile.RowCount; int colCount = myFile.ColCount; //get from excel sheets int from_currency_id_ = 0; int to_currency_id_ = 0; decimal newrate = 0; string yyyymmdd = string.Empty; int updated_record_count = 0; for (int i = 2; i <= rowCount; i++) { //for (int j = 1; j <= colCount; j++) //{ if (myFile.GetCellValue(i, 1) == null) { break; } from_currency_id_ = GetCurrencyId(myFile.GetCellValue(i, 1).ToString()); to_currency_id_ = GetCurrencyId(myFile.GetCellValue(i, 3).ToString()); newrate = CheckDecimal(myFile.GetCellValue(i, 5).ToString()); yyyymmdd = GetDateTime(myFile.GetCellValue(i, 6).ToString()); if (from_currency_id_.Equals(0) || to_currency_id_.Equals(0) || yyyymmdd.Equals("0") || newrate.Equals(0)) goto skipSave; updated_record_count++; //update the old data var updateOld = from ord in db.Exchange_Rate where ord.from_currency_id == from_currency_id_ && ord.to_currency_id == to_currency_id_ && ord.end_date == "9999/12/31" select ord; foreach (Exchange_Rate ord in updateOld) { ord.end_date = yyyymmdd; } db.SaveChanges(); //adding a new record Exchange_Rate myDm = new Exchange_Rate(); myDm.from_currency_id = from_currency_id_; myDm.to_currency_id = to_currency_id_; myDm.month_id = 1; myDm.exchange_rate1 = newrate; myDm.start_date = yyyymmdd; myDm.end_date = "9999/12/31"; db.Exchange_Rate.Add(myDm); db.SaveChanges(); skipSave: continue; //} } return updated_record_count; }