Пример #1
0
 public IActionResult Index(CreateCountry createCountry)
 {
     if (ModelState.IsValid)
     {
         _countryService.Add(createCountry);
         return(RedirectToAction(nameof(Index)));
     }
     return(View(_countryService.All()));
 }
Пример #2
0
 public IActionResult Create(CountryForm form)
 {
     if (_sessionManager.User is not null)
     {
         try
         {
             if (ModelState.IsValid)
             {
                 Country c = new Country {
                     Ctry = form.Ctry, ISO = form.ISO, IsEU = form.IsEU
                 };
                 _countryService.Add(c);
                 return(RedirectToAction("index"));
             }
         }
         catch (Exception ex)
         {
             ModelState.AddModelError("", ex.Message);
             //ViewBag.Error = ex.Message;
         }
         return(View());
     }
     else
     {
         return(RedirectToAction("Login", "Auth"));
     }
 }
Пример #3
0
        public IActionResult Create([FromForm] CountryCreateModel entity)
        {
            if (ModelState.IsValid)
            {
                string currentUser = HttpContext?.User?.Identity?.Name;
                if (!String.IsNullOrEmpty(currentUser))
                {
                    try
                    {
                        AuditedEntityMapper <CountryCreateModel> .FillCreateAuditedEntityFields(entity, currentUser);

                        bool statusResult = _countryService.Add(entity);
                        if (statusResult)
                        {
                            return(RedirectToAction(nameof(Index)).WithSuccess(LOCALIZATION_SUCCESS_DEFAULT));
                        }
                        else
                        {
                            return(RedirectToAction(nameof(Index)).WithError(LOCALIZATION_ERROR_DEFAULT));
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError(ex, ex.Message);
                        return(RedirectToAction(nameof(Index)).WithError(ex.Message));
                    }
                }
                else
                {
                    _logger.LogError(LOCALIZATION_ERROR_USER_MUST_LOGIN);
                    return(NotFound().WithError(LOCALIZATION_ERROR_USER_MUST_LOGIN));
                }
            }
            return(View(entity).WithWarning(LOCALIZATION_WARNING_INVALID_MODELSTATE));
        }
Пример #4
0
        public ActionResult <CountryViewModel> Post(CountryViewModel countryViewModel)
        {
            var country = _mapper.Map <CountryDto>(countryViewModel);

            _countryService.Add(country);
            return(Ok(countryViewModel));
        }
Пример #5
0
        private async Task <Country> CreateTestCountry(ServiceFactory serviceFactory)
        {
            ICountryService countryService = serviceFactory.CreateCountryService();
            Guid            countryId      = await countryService.Add(new AddCountry { Name = "Test Country", Abbreviation = "Test Abbreviation" });

            return(await countryService.GetById(countryId));
        }
Пример #6
0
 public void Add(Country ctry)
 {
     if (ctry is null)
     {
         throw new NullReferenceException($"Country Data empty ({where}) (ADD)");
     }
     _globalService.Add(ctry.ToGlobal());
 }
Пример #7
0
 public ActionResult Create(CreateCountryViewModel createCountryViewModel)
 {
     if (ModelState.IsValid)
     {
         _countrysService.Add(createCountryViewModel);
         return(RedirectToAction(nameof(Index)));
     }
     return(View(createCountryViewModel));
 }
Пример #8
0
        public async Task <IActionResult> Create([FromForm] Country country)
        {
            try
            {
                country.NoticeTranslate = JsonSerializer.Deserialize <ICollection <NoticeTranslate> >(country.Notices);
                if (!ModelState.IsValid)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, new Response
                    {
                        Status = "Error",
                        Messages = new Message[] {
                            new Message {
                                Lang_id = 1,
                                MessageLang = "Model state isn't valid!"
                            },
                            new Message {
                                Lang_id = 2,
                                MessageLang = "Состояние модели недействительно!"
                            },
                            new Message {
                                Lang_id = 3,
                                MessageLang = "Model vəziyyəti etibarsızdır!"
                            }
                        }
                    }));
                }
                ValidateModel res = country.Photo.PhotoValidate();
                if (!res.Success)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, res.Response));
                }
                ValidateModel res2 = country.FlagPhoto.PhotoValidate();
                if (!res2.Success)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, res.Response));
                }
                string folder   = Path.Combine("Site", "images", "countries");
                string fileName = await country.Photo.SaveImage(_env.WebRootPath, folder);

                country.Image = fileName;
                fileName      = await country.FlagPhoto.SaveImage(_env.WebRootPath, folder);

                country.BgImage = fileName;
                _countryContext.Add(country);

                foreach (NoticeTranslate item in country.NoticeTranslate)
                {
                    item.CountryId = country.Id;
                    _noticeContext.Add(item);
                }
                return(Ok());
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
            }
        }
