Exemplo n.º 1
0
        private static void CreateRecord(IStateRepository stateRepository)
        {
            State state = new State
            {
                Country        = "CO",
                Code           = "18",
                Name           = "Caquetá",
                NumberCitizens = 60
            };

            Console.WriteLine("Add a only element: " + stateRepository.Add(state));
            ListStates(stateRepository.GetAll());

            List <State> states = new List <State>
            {
                new State
                {
                    Country        = "CO",
                    Code           = "05",
                    Name           = "Antioquia",
                    NumberCitizens = 100
                },
                new State
                {
                    Country        = "CO",
                    Code           = "01",
                    Name           = "Cundinamarca",
                    NumberCitizens = 100
                }
            };

            Console.WriteLine("Add many elements: " + stateRepository.Add(states));
            ListStates(stateRepository.GetAll());
        }
Exemplo n.º 2
0
        public async Task <ActionResult <Response> > CreateState(StateModel model)
        {
            var country = await _countryRepository.GetCountryById(model.CountryId, include : false);

            if (country == null)
            {
                return(NotFound(ResponseHelper.CreateResponse("Pais não encontrado")));
            }

            var state = model.ToEntity(country);

            if (state.Invalid)
            {
                return(BadRequest(ResponseHelper.CreateResponse("Informações inválidas para cadastrar um estado", model)));
            }

            if (await _stateRepository.StateExist(state))
            {
                return(BadRequest(ResponseHelper.CreateResponse("Esse estado já foi cadastrado", model)));
            }

            _stateRepository.Add(state);

            return(Ok(ResponseHelper.CreateResponse("Estado cadastrado com sucesso!", (StateModel)state)));
        }
Exemplo n.º 3
0
		public void Test_StateRepository_Delete()
		{
			var data = _fixture.Create<StateEditData>();
			data.Language = TwoLetterISOLanguageName.English;

			var id = _states.Add(data);

			var actual = _states.Get(TwoLetterISOLanguageName.English, id).Single().Value;

			actual.ShouldBeEquivalentTo(data, options => options.ExcludingMissingProperties());
			actual.IsSystem.Should().BeFalse();

			_states.Delete(id);

			_states.Get(TwoLetterISOLanguageName.English, id).Should().BeEmpty();
		}
Exemplo n.º 4
0
        public IActionResult Create([FromBody] State state)
        {
            if (state == null)
            {
                return(BadRequest());
            }

            _stateRepository.Add(state);

            return(CreatedAtRoute("GetState", new { id = state.Id }, state));
        }
Exemplo n.º 5
0
        private static void FillTables(IStateRepository stateRepository, ICountryRepository countryRepository)
        {
            string       json   = File.ReadAllText(@"Resources\inputStates.txt");
            List <State> states = JsonConvert.DeserializeObject <List <State> >(json);

            states = states.FindAll(s => !string.IsNullOrEmpty(s.Code) && !string.IsNullOrEmpty(s.Country));
            states = states.FindAll(s => s.Country == "CO");
            Console.WriteLine($"Full Table: {stateRepository.Add(states)}");

            json = File.ReadAllText(@"Resources\inputCountries.txt");
            List <Country> countries = JsonConvert.DeserializeObject <List <Country> >(json);

            countries = countries.FindAll(c => !string.IsNullOrEmpty(c.Code) && (c.Code == "CO" || c.Code == "US"));
            Console.WriteLine($"Full Table: {countryRepository.Add(countries)}");
        }
Exemplo n.º 6
0
        public ActionResult StateInsert(StateViewModel state)
        {
            if (state == null)
            {
                throw new ArgumentNullException(nameof(state));
            }

            var countryModel = new State()
            {
                Title     = state.Title,
                Show      = state.Show,
                CountryId = state.CountryId
            };

            _stateRepository.Add(countryModel);
            _stateRepository.Complete();

            return(Json(""));
        }
Exemplo n.º 7
0
        public ActionResult Create([Bind(Include = "Id,Title,Colour,IsInitial")] StateViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                viewModel.Id = Guid.NewGuid();

                // if there is already initial state, change it to this one
                if (viewModel.IsInitial)
                {
                    removeInitialState(viewModel.Id);
                }

                viewModel.OrderIndex = _stateRepo.GetStatesOrderIndex();
                _stateRepo.Add(Mapper.Map <State>(viewModel));

                return(RedirectToAction("Index"));
            }

            return(View(viewModel));
        }
Exemplo n.º 8
0
        public IHttpActionResult Post([FromBody] State state)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (state == null)
            {
                return(BadRequest("Invalid argument"));
            }

            // state.Country is always NULL!!!!!!
            stateRepository.Add(state);

            var response = Request.CreateResponse(HttpStatusCode.Created, state);

            response.Headers.Location = Request.RequestUri;
            return(ResponseMessage(response));
        }
Exemplo n.º 9
0
        public virtual ActionResult Create(StateCreateModel model)
        {
            if (!ModelState.IsValid)
            {
                BindLanguageList();

                return(View(model));
            }

            var language = _identity.Language;

            var id = _states.Add(
                new StateEditData
            {
                LocalizedName = model.Name,
                Name          = model.Name,
                Position      = model.Position,
                Language      = language
            });

            return(RedirectToAction(MVC.Admin.State.Edit(id, language)));
        }
Exemplo n.º 10
0
        /// <summary>
        /// The Save
        /// </summary>
        /// <param name="entity">The entity<see cref="State"/></param>
        /// <returns>The <see cref="ServiceResult"/></returns>
        public ServiceResult Save(State entity)
        {
            try
            {
                if (entity.Identifier == 0)
                {
                    _repository.Add(entity);
                }
                else
                {
                    _repository.Update(entity);
                }

                return(new ServiceResult(true));
            }
            catch (Exception ex)
            {
                return(new ServiceResult(false)
                {
                    Error = ex.ToString()
                });
            }
        }
Exemplo n.º 11
0
 public void Insert(StateViewModel ViewModel)
 {
     _repository.Add(_mapper.Map <State>(ViewModel));
 }
Exemplo n.º 12
0
 public void Post([FromBody] State value)
 {
     value.Id = GuidSqlite.getGuid();
     _stateRepository.Add(value);
 }
Exemplo n.º 13
0
 public bool Add(State state)
 {
     return(!ExistsState(state) && StateRepository.Add(state));
 }