public async Task <IActionResult> Edit(int id, [Bind("ID,NameTh,NameEn,Abbr,ProjectId,RegisId,RegisDate,CancelDate,FundStatus,MAmcId,PermitUs,CountryFlag,StatusFlag,LastUpdate")] MFund mFund) { if (id != mFund.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(mFund); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MFundExists(mFund.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["MAmcId"] = new SelectList(_context.MAmc, "ID", "NameEn", mFund.MAmcId); return(View(mFund)); }
public static List <MFund> List() { List <MFund> lisQuery = new List <MFund>(); using (SqlConnection con = new SqlConnection(ConnectionDB.GetConnectionString())) { try { SqlCommand cmd = new SqlCommand("sp_Fund_Lis", con); cmd.CommandTimeout = 0; cmd.CommandType = CommandType.StoredProcedure; con.Open(); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { MFund entRow = new MFund(); entRow.FundId = Convert.ToInt32(reader["FundId"]); entRow.FundCode = Convert.ToString(reader["FundCode"]); entRow.Description = Convert.ToString(reader["Description"]); lisQuery.Add(entRow); } } con.Close(); } catch (Exception ex) { lisQuery = null; } } return(lisQuery); }
public async Task <IActionResult> Create([Bind("ID,NameTh,NameEn,Abbr,ProjectId,RegisId,RegisDate,CancelDate,FundStatus,MAmcId,PermitUs,CountryFlag,StatusFlag,LastUpdate")] MFund mFund) { if (ModelState.IsValid) { _context.Add(mFund); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["MAmcId"] = new SelectList(_context.MAmc, "ID", "NameEn", mFund.MAmcId); return(View(mFund)); }
public BaseResponse InsertFund([FromBody] FundsRequest request) { BaseResponse response = new BaseResponse(); using (TransactionScope scope = new TransactionScope()) { try { if (!BAplication.ValidateAplicationToken(request.ApplicationToken)) { response.Code = "2"; response.Message = Messages.ApplicationTokenNoAutorize; return(response); } string webRoot = _env.ContentRootPath; string rootPath = _appSettings.Value.rootPath; string ProjectPath = _appSettings.Value.ProjectPath; BaseRequest baseRequest = new BaseRequest(); foreach (MFund model in request.Funds) { MFund fund = new MFund(); fund.FundCode = model.FundCode; fund.Description = model.Description; BFund.Insert(fund); } response.Code = "0"; response.Message = "Success"; scope.Complete(); } catch (Exception ex) { response.Code = "2"; response.Message = ex.Message; scope.Dispose(); } } return(response); }
public static int Insert(MFund ent) { using (SqlConnection con = new SqlConnection(ConnectionDB.GetConnectionString())) { SqlCommand cmd = new SqlCommand("sp_Fund_Ins", con); cmd.CommandTimeout = 0; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@IFuncode", SqlDbType.VarChar).Value = ent.FundCode; cmd.Parameters.Add("@IDescription", SqlDbType.VarChar).Value = ent.Description; con.Open(); cmd.ExecuteNonQuery(); con.Close(); } return(0); }
public ActionResult Register(LoadFundsViewModel model, HttpPostedFileBase imageFile) { JSonResult objResult = new JSonResult(); string response = string.Empty; try { Session objSession = new Session() { UserId = AutenticationManager.GetUser().IdUsuario, }; List <MFund> entList = new List <MFund>(); List <ModelFundResult> entListData = new List <ModelFundResult>(); entListData = (List <ModelFundResult>)Session["ListFunds"]; foreach (ModelFundResult item in entListData) { MFund mFund = new MFund(); mFund.FundCode = item.FundCode; mFund.Description = item.Description; entList.Add(mFund); } response = new WebApiFund().InsertFund(entList, objSession); string statusCode = response.Split('|')[0]; string statusMessage = response.Split('|')[1]; objResult.isError = statusCode.Equals("2"); objResult.message = string.Format(MessageResource.SaveSuccess, "Funds");; } catch (Exception ex) { objResult.message = string.Format(MessageResource.SaveError + "Error :" + ex.Message, "Funds"); } return(Json(objResult)); }
public async Task <IActionResult> UpdateFromApi([Bind("QueryAmc")] string queryAmc) { if (string.IsNullOrEmpty(queryAmc)) { queryAmc = "0"; } var mamcId = await _context.MAmc.FirstOrDefaultAsync(x => x.UniqueId == queryAmc); if (mamcId != null) { var client = new HttpClient(); var queryString = HttpUtility.ParseQueryString(string.Empty); var key = _configuration.GetSection("SecSubscriptionKey").GetSection("FundFactSheet").Value.ToString(); var uri = "https://api.sec.or.th/FundFactsheet/fund/amc/" + queryAmc + "?" + queryString; // Request headers client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", key); var response = await client.GetAsync(uri); if (response.StatusCode == System.Net.HttpStatusCode.OK) { var jsonString = await client.GetStringAsync(uri); List <FundsModel> listJsonObject = JsonConvert.DeserializeObject <List <FundsModel> >(jsonString); foreach (FundsModel element in listJsonObject) { var fund = await _context.MFund.FirstOrDefaultAsync(m => m.ProjectId == element.proj_id); if (fund == null) { fund = new MFund() { ProjectId = element.proj_id, RegisId = element.regis_id, NameTh = element.proj_name_th, NameEn = element.proj_name_en, Abbr = element.proj_abbr_name, FundStatus = element.fund_status, PermitUs = element.permit_us_investment, MAmcId = mamcId.ID }; if (DateTime.TryParse(element.regis_date, out DateTime tempDT)) { fund.RegisDate = tempDT; } if (DateTime.TryParse(element.cancel_date, out tempDT)) { fund.CancelDate = tempDT; } if (int.TryParse(element.invest_country_flage, out int tempCF)) { fund.CountryFlag = tempCF; } _context.Add(fund); } else { fund.ProjectId = element.proj_id; fund.RegisId = element.regis_id; fund.NameTh = element.proj_name_th; fund.NameEn = element.proj_name_en; fund.Abbr = element.proj_abbr_name; fund.FundStatus = element.fund_status; fund.PermitUs = element.permit_us_investment; fund.MAmcId = mamcId.ID; fund.LastUpdate = DateTime.Now; if (DateTime.TryParse(element.regis_date, out DateTime tempDT)) { fund.RegisDate = tempDT; } if (DateTime.TryParse(element.cancel_date, out tempDT)) { fund.CancelDate = tempDT; } if (int.TryParse(element.invest_country_flage, out int tempCF)) { fund.CountryFlag = tempCF; } _context.Update(fund); } await _context.SaveChangesAsync(); } } } return(RedirectToAction(nameof(Index))); }