public ActionResult Edit([Bind(Include = "RegionId,Name")] Region region)
        {
            if (ModelState.IsValid)
            {
                if (ValidateRegion.AlreadyExistsRegion(region))
                {
                    ModelState.AddModelError(string.Empty, "A região já existe na base de dados.");

                    return(View(region));
                }

                db.Entry(region).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(region));
        }
Exemple #2
0
        public static async Task getRegionList(CQAPIResultData ValidUser, string ctryCode, string regionCD)
        {
            try
            {
                String uriAPI = "https://bkp.cqfutures.com/CQAPI/api/CQBO/region/GetRegionList";

                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(uriAPI);
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Add($"Authorization", $"Bearer " + ValidUser.token);
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    HttpResponseMessage response = await client.GetAsync(uriAPI + "?userId=" + ValidUser.userId + "&Form_Code=DIVDCD&ref_codeID=" + ctryCode);

                    if (response.IsSuccessStatusCode)
                    {
                        var content = await response.Content.ReadAsStringAsync();

                        //Console.WriteLine("Region List");
                        CQAPIRegionList regionRes = JsonConvert.DeserializeObject <CQAPIRegionList>(content);


                        //Console.WriteLine("regionRes totalRecord: " + regionRes.totalRecord);
                        //Console.WriteLine("regionRes.data count: " + regionRes.data.Count);
                        //foreach(var item in regionRes.data)
                        //{
                        //    Console.WriteLine(item.form_CodeID + " || " + item.form_CodeDescription);

                        //}


                        ValidateRegion region = new ValidateRegion();
                        region.SearchRegion(regionRes, regionCD);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex.Message);
                Console.ResetColor();
                throw ex;
            }
        }