/// <summary> /// Country list loading method. /// </summary> /// <returns>Returns - List of countries</returns> public static List <string> LoadCountryList() { // Initialization List <string> lst = new List <string>(); string line = string.Empty; try { // Initialization string srcFilePath = "Content/files/country_list.txt"; string rootPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase); string fullPath = Path.Combine(rootPath, srcFilePath); string filePath = new Uri(fullPath).LocalPath; StreamReader sr = new StreamReader(new FileStream(filePath, FileMode.Open, FileAccess.Read)); // Read file. while ((line = sr.ReadLine()) != null) { // Initialization. CountryObj obj = new CountryObj(); string[] info = line.Split(':'); // Setting. obj.CountryCode = info[0].ToString(); obj.CountryName = info[1].ToString(); // Adding. lst.Add(obj.CountryName); } // Closing. sr.Dispose(); sr.Close(); } catch (Exception ex) { throw ex; } return(lst); }
private bool validateForm(CountryObj obj, out string errorMsg) { var sb = new StringBuilder(); var errCount = 0; var exist = repoCoun.AllEager(f => f.COUNTRY_CODE == obj.COUNTRY_CODE).FirstOrDefault(); if (exist != null) { sb.AppendLine("Country Code Already Exist"); errCount++; } if (errCount > 0) { errorMsg = sb.ToString(); return(true); } errorMsg = sb.ToString(); return(false); }
public ActionResult Add(CountryObj model, string m) { if (model.ITBID == 0) { ViewBag.ButtonText = "Save"; } else { ViewBag.ButtonText = "Update"; } BindCombo(); try { menuId = SmartUtil.GetMenuId(m); ViewBag.MenuId = HttpUtility.UrlDecode(m); var errorMsg = ""; if (ModelState.IsValid) { if (model.ITBID > 0) { //using (var txscope = new TransactionScope(TransactionScopeOption.RequiresNew)) //{ var BType = new SM_COUNTRYTEMP() { COUNTRY_CODE = model.COUNTRY_CODE, COUNTRY_CODENO = model.COUNTRY_CODENO, COUNTRY_NAME = model.COUNTRY_NAME, STATUS = open, RECORDID = model.ITBID, USERID = User.Identity.Name, CREATEDATE = DateTime.Now, CURRENCY_CODE = model.CURRENCY_CODE }; repoCounTemp.Insert(BType); if (uow.Save(User.Identity.Name) > 0) { SM_AUTHLIST auth = new SM_AUTHLIST() { CREATEDATE = DateTime.Now, EVENTTYPE = model.STATUS == active ? eventEdit : model.STATUS, MENUID = menuId, //MENUNAME = "", RECORDID = BType.ITBID, STATUS = open, // TABLENAME = "ADMIN_DEPARTMENT", URL = Request.FilePath, USERID = User.Identity.Name, INSTITUTION_ITBID = institutionId, POSTTYPE = Single }; repoAuth.Insert(auth); var rst = uow.Save(User.Identity.Name) > 0 ? true : false; if (rst) { EmailerNotification.SendForAuthorization(menuId, fullName, deptCode, institutionId, "Country Record"); TempData["msg"] = "Record Updated SuccessFully...Authorization Pending."; //return Json(new { RespCode = 0, RespMessage = "Record Created SuccessFully...Authorization Pending." }); return(RedirectToAction("Index", "Country", new { m = m })); //return Json(new { RespCode = 0, RespMessage = "Record Updated SuccessFully...Authorization Pending." }); } else { ViewBag.Message = "Problem Updating Record."; //return Json(new { RespCode = 0, RespMessage = "Record Created SuccessFully...Authorization Pending." }); return(View("Add", new { m = m, id = model.ITBID })); //return Json(new { RespCode = 1, RespMessage = "Problem Updating Record." }); } } // var ret = _repo.PostRole(model, 1); //if (ret != null && ret.RespCode == 0) //{ // model.RoleId = int.Parse(ret.OutputKey.ToString()); // return Json(new { data = model, RespCode = 0, RespMessage = "Record Created Successfully" }); //} } else { var errMsg = ""; if (validateForm(model, out errMsg)) { ViewBag.Message = errMsg; // "Carscheme already Exist."; return(View("Add", model)); } ; var BType = new SM_COUNTRYTEMP() { CURRENCY_CODE = model.CURRENCY_CODE, COUNTRY_CODE = model.COUNTRY_CODE, COUNTRY_CODENO = model.COUNTRY_CODENO, COUNTRY_NAME = model.COUNTRY_NAME, STATUS = open, RECORDID = model.ITBID, USERID = User.Identity.Name, CREATEDATE = DateTime.Now }; repoCounTemp.Insert(BType); if (uow.Save(User.Identity.Name) > 0) { //var controller = ControllerContext.Controller..ToString(); SM_AUTHLIST auth = new SM_AUTHLIST() { CREATEDATE = DateTime.Now, EVENTTYPE = eventInsert, MENUID = menuId, //MENUNAME = "", RECORDID = BType.ITBID, STATUS = open, // TABLENAME = "ADMIN_DEPARTMENT", URL = Request.FilePath, USERID = User.Identity.Name, INSTITUTION_ITBID = institutionId, POSTTYPE = Single }; repoAuth.Insert(auth); var rst = uow.Save(User.Identity.Name) > 0 ? true : false; if (rst) { //newR = 1; EmailerNotification.SendForAuthorization(menuId, fullName, deptCode, institutionId, "Country Record"); TempData["msg"] = "Record Created SuccessFully...Authorization Pending."; //return Json(new { RespCode = 0, RespMessage = "Record Created SuccessFully...Authorization Pending." }); return(RedirectToAction("Index", new { m = m })); //return Json(new { RespCode = 0, RespMessage = "Record Created SuccessFully...Authorization Pending." }); } else { ViewBag.Message = "Problem Updating Record."; //return Json(new { RespCode = 0, RespMessage = "Record Created SuccessFully...Authorization Pending." }); return(View("Add", model)); // return Json(new { RespCode = 1, RespMessage = "Problem Creating Record." }); } } } } // If we got this far, something failed, redisplay form //return Json(new { RespCode = 1, RespMessage = errorMsg }); ViewBag.Message = errorMsg; return(View("Add", model)); } catch (SqlException ex) { ViewBag.Message = "Problem Updating Record."; //return Json(new { RespCode = 0, RespMessage = "Record Created SuccessFully...Authorization Pending." }); return(View("Add", model)); //return Json(new { RespCode = 1, RespMessage = ex.Message }); } catch (Exception ex) { ViewBag.Message = "Problem Updating Record."; //return Json(new { RespCode = 0, RespMessage = "Record Created SuccessFully...Authorization Pending." }); return(View("Add", model)); //return Json(new { RespCode = 1, RespMessage = ex.Message }); } }
/// <summary> /// Convinience method to save a Country Object. /// Important note: DO NOT CALL THIS IN A LOOP! /// </summary> /// <param name="CountryObj"></param> /// <remarks> /// Important note: DO NOT CALL THIS IN A LOOP! /// This method simply instantiates a CountryDBMapper and calls the save method /// </remarks> public static void saveCountry(params Country[] CountryObj) { CountryDBMapper dbm = new CountryDBMapper(); dbm.saveList(CountryObj.ToList()); }