コード例 #1
0
        public IActionResult Create(CountryViewModel model)
        {
            //Validate the model
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            try
            {
                Country country = new Country()
                {
                    Name = model.Name
                };

                _countryRepository.Create(country);


                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View(model));
            }
        }
コード例 #2
0
        public void Add(CountryDto countryDto)
        {
            if (countryDto == null)
            {
                throw new ArgumentException("There was not received country to save");
            }

            var city          = _cityRepository.GetByName(countryDto.Capital.Name);
            var region        = _regionRepository.GetByName(countryDto.Region.Name);
            var countryFromDb = _countryRepository.GetByCode(countryDto.Code);

            if (city != null && countryFromDb == null)
            {
                countryDto.CityId  = city.Id;
                countryDto.Capital = null;
            }

            if (region != null && countryFromDb == null)
            {
                countryDto.RegionId = region.Id;
                countryDto.Region   = null;
            }

            if (countryFromDb != null)
            {
                Update(countryDto, countryFromDb);
            }
            else
            {
                var country = _mapper.Map <Country>(countryDto);
                _countryRepository.Create(country);
            }
        }
コード例 #3
0
        public ActionResult Create(CreateCountryViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                var Country   = _mapper.Map <Country>(model);
                var isSuccess = _countryRepository.Create(Country);
                if (!isSuccess)
                {
                    return(View(model));
                }


                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                ModelState.AddModelError("", "در ثبت اطلاعات مشکلی به وجود آمده است");
                return(View(model));
            }
        }
        public async Task <IActionResult> Create([FromBody] CountryCreateDTO countryDTO)
        {
            try
            {
                if (countryDTO == null)
                {
                    return(BadRequest(ModelState));
                }
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                var country   = _mapper.Map <Country>(countryDTO);
                var isSuccess = await _countryRepository.Create(country);

                if (!isSuccess)
                {
                    return(InternalError($"Creation failed"));
                }
                return(Created("Create", new { country }));
            }
            catch (Exception e)
            {
                return(InternalError($"{e.Message} - {e.InnerException}"));
            }
        }
コード例 #5
0
        public async Task <IActionResult> Create([FromForm] Country country)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError(string.Empty, "One or more fields were invalid.");

                return(View(country));
            }

            var result = await _service.Create(country);

            if (result == ActionMessages.Created)
            {
                return(RedirectToAction(nameof(Index), new { message = $"{country.Name} was successfully created!" }));
            }
            else if (result == ActionMessages.FillAllFields)
            {
                ModelState.AddModelError(string.Empty, "Not all fields were filled correctly.");

                return(View(country));
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Unexpected error: The action failed.");

                return(BadRequest(ModelState));
            }
        }
コード例 #6
0
        public IActionResult CreateCountry([FromBody] Country country)
        {
            var errorMessages = new List <string>();

            try
            {
                if (string.IsNullOrEmpty(country.Name_EN))
                {
                    errorMessages.Add("Country name is required");
                    return(BadRequest(new { errors = errorMessages }));
                }

                var newCountry = new Country()
                {
                    Name_EN  = country.Name_EN,
                    Name_FR  = country.Name_FR ?? country.Name_EN,
                    FlagPath = country.FlagPath
                };

                var createdCountry = _countryRepository.Create(newCountry);


                return(Ok(new { createdCountry }));
            }
            catch (Exception ex)
            {
                errorMessages.Add(ex.Message);
                return(BadRequest(new { errors = errorMessages }));
            }
        }
コード例 #7
0
        public async Task <ServiceResponse <Country> > Create(AddCountryRequest request)
        {
            try
            {
                var checkExist = await _countryRepository.FindOneByConditions(c => c.Name.Equals(request.Name, StringComparison.OrdinalIgnoreCase));

                if (checkExist != null)
                {
                    return(new ServiceResponse <Country>($"A Country with name {request.Name} already exist."));
                }


                var country = new Country
                {
                    Code        = $"CNTRY{_codeGenerator.GenerateRandomString(7)}",
                    Name        = request.Name,
                    Description = request.Description
                };

                await _countryRepository.Create(country);

                return(new ServiceResponse <Country>(country));
            }
            catch (Exception ex)
            {
                return(new ServiceResponse <Country>($"An Error Occured While Creating a Country Resource. {ex.Message}"));
            }
        }
コード例 #8
0
        public async Task <ActionResult <Product> > Create([FromBody] Country country)
        {
            await _countryRepository.Create(country);

            var result = await _countryRepository.GetByName(country.Name);

            return(Ok(result));
        }
コード例 #9
0
 public bool Create(Country entity)
 {
     if (Validation(entity, false))
     {
         _countryRepository.Create(entity);
         return(true);
     }
     return(false);
 }
