コード例 #1
0
        public async Task <IActionResult> AddCountry(AddCountryModel model, IFormCollection UploadFlag)
        {
            var    webRoot   = _environment.WebRootPath;
            string countryId = Convert.ToString(UploadFlag["Id"]);
            string storePath = "/images/flags/";
            var    path      = Path.Combine(
                Directory.GetCurrentDirectory(), "wwwroot", "images", "flags",
                UploadFlag.Files[0].FileName);

            using (var stream = new FileStream(path, FileMode.Create))
            {
                await UploadFlag.Files[0].CopyToAsync(stream);
            }



            var countries = new Countries
            {
                Name    = model.Name,
                FlagUrl = storePath + model.UploadFlag.FileName
            };
            await _countriesService.Create(countries);

            return(RedirectToAction("Index", "Countries"));
        }
コード例 #2
0
        public ActionResult AddCountry(AddCountryModel model, int?id)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            using (var _Context = new ApplicationContext())
            {
                // current admin id
                var currentAdmin = _Context.Users.Single(m => m.Email == User.Identity.Name).UserId;

                // if new category
                if (id.Equals(null))
                {
                    // add new category
                    var create = _Context.Country_Details;
                    create.Add(new Country_Details
                    {
                        Country_Name = model.CountryName,
                        Country_Code = model.CountryCode,
                        Added_By     = currentAdmin,
                        Added_Date   = DateTime.Now,
                        IsActive     = true
                    });

                    _Context.SaveChanges();
                }
                // update existing category
                else
                {
                    var update = _Context.Country_Details.Single(m => m.Country_Id == id);
                    model.MaptoModel(update);
                    update.Modified_By   = currentAdmin;
                    update.Modified_Date = DateTime.Now;

                    _Context.SaveChanges();
                }
            }
            return(RedirectToAction("ManageCountry"));
        }
コード例 #3
0
        public static async Task <ErrorModel> AddCountry(string countryName)
        {
            var url     = Links.baseLink + Links.metadata + '/' + Links.countries;
            var payload = new AddCountryModel
            {
                CountryName = countryName
            };
            var token = await GetToken();

            var responseBody = await RestVerbs.Post(url, payload, token);

            if (string.IsNullOrEmpty(responseBody))
            {
                return new ErrorModel {
                           ErrorCode = false, Message = "Landet har inte lagts till", Object = new CountryResponse {
                               CountryId = 0, CountryName = ""
                           }
                }
            }
            ;

            try
            {
                var responseBodyJson = JsonConvert.DeserializeObject <CountryResponse>(responseBody);

                return(new ErrorModel {
                    ErrorCode = true, Message = null, Object = responseBodyJson
                });
            }
            catch (Exception error)
            {
                return(new ErrorModel {
                    ErrorCode = false, Message = error.Message, Object = null
                });
            }
        }
コード例 #4
0
        public IActionResult Create()
        {
            var model = new AddCountryModel();

            return(View(model));
        }