예제 #1
0
        public ActionResult UpdateCity(string CityID, string kode, string nama, string lstprovince)
        {
            string             userID   = HttpContext.Session.GetString(SessionKeyID);
            EditCityInputModel dataCity = new EditCityInputModel();

            dataCity.UserID       = Guid.Parse(userID);
            dataCity.CityID       = Guid.Parse(CityID);
            dataCity.Kode         = kode;
            dataCity.CityName     = nama;
            dataCity.KodeProvinsi = lstprovince.Split("|")[0].ToString();
            JsonConvert.SerializeObject(dataCity);
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(BaseAPI + "Base/");
                //HTTP POST
                var postTask = client.PostAsJsonAsync <EditCityInputModel>("EditCity", dataCity);
                postTask.Wait();

                var result = postTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    return(RedirectToAction("Index", "City"));
                }
                else
                {
                    TempData["CustomError"] = "Gagal memperbarui data. Mohon hubungi admin.";
                }
            }
            TempData["CustomError"] = "Terjadi kesalahan. Mohon hubungi admin.";
            return(RedirectToAction("Update", "City", new { @id = HttpContext.Session.GetString(SessionKeyEdit) }));
        }
예제 #2
0
        public EditCityOutputModel Update(EditCityInputModel data)
        {
            CityRepository repo = new CityRepository(db);

            City temp = new City();

            var tempKodeProvinsi = Convert.ToInt32(data.KodeProvinsi);

            temp.ID                 = data.CityID;
            temp.CityName           = data.CityName;
            temp.Kode               = Convert.ToInt32(data.Kode);
            temp.KodeProvinsi       = Convert.ToInt32(data.KodeProvinsi);
            temp.ProvinceID         = db.Province.Where(x => x.Kode == tempKodeProvinsi).FirstOrDefault().ID;
            temp.LastUpdateByUserID = data.UserID;
            temp.LastUpdateDate     = DateTime.Now;

            var res = repo.Update(temp);

            EditCityOutputModel output = new EditCityOutputModel();

            output.CityID   = res.ID;
            output.CityName = data.CityName;

            return(output);
        }
예제 #3
0
        public ActionResult <EditCityResponseModel> EditCity([FromBody] EditCityInputModel data)
        {
            EditCityResponseModel res = new EditCityResponseModel();

            try
            {
                CityBL bl   = new CityBL(db);
                var    res2 = bl.Update(data);

                res.data     = res2;
                res.Message  = res.Message;
                res.Response = true;
                return(res);
            }
            catch (Exception ex)
            {
                res.Message  = ex.Message;
                res.Response = false;
                return(res);
            }
        }