public async Task <ActionResult> Edit(Domain.State.State state) { try { var client = new RestClient(); var id = JsonConvert.DeserializeObject(this.HttpContext.Session.GetString("StateId")); var requestState = new RestRequest("https://localhost:5005/api/state/edit/"); requestState.AddJsonBody(JsonConvert.SerializeObject(new { Id = id, Name = state.Name })); await client.PutAsync <Domain.State.State>(requestState); this.HttpContext.Session.Remove("StateId"); return(RedirectToAction("Index")); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); ModelState.AddModelError("APP_ERROR", "State doesn't exist."); return(View()); } }
public async Task <IdentityResult> UpdateStateAsync(Domain.State.State newState) { if (this.StateRepository.GetAll().Where(x => x.Id == newState.Id).FirstOrDefault() == null) { throw new Exception("State doesn't exists."); } return(await StateRepository.UpdateStateAsync(newState)); }
public async Task <IdentityResult> UpdateStateAsync(Domain.State.State newState) { var oldState = Context.States.FirstOrDefault(x => x.Id == newState.Id); oldState.Name = newState.Name; Context.States.Update(oldState); await this.Context.SaveChangesAsync(); return(IdentityResult.Success); }
public async Task <IdentityResult> CreateStateAsync(Domain.State.State state) { var country = this.Context.Countries.Where(x => x.Name.ToLower().Replace(" ", "") == state.CountryName.ToLower().Replace(" ", "")).FirstOrDefault(); if (country == null) { throw new Exception("Country doesn't exist."); } state.Country = country; this.Context.States.Add(state); await this.Context.SaveChangesAsync(); return(IdentityResult.Success); }
public async Task <IdentityResult> Put([FromBody] Domain.State.State state) { return(await this.StateService.UpdateStateAsync(state)); }
public async Task <IdentityResult> CreateStateAsync(Domain.State.State state) { return(await StateRepository.CreateStateAsync(state)); }