コード例 #1
0
        public async Task <IdentityResult> UpdateCountryAsync(Domain.Country.Country newCountry)
        {
            var oldCountry = Context.Countries.FirstOrDefault(x => x.Id == newCountry.Id);

            oldCountry.Name = newCountry.Name;
            using (var transaction = this.Context.Database.BeginTransaction())
            {
                try
                {
                    foreach (var item in oldCountry.States)
                    {
                        item.Country     = oldCountry;
                        item.CountryName = oldCountry.Name;
                        this.Context.States.Update(item);
                    }
                    await this.Context.SaveChangesAsync();

                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                    transaction.Rollback();
                }
            }
            Context.Countries.Update(oldCountry);
            await this.Context.SaveChangesAsync();

            return(IdentityResult.Success);
        }
コード例 #2
0
        public async Task <ActionResult> Edit(Domain.Country.Country country)
        {
            try
            {
                var client = new RestClient();
                var id     = JsonConvert.DeserializeObject(this.HttpContext.Session.GetString("CountryId"));

                var requestCountry = new RestRequest("https://localhost:5005/api/country/edit/");
                requestCountry.AddJsonBody(JsonConvert.SerializeObject(new
                {
                    Id   = id,
                    Name = country.Name
                }));

                await client.PutAsync <Domain.Country.Country>(requestCountry);

                this.HttpContext.Session.Remove("CountryId");

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                ModelState.AddModelError("APP_ERROR", "Country doesn't exist.");
                return(View());
            }
        }
コード例 #3
0
        public async Task <IdentityResult> CreateCountryAsync(Domain.Country.Country country)
        {
            this.Context.Countries.Add(country);
            await this.Context.SaveChangesAsync();

            return(IdentityResult.Success);
        }
コード例 #4
0
 public async Task <IdentityResult> Put([FromBody] Domain.Country.Country country)
 {
     return(await this.CountryService.UpdateCountryAsync(country));
 }