コード例 #10
0
 public ActionResult Create([Bind(Include = "Id,Name,Code")] Country country)
 {
     if (ModelState.IsValid)
     {
         Repository.Create(country);
         return(RedirectToAction("Index"));
     }
     return(View(country));
 }
コード例 #11
0
 public IActionResult Create(Country Country)
 {
     if (ModelState.IsValid)
     {
         countryRepository.Create(Country);
         countryRepository.Commit();
         return(RedirectToAction(nameof(List)));
     }
     return(View(Country));
 }
コード例 #12
0
        public ActionResult <Country> PostCountry([FromBody] Country country)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            countryRepository.Create(country);
            return(CreatedAtAction(nameof(GetCountry), new { id = country.Id }, country));
        }
コード例 #13
0
        public async Task <Country> Create(CountryInputDto countryInputDto)
        {
            var newCountry = new Country(countryInputDto.Name,
                                         new List <Covid19Ranking>
            {
                new Covid19Ranking(countryInputDto.Summary.ActiveCases,
                                   countryInputDto.Summary.RecoveredCases, countryInputDto.Summary.FatalCases, countryInputDto.Summary.RankingPosition)
            });

            return(await _covid19RankingRepository.Create(newCountry));
        }
コード例 #14
0
        public ActionResult <CountryReadDto> Post(CountryCreateDto country)
        {
            var countryModel = _mapper.Map <Country>(country);

            _repository.Create(countryModel);
            _repository.SaveChanges();

            var countryReadDto = _mapper.Map <CountryReadDto>(countryModel);

            return(CreatedAtRoute(nameof(Get), new { Id = countryReadDto.id }, countryReadDto));
        }
コード例 #15
0
        public ActionResult AddCountry([FromBody] Country country)
        {
            if (country == null)
            {
                return(BadRequest());
            }

            _CountryRepository.Create(country);


            return(Ok("kayıt tamamlandı"));
        }
コード例 #16
0
 public IActionResult NewCountry(Country country)
 {
     if (countryRepository.Find(c => c.CountryName.ToLower() == country.CountryName.ToLower()).Any())
     {
         ModelState.AddModelError("CountryName", "This country has already been created");
     }
     if (ModelState.IsValid)
     {
         countryRepository.Create(country);
         return(RedirectToAction(nameof(Index)));
     }
     return(View(country));
 }
コード例 #17
0
        public async Task <IActionResult> Create(Country country)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var newCountry = await _service.Create(country);

            if (newCountry == null)
            {
                return(BadRequest("Something went wrong when creating the city. Please try again"));
            }

            return(Ok(newCountry));
        }
コード例 #18
0
 public IActionResult Create([Bind("Code,Codealpha,Nation,Natione,TelCode,Continent,Territory")] country country)
 {
     if (ModelState.IsValid)
     {
         var result = _countryRepository.Create(country);
         if (result == null)
         {
             SetAlert("Thêm quốc gia không thành công", "error");
         }
         else
         {
             SetAlert("Thêm quốc gia thành công", "success");
         }
         return(RedirectToAction(nameof(Index)));
     }
     return(View(country));
 }
コード例 #19
0
        public CountryViewModel Create(CountryCreateViewModel countryVM)
        {
            var country = countryRep.GetByName(countryVM.Name);

            if (country != null)
            {
                return(null);
            }

            Country add = new Country();

            add.Name = countryVM.Name;
            countryRep.Create(add);
            countryRep.SaveChanges();

            return(new CountryViewModel()
            {
                Id = add.Id,
                Name = add.Name
            });
        }
コード例 #20
0
ファイル: CountryService.cs プロジェクト: Hobinnah/CSRWebAPI
        public async Task <CountryDto> CreateCountry(CountryDto countryDto)
        {
            Country country = new Country();
            IEnumerable <Country> checkCountry = new List <Country>();

            try
            {
                checkCountry = await this.countryRepository.Find(x => x.Name.ToLower().Trim() == countryDto.CountryName.ToLower().Trim());

                if (checkCountry == null || checkCountry.Any())
                {
                    country = this.mapper.Map <Country>(countryDto);
                    country = await countryRepository.Create(country);

                    await countryRepository.Save();

                    cache.Remove(string.Format("{0}", CacheEnum.COUNTRIES.ToString()));
                }
            }
            catch (Exception er) { logger.LogError(string.Format("{0}===================={1}====================\n", DateTime.Now.ToString(), er.ToString())); }

            return(this.mapper.Map <CountryDto>(country));
        }
コード例 #21
0
        public async Task <IActionResult> Create([FromBody] Country toCreate)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                await _countryRepository.Create(toCreate);

                /*if (!await _productRepository.Create(toCreate))
                 * {
                 *  ModelState.AddModelError("", $"Something went wrong saving data");
                 *  return StatusCode(500, ModelState);
                 * } */
                return(CreatedAtRoute("GetCountry", new Country {
                    Id = toCreate.Id
                }, toCreate));
            }
            catch (Exception E)
            {
                return(StatusCode(500, E.Message));
            }
        }
