private bool ValidatePeople(PeopleDTO peopleDto) { if (string.IsNullOrEmpty(peopleDto.FirstName)) { return(false); } if (string.IsNullOrEmpty(peopleDto.LastName)) { return(false); } if (string.IsNullOrEmpty(peopleDto.SecondName)) { return(false); } if (peopleDto.DateBirthday == DateTime.MinValue) { return(false); } if (string.IsNullOrEmpty(peopleDto.Email)) { return(false); } return(true); }
public IEnumerable <PeopleDTO> GetPeoples() { // Применяем автомаппер для проекции одной коллекции на другую. var peoplesTask = Task.Factory.StartNew(() => database.Peoples.GetAll()); var peoplesResult = new List <PeopleDTO>(); var mapper = new MapperConfiguration(cfg => cfg.CreateMap <Phone, PhoneDTO>()).CreateMapper(); foreach (var people in peoplesTask.Result) { var phones = mapper.Map <IEnumerable <Phone>, List <PhoneDTO> >(people.Phones); var peopleDTO = new PeopleDTO { Id = people.Id, FirstName = people.FirstName, LastName = people.LastName, SecondName = people.SecondName, Email = people.Email, DateBirthday = people.DateBirthday, Phones = phones }; peoplesResult.Add(peopleDTO); } return(peoplesResult); }
public JsonResult GetPeoples() { var response = WebHostCache.Current.GetResponse <XElement>(@"api\Dictionary\GetPeoples?sessionKey=" + session.Key.ToString()); var result = PeopleDTO.ArrayFromXElement(response).ToList(); return(Json(new { rc = 0, Items = result }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// Xuất bảng lương nhân viên /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btSave_Click_1(object sender, EventArgs e) { if (txtFN.Text != "") { PeopleDTO nv = new PeopleDTO(); Salary sl = null; for (int i = 0; i < tbNV.Rows.Count; i++) { if (tbNV.Rows[i]["Id"].ToString() == cbbIDP.Text.Substring(0, cbbIDP.Text.Length - 3)) { nv.ID = Int32.Parse(tbNV.Rows[i]["Id"].ToString()); nv.KH = tbNV.Rows[i]["Kh"].ToString(); nv.FName = tbNV.Rows[i]["FName"].ToString(); nv.LName = tbNV.Rows[i]["LName"].ToString(); nv.MaCV = Int32.Parse(tbNV.Rows[i]["Id"].ToString()); sl = new Salary(nv); sl.CV = cbbCV.Text; sl.Luong = luongNV; break; } } sl.ShowDialog(); } else { MessageBox.Show("Chưa nhập đủ thông tin", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Lưu KTKL cho nhân viên /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btSave_Click(object sender, EventArgs e) { if (txtN.Text != "" && txtKLKT.Text != "") { PeopleDTO pp = new PeopleDTO(); KTKLDTO kt = new KTKLDTO(); kt.ID = Int32.Parse(cbbKTKL.Text); pp.ID = Int32.Parse(cbbID.Text.Substring(0, cbbID.Text.Length - 3)); pp.KH = cbbID.Text.Substring(cbbID.Text.Length - 3); int result = ketoan.ThemNVKTKL(kt, pp); if (result > 0) { MessageBox.Show("Thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { MessageBox.Show("Không thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Chưa nhập đủ thông tin", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static List <PeopleDTO> loadListTeacher(string status) { string sCommand = ""; if (status == "System.Windows.Controls.ComboBoxItem: Active") { sCommand = @"Select* from Teacher where isActive = 'T'"; } else if (status == "System.Windows.Controls.ComboBoxItem: Deactive") { sCommand = @"Select* from Teacher where isActive = 'F'"; } else { sCommand = @"Select* from Teacher"; } con = DataProvider.OpenConnection(); DataTable dt = DataProvider.GetDataTable(sCommand, con); if (dt.Rows.Count <= 0) { DataProvider.CloseConnection(con); return(null); } else { List <PeopleDTO> result = new List <PeopleDTO>(); int n = dt.Rows.Count; for (int i = 0; i < n; i++) { PeopleDTO teacher = new PeopleDTO(); teacher.Id = dt.Rows[i]["IDTeacher"].ToString(); teacher.Name = dt.Rows[i]["Name"].ToString(); teacher.Gender = dt.Rows[i]["Gender"].ToString(); teacher.Email = dt.Rows[i]["Email"].ToString(); teacher.DateofBith = dt.Rows[i]["BirthDay"].ToString(); if (dt.Rows[i]["TypeTeacher"].ToString() == "PDT") { teacher.Type = "AAO Staff"; } else { teacher.Type = "Teacher"; } teacher.Password = dt.Rows[i]["Password"].ToString(); teacher.Phone = dt.Rows[i]["Phone"].ToString(); if (dt.Rows[i]["isActive"].ToString() == "T") { teacher.Status = "Active"; } else { teacher.Status = "Deactive"; } result.Add(teacher); } DataProvider.CloseConnection(con); return(result); } }
public void GetNhanVienDTO(out PeopleDTO Nv, object Id) { Nv = new PeopleDTO(); Providers provi = new Providers(); SqlDataReader reader = provi.GetNhanVienDTO(Id); if (reader.Read()) { Nv.ID = int.Parse(reader["Id"].ToString()); Nv.FName = reader["Fname"].ToString(); Nv.LName = reader["LName"].ToString(); Nv.GioiTinh = reader["GioiTinh"].ToString(); Nv.KH = reader["Kh"].ToString(); Nv.DOB = DateTime.Parse(reader["DOB"].ToString()); Nv.HD = DateTime.Parse(reader["HireDay"].ToString()); Nv.QueQuan = reader["QueQuan"].ToString(); Nv.MaPB = int.Parse(reader["Id_PB"].ToString()); Nv.MaCV = int.Parse(reader["Id_CV"].ToString()); if (reader["Id_NQL"] != DBNull.Value) { Nv.IDNQL = int.Parse(reader["Id_NQL"].ToString()); } if (reader["Kh_NQL"] != DBNull.Value) { Nv.KHNQL = reader["Kh_NQL"].ToString(); } } reader.Close(); }
private void SelectItem(object sender, MouseButtonEventArgs e) { PeopleDTO item = (PeopleDTO)listviewUser.SelectedItems[0]; fullname_user_infor.Text = item.Name; birthofday_user_infor.Text = item.DateofBith; email_user_infor.Text = item.Email; password_user_infor.Password = item.Password; if (item.Gender == "Male") { gender_user_infor.SelectedIndex = 1; } else if (item.Gender == "Female") { gender_user_infor.SelectedIndex = 2; } else { gender_user_infor.SelectedIndex = 0; } phone_user_infor.Text = item.Phone; author_user_infor.Text = item.Type; if (item.Type == "Student") { if (item.Status == "Active") { btnDelete.Visibility = Visibility.Visible; } else if (item.Status == "Deactive") { btnActive.Visibility = Visibility.Visible; } } }
private void btnActive_Click(object sender, RoutedEventArgs e) { PeopleDTO item = (PeopleDTO)listviewUser.SelectedItems[0]; if (!AdminBUS.ActiveUser(item.Id, item.Type)) { MessageBox.Show("Error", "Active user failed", MessageBoxButton.OK, MessageBoxImage.Error); } if (chooseAuthor.SelectedValue.ToString() == "System.Windows.Controls.ComboBoxItem: Student") { listviewUser.ItemsSource = AdminBUS.loadListStudent(chooseStatus.SelectedValue.ToString()); } else if (chooseAuthor.SelectedValue.ToString() == "System.Windows.Controls.ComboBoxItem: Teacher") { listviewUser.ItemsSource = AdminBUS.loadListTeacher(chooseStatus.SelectedValue.ToString()); } else { listviewUser.ItemsSource = AdminBUS.loadListUser(chooseStatus.SelectedValue.ToString()); } btnDelete.Visibility = Visibility.Collapsed; btnActive.Visibility = Visibility.Collapsed; btnEdit.IsEnabled = false; }
private bool ValidatePeople(PeopleDTO peopleDto) { if (string.IsNullOrEmpty(peopleDto.FirstName)) { throw new ValidationException("имя пустое", "Firstname"); } if (string.IsNullOrEmpty(peopleDto.LastName)) { throw new ValidationException("фамилия пустая", "Lastname"); } if (string.IsNullOrEmpty(peopleDto.SecondName)) { throw new ValidationException("отчество пустое", "Secondname"); } if (string.IsNullOrEmpty(peopleDto.Phone)) { throw new ValidationException("телефон пустой", "Phone"); } if (peopleDto.DateBirthday == null) { throw new ValidationException("дата рождения не задана", "DateBirthday"); } if (string.IsNullOrEmpty(peopleDto.Email)) { throw new ValidationException("Email пустой", "Email"); } return(true); }
public JsonResult AddPeopleJSON(PeopleViewModel people) { try { var peopleDto = new PeopleDTO { Id = people.Id, FirstName = people.FirstName, LastName = people.LastName, SecondName = people.SecondName, Email = people.Email, Phone = people.Phone, DateBirthday = people.DateBirthday }; if (people.Id > 0) { peopleService.EditPeople(peopleDto); } else { peopleService.AddPeople(peopleDto); } return(Json(new { success = true, data = people }, JsonRequestBehavior.AllowGet)); } catch (ValidationException ex) { ModelState.AddModelError(ex.Property, ex.Message); return(Json(new { success = false, errorstring = ex.Message }, JsonRequestBehavior.AllowGet)); } }
public async Task <JsonResult> AddPeopleJSON(PeopleViewModel people) { try { var peopleDto = new PeopleDTO { Id = people.Id, FirstName = people.FirstName, LastName = people.LastName, SecondName = people.SecondName, Email = people.Email, DateBirthday = people.DateBirthday }; if (people.Id > 0) { await peopleService.EditPeopleTask(peopleDto); } else { var result = await peopleService.AddPeopleTask(peopleDto); if (!result.Successed) { return(Json(new { success = false, Message = result.ErrorMessage }, JsonRequestBehavior.AllowGet)); } people.Id = result.Id; } foreach (var phone in people.Phones) { if (phone.ForDelete && phone.Id > 0) { await peopleService.DelPhoneForPeopleTask(phone.Id, people.Id); } if (phone.Id == 0 && !phone.ForDelete) { await peopleService.AddPhoneForPeopleTask(phone.PhoneNumber, people.Id); } if (!phone.ForDelete && phone.Id > 0) { await peopleService.EditPhoneForPeopleTask(phone.Id, people.Id, phone.PhoneNumber); } } return(Json(new { success = true, data = people }, JsonRequestBehavior.AllowGet)); } catch (ValidationException ex) { ModelState.AddModelError(ex.Property, ex.Message); return(Json(new { success = false, errorstring = ex.Message }, JsonRequestBehavior.AllowGet)); } }
//public void AddSubject(Subject newSubject) //{ // _context.Add(newSubject); // _context.SaveChanges(); //} public async Task <PeopleDTO> GetPeopleAsync() { var people = new PeopleDTO(); people.admins = await Task.Run(() => _context.Admins); people.students = await Task.Run(() => _context.Students.Include(s => s.Class)); people.teachers = await Task.Run(() => _context.Teachers); return(people); }
/// <summary> ///Truyền dữ liệu vào User peple và User thannhan /// </summary> /// <param name="people">Đối tượng people được đưa vào</param> /// <param name="pb">danh sách phòng ban</param> /// <param name="thongbao">xử lý được chọn</param> /// <param name="changed">cờ để kiểm tra có gán các giá trị mặt định cho nhan vien hay không</param> public void TranslationPeople(PeopleDTO people, List <PhongBanDTO> pb, string thongbao, bool changed) { this.Text = thongbao; StringThongBao = thongbao; ppus.StringThongBao = thongbao; ppus.Visiblenew = changed; nhanVien = people; ppus.NhanVien = nhanVien; ppus.LPB = pb; tnus1.Temp = stringThongBao; tnus1.BinDing(); }
public void AddPeopleByNullDateBirthdayTest() { PeopleDTO pdto = new PeopleDTO(); pdto.FirstName = "qqqq"; pdto.LastName = "eeee"; pdto.SecondName = "wwww"; pdto.Email = "*****@*****.**"; var result = peopleserv.AddPeople(pdto); Assert.AreEqual(result.ErrorMessage, "validation error"); }
public void EditPeopleByEmptyEmailTest() { PeopleDTO pdto = new PeopleDTO(); pdto.FirstName = "qqqq"; pdto.LastName = "eeee"; pdto.SecondName = "wwww"; pdto.Email = ""; pdto.DateBirthday = DateTime.Now; var result = peopleserv.EditPeople(pdto); Assert.AreEqual(result.ErrorMessage, "validation error"); }
private void btAdd_Click(object sender, EventArgs e) { PeopleDTO people = new PeopleDTO(); Form4 f4 = new Form4(true); f4.TranslationPeople(people, listPhongBan, "Add", true); f4.ShowDialog(); txttrang2.Text = null; txttrang2.Text = txtTrang.Text; if (txtTrang.Text == "") { soTrang = 1; txttrang2.Text = 1.ToString(); } }
private void btnDoneofEdit_click(object sender, RoutedEventArgs e) { PeopleDTO item = (PeopleDTO)listviewUser.SelectedItems[0]; if (!AdminBUS.resetPassword(item.Id, password_user_infor.Password, item.Type)) { MessageBox.Show("Change password failed"); return; } btnEdit.Visibility = Visibility.Visible; btnDoneOfEdit.Visibility = Visibility.Collapsed; password_user_infor.IsEnabled = false; btnCancel.Visibility = Visibility.Collapsed; }
public void AddPeopleTest() { PeopleDTO pdto = new PeopleDTO(); pdto.FirstName = "qqqq"; pdto.LastName = "eeee"; pdto.SecondName = "wwww"; pdto.Email = "*****@*****.**"; pdto.DateBirthday = DateTime.Now; var result = peopleserv.AddPeople(pdto); peopleserv.DelPeople(result.Id); Assert.AreEqual(result.Successed, true); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } PeopleDTO = await _context.PeopleDTO.FirstOrDefaultAsync(m => m.Id == id); if (PeopleDTO == null) { return(NotFound()); } return(Page()); }
/// <summary> /// Thêm nhân viên /// </summary> /// <param name="pp">đối tượng Nhân viên DTO</param> /// <returns></returns> public int ThemNhanVien(PeopleDTO pp) { Providers provi = new Providers(); int kq = provi.ThemNhanVien(pp.KH, pp.FName, pp.LName, pp.GioiTinh, pp.DOB, pp.HD, pp.QueQuan, pp.MaPB, pp.IDNQL, pp.KHNQL, pp.MaCV); if (kq >= 0) { return(kq); } else { MessageBox.Show("Xử lý lổi", "Error"); return(-1); } }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } PeopleDTO = await _context.PeopleDTO.FindAsync(id); if (PeopleDTO != null) { _context.PeopleDTO.Remove(PeopleDTO); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public void EditPeople(PeopleDTO peopleDto) { if (ValidatePeople(peopleDto)) { var people = this.database.Peoples.Get(peopleDto.Id); people.FirstName = peopleDto.FirstName; people.LastName = peopleDto.LastName; people.SecondName = peopleDto.SecondName; people.Email = peopleDto.Email; people.Phone = peopleDto.Phone; people.DateBirthday = peopleDto.DateBirthday; this.database.Peoples.Update(people); EventChanges = new EditOperation(EventChanges); EventChanges.AddOperation(); Save(); } }
static void Main(string[] args) { Console.WriteLine("Hello World!"); var client = new MongoClient("mongodb://localhost:27017"); var database = client.GetDatabase("school"); var peopleDB = database.GetCollection <People>("people"); var people = new People() { Id = "6089d0ab6c3db54c32838b99", Edad = 30, Nombre = "oscar cortez villca" }; // peopleDB.InsertOne(people); List <People> lstPeople = peopleDB.Find(d => true).ToList(); lstPeople.ForEach(person => { Console.WriteLine($"id: {person.Id}, Nombre: {person.Nombre} Edad: {person.Edad}"); }); //peopleDB.ReplaceOne( // d => d.Id == "6089d0ab6c3db54c32838b99", // people //); //peopleDB.DeleteOne(d => d.Id == "6089d0ab6c3db54c32838b99"); MapperConfiguration PeopleConfig = new MapperConfiguration(cfg => cfg.CreateMap <People, PeopleDTO>() ); // and if the attribute name is different // . ForMember ( dest = > dest. FullName , act = > act. MapFrom ( src = > src. Name )) Mapper mapper = new Mapper(PeopleConfig); PeopleDTO peopleDTO2 = mapper.Map <People, PeopleDTO>(people); //var peopleDTO = mapper.Map<PeopleDTO>(people); Console.WriteLine($"nombre: {peopleDTO2.Nombre}, edad: {peopleDTO2.Edad}, id: {peopleDTO2.Id}"); }
public async Task <XElement> GetPeoples(string sessionKey, long requestId) { #region Заглушка var hubConn = new HubConnection(Settings.Default.ResponseHubUrl); var hubProxy = hubConn.CreateHubProxy("ResponseHub"); await hubConn.Start(); var result = PeopleDTO.ArrayToXElement(new PeopleDTO[] { new PeopleDTO() { Id = Guid.NewGuid(), Name = "Артем Аленин", }, new PeopleDTO() { Id = Guid.NewGuid(), Name = "Иванов Александр", }, new PeopleDTO() { Id = Guid.NewGuid(), Name = "Денис Стенюшкин" }, new PeopleDTO() { Id = Guid.NewGuid(), Name = "Малышева Ирина" }, new PeopleDTO() { Id = Guid.NewGuid(), Name = "Валерий Рябов" } }); result.Add(new XElement("rc", 0)); result.Add(new XElement("msg", "")); hubProxy.Invoke("OperationCallback", sessionKey, requestId, result); return(zapad.Model.API.ReturnCodes.BuildRcAnswer(0, "Успешно")); #endregion }
public PeopleDTO AddPeople(PeopleDTO peopleDto) { if (peopleDto == null) { return(new PeopleDTO { Successed = false, ErrorMessage = "People not be null" }); } if (ValidatePeople(peopleDto)) { People people = new People { FirstName = peopleDto.FirstName, LastName = peopleDto.LastName, SecondName = peopleDto.SecondName, DateBirthday = peopleDto.DateBirthday, Email = peopleDto.Email }; var peopleRes = this.database.Peoples.Create(people); this.EventChanges = new AddingOperation(EventChanges); this.EventChanges.AddOperation(peopleRes.Id); Save(); return(new PeopleDTO { Id = peopleRes.Id, FirstName = peopleRes.FirstName, LastName = peopleRes.LastName, SecondName = peopleRes.SecondName, Email = peopleRes.Email, DateBirthday = peopleRes.DateBirthday, Successed = true }); } return(new PeopleDTO { Successed = false, ErrorMessage = "validation error" }); }
public void AddPeople(PeopleDTO peopleDto) { if (ValidatePeople(peopleDto)) { People people = new People { FirstName = peopleDto.FirstName, LastName = peopleDto.LastName, SecondName = peopleDto.SecondName, DateBirthday = peopleDto.DateBirthday, Email = peopleDto.Email, Phone = peopleDto.Phone }; this.database.Peoples.Create(people); EventChanges = new AddingOperation(EventChanges); EventChanges.AddOperation(); Save(); } }
public async Task <IActionResult> GetById(int id) { if (id == 0) { return(BadRequest()); } People people = await _peopleUseCase.GetById(id); if (people == null) { return(NotFound()); } List <Car> car = await _carUseCase.GetCarsByPeopleId(id); PeopleDTO peopleDTO = PeopleMapper.MapperModelToDTO(people, car); return(Ok(peopleDTO)); }
public PeopleDTO EditPeople(PeopleDTO peopleDto) { if (peopleDto == null) { return new PeopleDTO { Successed = false, ErrorMessage = "People not be null" } } ; if (this.ValidatePeople(peopleDto)) { var peopleTask = Task.Factory.StartNew(() => this.database.Peoples.Get(peopleDto.Id)); var people = peopleTask.Result; people.FirstName = peopleDto.FirstName; people.LastName = peopleDto.LastName; people.SecondName = peopleDto.SecondName; people.Email = peopleDto.Email; people.DateBirthday = peopleDto.DateBirthday; this.database.Peoples.Update(people); this.EventChanges = new EditOperation(EventChanges); this.EventChanges.AddOperation(people.Id); Save(); peopleDto.Successed = true; return(peopleDto); } return(new PeopleDTO { Successed = false, ErrorMessage = "validation error" }); }
public IEnumerable <PeopleDTO> FindPeoples(string filter) { var peoplesTask = Task.Factory.StartNew(() => database.Peoples.Find(p => findFynction(p, filter))); var peoplesResult = new List <PeopleDTO>(); var mapper = new MapperConfiguration(cfg => cfg.CreateMap <Phone, PhoneDTO>()).CreateMapper(); foreach (var people in peoplesTask.Result) { var phones = mapper.Map <IEnumerable <Phone>, List <PhoneDTO> >(people.Phones); var peopleDTO = new PeopleDTO { Id = people.Id, FirstName = people.FirstName, LastName = people.LastName, SecondName = people.SecondName, Email = people.Email, DateBirthday = people.DateBirthday, Phones = phones }; peoplesResult.Add(peopleDTO); } return(peoplesResult); }