public int SaveGender(GenderDTO gender) { if (gender.GenderId == 0) { var c = new Gender() { Name = gender.Name, CreatedOn = DateTime.Now }; this.UnitOfWork.Get<Gender>().AddNew(c); this.UnitOfWork.SaveChanges(); return c.GenderId; } else { var c = this.UnitOfWork.Get<Gender>().AsQueryable() .FirstOrDefault(d => d.GenderId == gender.GenderId); if (c != null) { c.Name = gender.Name; c.CreatedOn = gender.CreatedOn; c.TimeStamp = gender.TimeStamp; this.UnitOfWork.Get<Gender>().Update(c); this.UnitOfWork.SaveChanges(); } return c.GenderId; } }
private void Button_Click(object sender, RoutedEventArgs e) { var c = new GenderDTO() { Name = genderTextbox.Text, }; _dataService.SaveGender(c); }