public ActionResult AddState(State state) { if (string.IsNullOrEmpty(state.StateAbbreviation) || state.StateAbbreviation.Length != 2) { ModelState.AddModelError("StateAbbreviation", "Please enter a 2 letter state abbreviation"); } else { IEnumerable <State> states = StateRepository.GetAll(); if (states.Any(s => s.StateAbbreviation == state.StateAbbreviation.ToUpper())) { ModelState.AddModelError("StateAbbreviation", "State abbreviation already exists, please enter another abbreviation"); } } if (string.IsNullOrEmpty(state.StateName)) { ModelState.AddModelError("StateName", "Please enter a state name"); } if (ModelState.IsValid) { state.StateAbbreviation = state.StateAbbreviation.ToUpper(); StateRepository.Add(state); return(RedirectToAction("States")); } else { return(View("AddState", state)); } }
public void AddTest() { CountryRepository cr = new CountryRepository(); var p = cr.GetAll().GetEnumerator(); p.MoveNext(); Estado item = new Estado() { Nome = "Estado01", Sigla = "01", Pais = p.Current }; IStateRepository target = new StateRepository(); target.Add(item); try { // use session to try to load the product using (ISession session = NHibernateHelper.OpenSession()) { var fromDb = session.Get <Estado>(item.Id); Assert.IsNotNull(fromDb); Assert.AreNotSame(item, fromDb); Assert.AreEqual(item.Nome, fromDb.Nome); Assert.AreEqual(item.Sigla, fromDb.Sigla); Assert.AreEqual(item.Pais.Id, fromDb.Pais.Id); } } finally { target.Remove(item); } }
public ActionResult AddState(State model) { if (string.IsNullOrEmpty(model.StateAbbreviation)) { ModelState.AddModelError("StateAbbreviation", "Please enter the state abbreviation."); } if (!string.IsNullOrEmpty(model.StateAbbreviation)) { if (model.StateAbbreviation.Length > 2 || model.StateAbbreviation.Length < 2) { ModelState.AddModelError("StateAbbreviation", "The state abbreviation must be 2 characters."); } } if (string.IsNullOrEmpty(model.StateName)) { ModelState.AddModelError("StateName", "Please enter the state name."); } if (ModelState.IsValid) { StateRepository.Add(model); return(RedirectToAction("States")); } return(View(model)); }
public ActionResult AddState(State state) { if (ModelState.IsValidField("State")) { if (string.IsNullOrEmpty(state.StateName)) { ModelState.AddModelError("State", "State Name Cannot Be Blank!"); } else if (state.StateName.Any(char.IsDigit)) { ModelState.AddModelError("State", "State Name Cannot Contain Numbers!"); } else if (string.IsNullOrEmpty(state.StateAbbreviation)) { ModelState.AddModelError("State", "State Abbreviation Cannot Be Blank!"); } else if (state.StateAbbreviation.Length > 2) { ModelState.AddModelError("State", "State Abbreviation Must Be Only Two Characters!"); } else { StateRepository.Add(state); return(RedirectToAction("States")); } return(View(state)); } return(View(state)); }
public ActionResult AddState(State state) { if (string.IsNullOrEmpty(state.StateAbbreviation)) { ModelState.AddModelError("StateAbbreviation", "The State Abbreviation field is required!"); } else if (!state.StateAbbreviation.All(c => Char.IsLetter(c)) || state.StateAbbreviation.Length != 2) { ModelState.AddModelError("StateAbbreviation", "The State Abbreviation may only consist of 2 characters!"); } else if (StateRepository.Get(state.StateAbbreviation.ToUpper()) != null) { ModelState.AddModelError("StateAbbreviation", $"The State Abbreviation {state.StateAbbreviation} already exists!"); } if (string.IsNullOrEmpty(state.StateName)) { ModelState.AddModelError("StateName", "The State Name field is required!"); } if (ModelState.IsValid) { StateRepository.Add(state); return(RedirectToAction("States")); } else { return(View(new State())); } }
public ActionResult AddState(State state) { // public void AddModelError( //string key, //string errorMessage if (string.IsNullOrWhiteSpace(state.StateName)) { ModelState.AddModelError("StateName", "A state name needs to be entered"); } if (string.IsNullOrWhiteSpace(state.StateAbbreviation)) { ModelState.AddModelError("StateAbbreviation", "A state abbreviation needs to be entered"); } if (ModelState.IsValid) { StateRepository.Add(state); return(RedirectToAction("States")); } else { return(View("AddState", state)); } }
public ActionResult AddState(StateVM stateVM) { stateVM.ValidStates = StatesList.States; stateVM.State = (stateVM.State ?? new State { StateAbbreviation = "", StateName = null }); if (ModelState.IsValid) { try { stateVM.State.StateName = StatesList.States.FirstOrDefault(s => stateVM?.State.StateAbbreviation == s.Value)?.Text; } catch (NullReferenceException) { stateVM.State.StateName = null; } if (stateVM.State.StateName == null) { return(View(stateVM)); } StateRepository.Add(stateVM.State); return(RedirectToAction("States")); } return(View(stateVM)); }
public ActionResult AddState2(StateVM sVM) { IEnumerable <State> states = StateRepository.GetAll(); IEnumerable <State> allStates = StateRepository.AllStates(); if (states.Any(s => s.StateAbbreviation == sVM.State.StateAbbreviation)) { ModelState.AddModelError("StateAbbreviation", "This State Abbreviation is already in use."); } if (!allStates.Any(s => s.StateAbbreviation == sVM.State.StateAbbreviation)) { ModelState.AddModelError("StateAbbreviation", "Please choose a valid state to add."); } foreach (var item in allStates) { if (item.StateAbbreviation == sVM.State.StateAbbreviation) { sVM.State = item; } } if (ModelState.IsValid) { StateRepository.Add(sVM.State); return(RedirectToAction("States")); } return(View("AddState2", sVM)); }
public void GetByNameTest() { CountryRepository cr = new CountryRepository(); var p = cr.GetAll().GetEnumerator(); p.MoveNext(); Estado item = new Estado() { Nome = "Estado01", Sigla = "01", Pais = p.Current }; IStateRepository target = new StateRepository(); target.Add(item); try { var fromDb = target.GetByName(item.Nome); Assert.IsNotNull(fromDb); Assert.AreNotSame(item, fromDb); Assert.AreEqual(item.Nome, fromDb.Nome); Assert.AreEqual(item.Sigla, fromDb.Sigla); Assert.AreEqual(item.Pais.Id, fromDb.Pais.Id); } finally { target.Remove(item); } }
public static void Add() { try { State state = new State(); Console.WriteLine("Please enter the following information:"); Console.Write("Order status: "); state.OrderStatus = Console.ReadLine(); while (string.IsNullOrWhiteSpace(state.OrderStatus)) { Console.Write("Please enter correct name of status:"); state.OrderStatus = Console.ReadLine(); } using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString)) { ISalonManager <State> stateManager = new StateRepository(connection); State addedState = stateManager.Add(state); } Console.WriteLine($"Status {state.OrderStatus} successfully added!"); } catch (Exception ex) { Console.WriteLine("Something went wrong... Try latter"); Console.WriteLine(ex.Message); } }
public ActionResult AddState(State state) { StateRepository.Add(state); List <State> model = new List <State>(); model = StateRepository.GetAll().ToList(); return(View("States", model)); }
public ActionResult AddState(State state) { if (ModelState.IsValid) { StateRepository.Add(state); return(RedirectToAction("States")); } return(View(state)); }
public ActionResult AddState(AddStateVM viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } StateRepository.Add(viewModel.currentState); return(RedirectToAction("States")); }
private UserState GetState(long id) { var user = stateRepository.Get(id); if (user == null) { user = new UserState(id); stateRepository.Add(user); } return(user); }
public ActionResult AddState(State state) { if (ModelState.IsValid) { state.StateName = state.StateName.ToTitle(); state.StateAbbreviation = state.StateAbbreviation.ToUpper(); StateRepository.Add(state); return(RedirectToAction("States")); } else { return(View(state)); } }
public ActionResult AddState(State state) { if (string.IsNullOrEmpty(state.StateName)) { ModelState.AddModelError("StateName", "Please enter state name."); } if (!ModelState.IsValid) { return(View(state)); } StateRepository.Add(state); return(RedirectToAction("States")); }
public ActionResult AddState(State state) { if (ModelState.IsValid) { state.StateAbbreviation = state.StateAbbreviation.ToUpper(); state.StateName = state.StateName.Substring(0, 1).ToUpper() + state.StateName.Substring(1); StateRepository.Add(state); return(RedirectToAction("States")); } else { return(View("AddState", new State())); } }
public override IEnumerable <Row> Execute(IEnumerable <Row> rows) { using (var conn = new NpgsqlConnection(conString)) { conn.Open(); foreach (var row in rows) { StateRepository.Add(conn, (string)row["OriginState"], (string)row["OriginStateName"], (string)row["OriginAirportName"], (string)row["OriginCityName"], _stateDict); StateRepository.Add(conn, (string)row["DestState"], (string)row["DestStateName"], (string)row["DestAirportName"], (string)row["DestCityName"], _stateDict); yield return(row); } } }
public ActionResult AddState(StateVM stateVM) { if (ModelState.IsValid) { var state = new State(); state.StateAbbreviation = stateVM.StateAbbreviation; state.StateName = stateVM.StateName; StateRepository.Add(state); return(RedirectToAction("States")); } else { return(View("AddState", stateVM)); } }
public ActionResult AddState(State state) { if (ModelState.IsValid) { TextInfo myTI = new CultureInfo("en-US", false).TextInfo; state.StateName = myTI.ToTitleCase(state.StateName); state.StateAbbreviation = myTI.ToTitleCase(state.StateAbbreviation); StateRepository.Add(state); return(RedirectToAction("States")); } return(View("AddState", state)); }
public ActionResult AddState(State state) { if (string.IsNullOrEmpty(state.StateAbbreviation) || string.IsNullOrEmpty(state.StateName)) { ModelState.AddModelError("StateAbbreviation", "Please enter state abbreviation"); ModelState.AddModelError("StateName", "Please enter state name"); return(View(new State())); } else { StateRepository.Add(state); return(RedirectToAction("StatesPage")); } }
public async Task <bool> Add(StateRequest stateReq) { Guid Id = Guid.NewGuid(); string url = await ImageService.UploadImage(Id, stateReq.PhotoUrl); State state = new State() { Id = Id, Name = stateReq.Name, CountryId = stateReq.CountryId, Country = stateReq.Country, Friends = stateReq.Friends, PhotoUrl = url }; return(await StateRepository.Add(state)); }
public ActionResult AddState(State state) { if (string.IsNullOrWhiteSpace(state.StateName)) { ModelState.AddModelError("StateName", "Please enter a state name"); } if (string.IsNullOrWhiteSpace(state.StateAbbreviation)) { ModelState.AddModelError("StateAbbreviation", "Please enter a state abbreviation"); } if (ModelState.IsValid) { StateRepository.Add(state); return(RedirectToAction("States")); } return(View(state)); }
public void AddSingleModelStateTest() { //country table must NOT be Empty var context = new ApplicationDbContext(); var expected = context.State.Count() + 1; var target = new StateRepository(context); var countryId = context.Country.FirstOrDefault().Id;//select first row from Country Table, For Country id var state = new State() { CountryId = countryId, Title = "Rasht" }; target.Add(state); target.Complete(); var actual = context.State.Count(); Assert.AreEqual(expected, actual);//if expected equals to actual then the test would be passed }
public ActionResult AddState(State state) { if (string.IsNullOrEmpty(state.StateName)) { ModelState.AddModelError("StateName", "Enter a valid state name."); } if (string.IsNullOrEmpty(state.StateAbbreviation)) { ModelState.AddModelError("StateAbbreviation", "Enter a valid state abbreviation."); } if (ModelState.IsValid) { StateRepository.Add(state); return(RedirectToAction("States")); } else { return(View("AddState", state)); } }
public ActionResult AddState(State state) { if (string.IsNullOrWhiteSpace(state.StateName)) { ModelState.AddModelError("StateName", "please enter the name of the state"); } if (string.IsNullOrWhiteSpace(state.StateAbbreviation) || state.StateAbbreviation.Length != 2) { ModelState.AddModelError("StateAbbreviation", "Please enter a valid, two character abbreviation"); } if (ModelState.IsValid) { StateRepository.Add(state); return(RedirectToAction("States")); } else { return(View("AddState", state)); } }
public ActionResult AddState(State state) { if (string.IsNullOrEmpty(state.StateName)) { ModelState.AddModelError("StateName", "Please enter the state name"); } IEnumerable <State> states = StateRepository.GetAll(); if (states.Any(s => s.StateAbbreviation == state.StateAbbreviation)) { ModelState.AddModelError("StateAbbreviation", "State Abbreviation in use"); } if (ModelState.IsValid) { StateRepository.Add(state); return(RedirectToAction("States")); } return(View("AddState", state)); }
private T GetOrCreateState(long id, ClientType clientType) { var user = stateRepository.Get(id); if (user == null) { user = new T() { Id = id, Client = clientType, }; Type type = conversations.Where( x => ((ConversationAttribute)Attribute.GetCustomAttribute(x.GetType(), typeof(ConversationAttribute))) .Type == StateType.Start) .FirstOrDefault().GetType(); user.SetConversationState(type.Name); stateRepository.Add(user); } ; return((T)user); }
public ActionResult AddState(State state) { StateRepository.Add(state); return(RedirectToAction("States")); }
public string Add(State state) { bool success = StateRepository.Add(state); return("State created with success"); }