public void InsertBabyName(BabyName babyName) { var entity = Integration.UseCases.BabyNames.Mappers.BabyBusinessObjectToEntityMapper.ConvertFromBusinessObject(babyName); this.context.BabyNames.Add(entity); this.context.SaveChanges(); }
public void Post([FromBody] BabyName baby) { if (ModelState.IsValid) { babyRepository.Add(baby); } }
public EditViewModel() { SDNAppsEntities saEntities = new SDNAppsEntities(); BabyName = new BabyName(); KidNames = new SelectList(saEntities.BabyNames, "ID", "BabyName1"); }
public void LoadNames(object Object, RoutedEventArgs e) { string[] names = File.ReadAllLines("05-babynames.txt", Encoding.Default); foreach (var name in names) { var baby = new BabyName(name); for (int i = 0; i < 11; i++) { if ((baby.Rank(1900 + i * 10) < 11) && (baby.Rank(1900 + i * 10) != 0)) { //Debug.WriteLine("{0}, {1}", baby.Rank(1900 + i * 10), baby.Name); var tup = Tuple.Create(baby.Rank(1900 + i * 10), baby.Name); _topNames[i].Add(tup); } } _babyNames.Add(baby); } for (int i = 1900; i < 2005; i += 10) { Decades.Items.Add(new ListBoxItem() { Content = i.ToString() }); } }
public void Put(int id, [FromBody] BabyName baby) { baby.baby_id = id; if (ModelState.IsValid) { babyRepository.Update(baby); } }
void Search(object sender, RoutedEventArgs e) { // get the name entered by the user: string name = tbxName.Text; // search through collection... int i; if (name == "") { i = namesCollection.Count + 1; } else { i = namesCollection.IndexOf(new BabyName(name + " 1 1 1 1 1 1 1 1 1 1 1")); } // Alternative manual search //for (i = 0; i < namesCollection.Count; ++i) //{ // if (namesCollection[i].Name == name) // break; //} if (-1 < i && i < namesCollection.Count) { tblkError.Text = ""; BabyName theName = namesCollection[i]; tboxAveRank.Text = theName.AverageRank().ToString(); if (theName.Trend() > 0) { tboxTrend.Text = "More popular"; } else if (theName.Trend() == 0) { tboxTrend.Text = "Inconclusive"; } else { tboxTrend.Text = "Less popular"; } int rank; lstNameRanking.Items.Clear(); for (int year = 1900; year < 2001; year += 10) { rank = theName.Rank(year); lstNameRanking.Items.Add(string.Format("{0:####} {1:####}", year, rank)); } } else { tblkError.Text = "Name not found!"; tboxAveRank.Text = ""; tboxTrend.Text = ""; lstNameRanking.Items.Clear(); } }
public ActionResult DeleteConfirmed(int id) { BabyName babyName = db.BabyNames.Find(id); babyName.Delete = true; //db.BabyNames.Remove(babyName); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "ID,BabyName1,Delete,IPAddress,Longitude,Latitude")] BabyName babyName) { if (ModelState.IsValid) { db.Entry(babyName).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(babyName)); }
public void Add(BabyName baby) { using (System.Data.IDbConnection dbConnection = Connection) { string sQuery = "INSERT INTO baby_name (first_name, last_name, baby_birthday)" + " VALUES(@first_name, @last_name, @baby_birthday)"; dbConnection.Open(); dbConnection.Execute(sQuery, baby); } }
public void Update(BabyName baby) { using (System.Data.IDbConnection dbConnection = Connection) { string sQuery = "UPDATE baby_name SET" + " first_name=@first_name, last_name=@last_name, baby_birthday=@baby_birthday" + " WHERE baby_id = @baby_id"; dbConnection.Open(); dbConnection.Query(sQuery, baby); } }
public void InsertNewYearData(BabyName babyName) { var babyNameEntity = context.BabyNames.FirstOrDefault(b => b.Name == babyName.Name); babyNameEntity.YearEntries.Add(new Data.Entities.YearEntry { Year = babyName.YearEntries[0].Year, NumberInYear = babyName.YearEntries[0].NumberInYear, RankInYear = babyName.YearEntries[0].RankInYear }); this.context.Update(babyNameEntity); this.context.SaveChanges(); }
public ActionResult Create([Bind(Include = "ID,BabyName1,Delete,IPAddress,Longitude,Latitude")] BabyName babyName) { if (ModelState.IsValid) { db.BabyNames.Add(babyName); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(babyName)); }
//public Task<BabyName> GetItemAsync(int id) //{ // return _database.Table<BabyName>().Where(i => i.ID == id).FirstOrDefaultAsync(); //} //public Task<int> SaveItemAsync(BabyName item) //{ // if (item.ID != 0) // { // return _database.UpdateAsync(item); // } // else // { // return _database.InsertAsync(item); // } //} public int SaveItem(BabyName item) { if (item.ID != 0) { return(_db.Update(item)); } else { return(_db.Insert(item)); } }
// GET: Baby/BabyNames/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BabyName babyName = db.BabyNames.Find(id); if (babyName == null) { return(HttpNotFound()); } return(View(babyName)); }
void Search(object sender, RoutedEventArgs e) { string name = tbxName.Text; int i; for (i = 0; i < _namesCollection.Count; i++) { if (_namesCollection[i].Name == name) { break; } } if (-1 < i && i < _namesCollection.Count) { tblkError.Text = ""; BabyName theName = _namesCollection[i]; tboxAveRank.Text = theName.AverageRank().ToString(); if (theName.Trend() > 0) { tboxTrend.Text = "More popular"; } else if (theName.Trend() == 0) { tboxTrend.Text = "Inconclusive"; } else { tboxTrend.Text = "Less popular"; } int rank; IstNameRanking.Items.Clear(); for (int year = 1900; year < 2001; year += 10) { rank = theName.Rank(year); IstNameRanking.Items.Add(string.Format("{0:####} {1:####}", year, rank)); } } else { tblkError.Text = "Name not found!"; tboxAveRank.Text = ""; tboxTrend.Text = ""; IstNameRanking.Items.Clear(); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { //read all baby names on loadup. using (var reader = new StreamReader(@"../../../05-babynames.txt")) { while (!reader.EndOfStream) { var line = reader.ReadLine(); babyNames.Add(new BabyName(line)); } } //create matrix of top 10 baby names pr. decade for (int i = 1900; i <= 2000; i += 10) { //MessageBox.Show("Calculating top 10 names for: " + i); //Make placeholder array for top 10 names (boys and girls. 1= place 0 & 10, 2 =1 & 11, etc..) BabyName[] top10ofTheDecade = new BabyName[20]; foreach (BabyName BN in babyNames) { int rank = BN.Rank(i); //get rank if (rank <= 10 && rank != 0) //if in top 10 { if (top10ofTheDecade[rank - 1] == null) // if first value holder is null. { top10ofTheDecade[rank - 1] = BN; } else { top10ofTheDecade[rank + 10 - 1] = BN; } } } top10babyNamesByDecade.Add(i, top10ofTheDecade); //add to matrix of top names. String[] strings = new String[10]; //create strings containing both boy and girl names. for (int j = 0; j < 10; j++) { strings[j] = top10ofTheDecade[j].Name + " and " + top10ofTheDecade[j + 10].Name; } //add to matrix of name strings. top10babyNamesStrings.Add(i, strings); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.BabyNameDetailView); selectedBabyName = new BabyName() { Name = Intent.GetStringExtra("selectedBabyName") }; //BabyNameDataService dataService = new BabyNameDataService(); dataService = new BabyNameDataService(); //selectedBabyName = dataService.GetBabyNameByName("Shit"); FindViews(); BindData(); HandleEvents(); }
// Add new baby-name data to the linked list. public void Add(string name, int countFemales, int countMales) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("Invalid baby name", "name"); } bool babyExists = false; // Check if the name already exists in the linked list foreach (BabyName babyName in this.ToArray()) { if (name == babyName.Name) { // If it exists, increment the number of M/F babyExists = true; babyName.IncrementMales(countMales); babyName.IncrementFemales(countFemales); } } if (babyExists == false) { // If the name doesn't exist, create a new name BabyName baby = new BabyName(name); baby.IncrementMales(countMales); baby.IncrementFemales(countFemales); // Create a new list entry Node tmp = new Node(baby); tmp.Link = null; // If this is the first element, set it as such if (this.head == null) { this.head = tmp; } else { // Set the next element in the tail to the current element this.tail.Link = tmp; } // Set the tail to the last element this.tail = tmp; } }
private void Button_Click(object sender, RoutedEventArgs e) { String currentName = TB_searchName.Text.ToString(); //get name to search for MessageBox.Show("Searching for name: " + currentName); try { BabyName currentNameObject = babyNames.Find(x => x.Name == currentName); //find name object. TB_avg_rating.Text = currentNameObject.AverageRank().ToString(); //get average rating. //get rating over years. selectedNameOverYears.Clear(); for (int i = 1900; i <= 2000; i += 10) { selectedNameOverYears.Add(i + ": " + currentNameObject.Rank(i)); } //update ListBox LB_nameOverYears.ItemsSource = selectedNameOverYears; //Get trend String trend = ""; if (currentNameObject.Trend() == 0) { trend = "Popularity stable"; } else if (currentNameObject.Trend() < 0) { trend = "Decreasing popularity"; } else if (currentNameObject.Trend() > 0) { trend = "Increasing popularity"; } //update trend TB_trend.Text = trend; } catch //if no data for name is found { MessageBox.Show("No data for name: " + currentName); } }
public Return BabyName(BabyName babyName) { var resultReturn = new Return(); try { var dic = Services.WebData.BabyName.Handler.GetHtml(babyName.Surname, babyName.BirthDay, babyName.IsMan, babyName.Province, babyName.City, babyName.NameType); resultReturn.Content = dic; return(resultReturn); } catch (Exception ex) { LogService.InsertLog(ex); resultReturn.SetWrong(); return(resultReturn); } }
// Convert the linked list to an array of its data elements. public BabyName[ ] ToArray( ) { // Collect data objects from the linked list. ArrayList objects = new ArrayList( ); Node current = head; while( current != null ) { objects.Add( current.Data ); current = current.Link; } // Covert the collection of objects to an array of strings. BabyName[ ] results = new BabyName[ objects.Count ]; for( int i = 0; i < results.Length; i ++ ) { results[ i ] = ( BabyName ) objects[ i ]; } return results; }
// Convert the linked list to an array of its data elements. public BabyName[] ToArray( ) { // Collect data objects from the linked list. ArrayList objects = new ArrayList( ); Node current = head; while (current != null) { objects.Add(current.Data); current = current.Link; } // Covert the collection of objects to an array of strings. BabyName[] results = new BabyName[objects.Count]; for (int i = 0; i < results.Length; i++) { results[i] = ( BabyName )objects[i]; } return(results); }
private void ConvertCSVtoEntities() { const int startOnLine = 1; for (int i = startOnLine; i < linesOfFile.Length; i++) { var babyName = new BabyName(); string[] lineContent = Utilities.CSVutilities.SplitLineOfCSV(linesOfFile[i]); babyName.Name = lineContent[nameColumnIndex]; babyName.Gender = this.gender; YearEntry newYearEntry = new YearEntry(); newYearEntry.Year = this.year; newYearEntry.RankInYear = int.Parse(lineContent[rankColumnIndex]); newYearEntry.NumberInYear = int.Parse(lineContent[numberColumnIndex]); babyName.YearEntries.Add(newYearEntry); babyNamesForImport.Add(babyName); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { var dlg = new Microsoft.Win32.OpenFileDialog(); dlg.DefaultExt = ".txt"; dlg.Filter = "TXT files (*.txt)|*.txt"; var result = dlg.ShowDialog(); if (result != true) { Close(); return; } var fileName = dlg.FileName; StreamReader file = new StreamReader(fileName); string line; while ((line = file.ReadLine()) != null) { BabyName baby = new BabyName(line); babynames.Add(baby); } FillTopLists(); SortLists(); }
public Node(BabyName data) { link = null; this.data = data; }
//Beginning of Add Method //=================================================== // Add new baby-name data to the linked list. public void Add( string name, int countFemales, int countMales ) { if( string.IsNullOrWhiteSpace( name ) ) throw new ArgumentException( "Invalid baby name", "name" ); Node current = head; //beginning the list if (head == null) { // creating an object BabyName b = new BabyName(name); // creating the first node head = new Node(b); head.Data.IncrementFemales(countFemales); head.Data.IncrementMales(countMales); tail = head; } bool DoesContain = false; //search through the list and look for the name while( current != null ) { if (current.Data.Name == name ) { // when it exits the loop, we have the position of the node // with the object we are looking for DoesContain = true; break; } current = current.Link; } // case 1: baby name is in name and the number of males and females //have to be updated if (DoesContain) { // updates the information current.Data.IncrementFemales(countFemales); current.Data.IncrementMales(countMales); } // case 2: name has not been seen before, so create a new object // and add it to the list else if(current != head) { // creating an object BabyName b = new BabyName(name); // creating a new node Node newNode = new Node(b); //adding information to the object newNode.Data.IncrementFemales(countFemales); newNode.Data.IncrementMales(countMales); // placing the node at the end of the list tail.Link = newNode; // updating the tail tail = newNode; } // TO DO: Complete this method. }
public Node( BabyName data ) { link = null; this.data = data; }
public Return BabyName(BabyName nameModel) { var resultReturn = new Return(); try { //用户ID和安卓ID都为空 if (Guid.Empty == nameModel.CustomerId && string.IsNullOrEmpty(nameModel.AndroidId)) { resultReturn.ReturnCode.Code = 2889; return(resultReturn); } decimal?prePrice = 0m; var oriPrice = 0m; var priceRight = false; if (nameModel.IsRepeat) { priceRight = ValidPrice((int)BusinessTypeEnum.BabyName, nameModel.Amout, true, ref oriPrice, ref prePrice); } else { priceRight = ValidPrice((int)BusinessTypeEnum.BabyName, nameModel.Amout, false, ref oriPrice, ref prePrice); } if (!priceRight) { resultReturn.ReturnCode.Code = 2886; return(resultReturn); } var orderInfoModel = TransferToOrderInfoModel(nameModel); orderInfoModel.SalesPromotionId = 2; orderInfoModel.OrderType = (int)BusinessTypeEnum.BabyName; orderInfoModel.PreferentialPrice = prePrice; orderInfoModel.OriginalPrice = oriPrice; if (_isTesting) { orderInfoModel.PayState = GlobalConst.Paid; } var tuple = OrderService.Insert(orderInfoModel); if (!tuple.Item1) { resultReturn.ReturnCode.Code = -1; return(resultReturn); } else { //写入OrderSearch表 var orderSearchModel = new OrderSearch { OrderId = Guid.Parse(tuple.Item2), BSurname = nameModel.Surname, BBirthDay = nameModel.BirthDay, BSex = nameModel.Sex, BProvince = nameModel.Province, BCity = nameModel.City, BNameType = nameModel.NameType }; var flag = OrderSearchService.Insert(orderSearchModel); //写入失败 if (!flag) { //设置该订单失效 OrderService.SetToDelete(tuple.Item2); } } resultReturn.Content = new Dictionary <string, string> { { "OrderId", tuple.Item2 } }; } catch (Exception ex) { LogService.InsertLog(ex); resultReturn.SetWrong(); } return(resultReturn); }