コード例 #22
0
 public Country Create(Country newCountry)
 {
     ValidateCreate(newCountry);
     return(_countryRepository.Create(newCountry));
 }
コード例 #23
0
 public int Create(CountryVM countryVM)
 {
     return(countryRepository.Create(countryVM));
 }
コード例 #24
0
 public ActionResult Save(CountryDisplayModel country)
 {
     _countryRepository.Create(country);
     return(RedirectToAction("List"));
 }
コード例 #25
0
        public void Execute(CreateCountry message)
        {
            var item = new Country(0, message.Name);

            _repository.Create(item);
        }
コード例 #26
0
 public Country Create(Country country)
 {
     return(_countryRepository.Create(country));
 }
コード例 #27
0
        public void InitData()
        {
            Country country = _countryRepository.Create(new Country()
            {
                Name = "Denmark"
            });

            _countryRepository.Create(new Country()
            {
                Name = "Sweden"
            });
            _countryRepository.Create(new Country()
            {
                Name = "Norway"
            });
            var listCities = new List <City>();

            for (int i = 0; i < 10; i++)
            {
                listCities.Add(new City()
                {
                    ZipCode = 6001 + i,
                    Name    = "osteBy" + i,
                    Country = country
                });
            }
            _cityRepository.CreateAll(listCities);

            var tourist1 = _ctx.Tourists.Add(new TouristSql()
            {
                Name = "John"
            }).Entity;
            var tourist2 = _ctx.Tourists.Add(new TouristSql()
            {
                Name = "Bill"
            }).Entity;
            var tourist3 = _ctx.Tourists.Add(new TouristSql()
            {
                Name = "Bob"
            }).Entity;
            var tourist4 = _ctx.Tourists.Add(new TouristSql()
            {
                Name = "Allan"
            }).Entity;

            _ctx.SaveChanges();

            _ctx.CityTourists.Add(new CityTouristSql()
            {
                CityId = listCities[0].ZipCode, TouristId = tourist1.Id, VisitDate = DateTime.Now
            });
            _ctx.CityTourists.Add(new CityTouristSql()
            {
                CityId = listCities[0].ZipCode, TouristId = tourist2.Id, VisitDate = DateTime.Now.AddYears(-3)
            });
            //_ctx.CityTourists.Add(new CityTourist() {CityId = listCities[2].ZipCode, TouristId = tourist1.Id});
            //_ctx.CityTourists.Add(new CityTourist() {CityId = listCities[1].ZipCode, TouristId = tourist2.Id});
            _ctx.SaveChanges();

            var address = new Address
            {
                Id         = 1,
                StreetName = "Øffgade",
                StreetNr   = 7,
                Additional = "TTL",
                Customers  = new List <Customer>(),
                City       = listCities[0]
            };

            _addressRepository.Create(address);

            /*
             * Customer cust;
             * _customerRepository.Create(
             *  cust = new Customer()
             *  {
             *      Address = address,
             *      FirstName = "John",
             *      LastName = "Bilsson"
             *  });
             * address.Customers.Add(cust);
             * _customerRepository.Create(
             *  cust = new Customer()
             *  {
             *      Address = address,
             *      FirstName = "Bill",
             *      LastName = "Bilbo"
             *  });
             * address.Customers.Add(cust);
             * _customerRepository.Create(
             *  cust = new Customer()
             *  {
             *      Address = address,
             *      FirstName = "Bob",
             *      LastName = "Snurfheit the 3rd"
             *  });
             * address.Customers.Add(cust);
             * _customerRepository.Create(
             *  cust = new Customer()
             *  {
             *      Address = address,
             *      FirstName = "Little",
             *      LastName = "John"
             *  });
             * address.Customers.Add(cust);
             * _customerRepository.Create(
             *  cust = new Customer()
             *  {
             *      Address = address,
             *      FirstName = "Zilbo",
             *      LastName = "Zaggins"
             *  });
             * address.Customers.Add(cust);
             * _customerRepository.Create(
             * cust = new Customer()
             *  {
             *      Address = address,
             *      FirstName = "Aykoniksotytytjiiimsi",
             *      LastName = "OST"
             *  });
             * address.Customers.Add(cust);
             */
        }
コード例 #28
0
        public void CreateCountry(CountryDetails countryDetails)
        {
            var country = Mapper.Map <Country>(countryDetails);

            _countryRepository.Create(country);
        }
コード例 #29
0
 public void Create(Country entity)
 {
     _CountryRepository.Create(entity);
 }