Пример #9
0
        public async Task <IActionResult> AddCountry([FromBody] CountryDTO country)
        {
            if (ModelState.IsValid)
            {
                country = await _countryService.Add(country);

                return(Ok(country));
            }
            return(BadRequest(ModelState));
        }
        public void AddTest()
        {
            var count = _memoryDbContext.Countries.Count();
            var countryCreateModel = Builder <CountryCreateModel> .CreateNew().With(c => c.Path = "uniquePath").Build();

            _countryService.Add(countryCreateModel);


            Assert.AreEqual(_memoryDbContext.Countries.Count(), count + 1);
        }
Пример #11
0
        public IActionResult Add(Country country)
        {
            var result = _countryService.Add(country);

            if (result.Success)
            {
                return(Ok());
            }
            return(BadRequest());
        }
Пример #12
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            countryService.Add(new Country()
            {
                Id      = Int32.Parse(tbxId.Text),
                Name    = tbxCountry.Text,
                Capital = tbxCapital.Text
            });

            GV_Refresh();
        }
Пример #13
0
        public virtual ActionResult Create(CountryEditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var id = _countries.Add(model);

            return(RedirectToAction(MVC.Country.Edit(id)));
        }
        public async Task <IActionResult> Add([FromBody] CountryDTO country)
        {
            var outputHandler = await _service.Add(country);

            if (outputHandler.IsErrorOccured)
            {
                return(BadRequest(outputHandler.Message));
            }

            return(Created("", outputHandler.Message));
        }
Пример #15
0
        public async Task <IActionResult> Add(Country country)
        {
            var result = await _countryService.Add(country);

            if (result.Success)
            {
                return(Ok(result));
            }

            return(BadRequest(result));
        }
Пример #16
0
 public ActionResult Create(CreateCountryViewModel createCountry)
 {
     if (ModelState.IsValid)
     {
         _countryService.Add(createCountry); //I'm not sure solving
         return(RedirectToAction(nameof(Index)));
     }
     else
     {
         return(View(createCountry));
     }
 }
Пример #17
0
 public JavaScriptResult Create(CountryViewModel countryvm)
 {
     try
     {
         _countryService.Add(Mapper.Map <Country>(countryvm));
         return(JavaScript($"ShowResult('{"Data saved successfully."}','{"success"}','{"redirect"}','{"."}')"));
     }
     catch (Exception ex)
     {
         return(JavaScript($"ShowResult('{ex.Message}','failure')"));
     }
 }
        public ActionResult Add(CountryModel country)
        {
            if (ModelState.IsValid)
            {
                var countryDTO = _countryMaper.MapBack(country);
                _countryService.Add(countryDTO);

                return(RedirectToAction("List"));
            }
            else
            {
                return(View());
            }
        }
Пример #19
0
        public void CanAdd()
        {
            testContext.RunInTestEnvironment(async(serviceFactory) =>
            {
                //Arrange
                ICountryService countryService = serviceFactory.CreateCountryService();

                //Act
                Guid id = await countryService.Add(new AddCountry {
                    Name = "Test Country", Abbreviation = "Test Abbreviation"
                });

                //Assert
                Assert.NotEqual(id, Guid.Empty);
            });
        }
