Exemple #1
0
        public async Task <JsonResult> AddState(CreateStateViewModel csvm)
        {
            var data   = "State Added Failed !";
            var status = false;

            try
            {
                var firebase  = FirebaseConnection.FirebaseDatabase();
                var stateList = await firebase.Child("state").OnceAsync <GetStateViewModel>();

                foreach (var stateDetail in stateList)
                {
                    if (stateDetail.Object.stateName.Equals(csvm.stateName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        data = "State Name Already Exist !";
                        return(Json(new { data = data, status = status }, JsonRequestBehavior.AllowGet));
                    }
                }
                csvm.stateName = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(csvm.stateName.ToLower().Trim());
                var stateAdded = await firebase.Child("state").PostAsync(csvm, true);

                data   = "State Added Successfully !";
                status = true;
            }
            catch (Exception stateAddException)
            {
                var stateError = stateAddException.GetType().GetProperty("Reason").GetValue(stateAddException, null);
            }
            return(Json(new { data = data, status = status }, JsonRequestBehavior.AllowGet));
        }
Exemple #2
0
        public IActionResult Create()
        {
            var vm = new CreateStateViewModel()
            {
                CountriesList = _countryService.GetCountries().
                                Select(x => new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem {
                    Text    = x.Name
                    , Value = x.Id.ToString()
                })
            };

            return(View(vm));
        }
Exemple #3
0
        public ActionResult Create(CreateStateViewModel createStateViewModel)
        {
            if (ModelState.IsValid)
            {
                var client = new RestClient();

                var request  = new RestRequest("http://localhost:5000/api/states", DataFormat.Json);
                var urlPhoto = UploadPhotoFriend(createStateViewModel.PhotoFile);
                createStateViewModel.Flag = urlPhoto;
                request.AddJsonBody(createStateViewModel);
                var response = client.Post <CreateStateViewModel>(request);
                return(Redirect("/state/index"));
            }
            return(BadRequest());
        }
Exemple #4
0
        public ActionResult Create(CreateStateViewModel state)
        {
            if (ModelState.IsValid)
            {
                var urlPhoto = UploadPhoto(state.Photo);
                state.UrlPhoto = urlPhoto;

                var client  = new RestClient();
                var request = new RestRequest("http://localhost:63454/api/states/", DataFormat.Json);
                request.AddJsonBody(state);
                var response = client.Post <CreateStateViewModel>(request);

                return(Redirect("/state/index"));
            }
            return(BadRequest());
        }
Exemple #5
0
        public ActionResult Edit(int id, CreateStateViewModel state)
        {
            try
            {
                if (state.Photo != null)
                {
                    var urlPhoto = UploadPhoto(state.Photo);
                    state.UrlPhoto = urlPhoto;
                }

                var client  = new RestClient();
                var request = new RestRequest("http://localhost:63454/api/states/" + id, DataFormat.Json);
                request.AddJsonBody(state);

                var response = client.Put <CreateStateViewModel>(request);
                return(Redirect("/state/index"));
            }
            catch
            {
                return(View());
            }
        }