Пример #20
0
        public IActionResult Post([FromBody] CreateEditViewModel model)
        {
            DataClaim.GetClaim(Request);
            var country = new Country();

            if (model is null)
            {
                return(BadRequest("Country is null."));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            _mapper.Map(model, country);
            _countryProvider.Add(country);
            return(Ok(country));
        }
Пример #21
0
 public IActionResult Create(CountryModel country)
 {
     if (ModelState.IsValid)
     {
         var result = _countryService.Add(country);
         if (result.Status == ResultStatus.Success)
         {
             return(RedirectToAction(nameof(Index)));
         }
         if (result.Status == ResultStatus.Error)
         {
             ModelState.AddModelError("", result.Message);
             return(View(country));
         }
         throw new Exception(result.Message);
     }
     return(View(country));
 }
Пример #22
0
        public ActionResult CreateCountry(CreateCountryViewModel ctyVM)
        {
            if (ModelState.IsValid)
            {
                Country country = _countryService.Add(ctyVM);

                if (country == null)
                {
                    ModelState.AddModelError("msg", "Database Problem");
                    return(View(ctyVM));
                }

                return(RedirectToAction(nameof(ShowCountry)));
            }
            else
            {
                return(View(ctyVM));
            }
        }
Пример #23
0
        public void CanGetByAbbreviation()
        {
            testContext.RunInTestEnvironment(async(serviceFactory) =>
            {
                //Arrange
                ICountryService countryService = serviceFactory.CreateCountryService();
                Guid id = await countryService.Add(new AddCountry {
                    Name = "Test Country", Abbreviation = "Test Abbreviation"
                });
                Assert.NotEqual(id, Guid.Empty);

                //Act
                IEnumerable <Country> countries = await countryService.GetByAbbreviation("Test Abbreviation");

                //Assert
                Assert.NotNull(countries);
                Assert.Single(countries);
            });
        }
Пример #24
0
        public ActionResult Add(Country country)
        {
            if (string.IsNullOrEmpty(country.Name))
            {
                return(Content("error! countryName  is required!"));
            }
            int count = CountryService.LoadEntities(c => c.Name.Equals(country.Name)).Count();

            if (count > 0)
            {
                //已有此记录,不处理
                return(Content("ok"));
            }
            else
            {
                CountryService.Add(country);
                return(Content("ok"));
            }
        }
Пример #25
0
        public void CanDelete()
        {
            testContext.RunInTestEnvironment(async(serviceFactory) =>
            {
                //Arrange
                ICountryService countryService = serviceFactory.CreateCountryService();
                Guid id = await countryService.Add(new AddCountry {
                    Name = "Test Country", Abbreviation = "Test Abbreviation"
                });
                Assert.NotEqual(id, Guid.Empty);
                Country country = await countryService.GetById(id);
                Assert.NotNull(country);

                //Act
                await countryService.Delete(id);

                //Assert
                country = await countryService.GetById(id);
                Assert.Null(country);
            });
        }
Пример #26
0
        public async Task <ActionResult> Post([FromBody] Country country)
        {
            logger.LogInformation($"Call CountryController.Post");
            try
            {
                if (!country.Validate(country))
                {
                    return(new BadRequestObjectResult(ModelState));
                }
                else
                {
                    await _countryService.Add(country);

                    return(new OkResult());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #27
0
        public IActionResult Add([FromBody] CountryForm ctry)
        {
            try
            {
                if (ctry is null)
                {
                    throw new ArgumentNullException("Country Object Empty (ADD)");
                }

                Country ctryo = new Country()
                {
                    ISO = ctry.ISO, Ctry = ctry.Ctry, IsEU = ctry.IsEU
                };
                _clientService.Add(ctryo);
                return(ApiControllerHelper.SendOk(this, new ApiResult <Country>(HttpStatusCode.OK, null, ctryo), true));
            }
            catch (Exception ex)
            {
                return(ApiControllerHelper.SendError(this, ex));
            }
        }
Пример #28
0
 public IActionResult Create(Country country)
 {
     try
     {
         if (country == null)
         {
             _logger.LogError("Create operation failed on Countries table");
             return(BadRequest("Invalid data submited"));
         }
         else
         {
             _logger.LogInformation("Create request successfull on Countries table");
             _countryService.Add(country);
             return(Ok($"Record successfully added {country}"));
         }
     }
     catch (Exception ex)
     {
         //_logger.LogError("Create operation failed on Countries table", ex);
         return(BadRequest($"There was an error trying nto process the request {ex}"));
     }
 }
Пример #29
0
        public void CanUpdate()
        {
            testContext.RunInTestEnvironment(async(serviceFactory) =>
            {
                //Arrange
                ICountryService countryService = serviceFactory.CreateCountryService();
                Guid id = await countryService.Add(new AddCountry {
                    Name = "Test Country", Abbreviation = "Test Abbreviation"
                });
                Assert.NotEqual(id, Guid.Empty);

                //Act
                await countryService.Update(new UpdateCountry {
                    Id = id, Name = "Test Country Edit", Abbreviation = "Test Abbreviation Edit"
                });

                //Assert
                Country country = await countryService.GetById(id);
                Assert.Equal("Test Country Edit", country.Name);
                Assert.Equal("Test Abbreviation Edit", country.Abbreviation);
            });
        }
Пример #30
0
 public void Post([FromBody] Country country)
 {
     logger.LogInformation("Add Country: {country.Code}", country.Code);
     countryService.Add(country);
 }