public void AddUser(string username, bool sort) { if (!HasUser(username)) { string prefix = null; if (username.Length > 2) { prefix = username[0] + "" + username[1]; } else { prefix = username[0] + ""; } User user = new User { Nick = username.Replace("@", "").Replace("+", ""), Prefix = prefix }; RawUsers.Add(user.Nick); Users.Add(user); if (sort) { SortUsers(); } } }
public void RemoveUser(string nick) { if (Users.Any(user => user.Nick == nick)) { var user = Users.First(u => u.Nick == nick); Users.Remove(user); RawUsers.Remove(user.Nick); SortUsers(); } }
/// <summary> /// Excel'den alınan verileri User nesnesine çevirme. /// </summary> /// <param name="rawUsers">Excel'den okunan verilerin RawUsers Tablosundaki nesne karşılığı</param> /// <returns></returns> public static Users RawUserToUser(RawUsers rawUsers) { var user = new Users { Adi = rawUsers.Adi, Soyadi = rawUsers.Soyadi, Adres = rawUsers.Adres, Aciklama = rawUsers.Aciklama, ID = rawUsers.ID, Kart_ID = rawUsers.Kart_ID, Dogrulama_PIN = rawUsers.Dogrulama_PIN, Kimlik_PIN = rawUsers.Kimlik_PIN, Kullanici_Tipi = rawUsers.Kullanici_Tipi, Sifre = rawUsers.Sifre, Gecis_Modu = rawUsers.Gecis_Modu, Grup_No = rawUsers.Grup_No, Visitor_Grup_No = rawUsers.Visitor_Grup_No, Resim = rawUsers.Resim, Plaka = rawUsers.Plaka, TCKimlik = rawUsers.TCKimlik, Blok_No = rawUsers.Blok_No, Daire = rawUsers.Daire, Gorev = rawUsers.Gorev, Departman_No = rawUsers.Departman_No, Sirket_No = rawUsers.Sirket_No, Iptal = rawUsers.Iptal, Grup_Takvimi_Aktif = rawUsers.Grup_Takvimi_Aktif, Grup_Takvimi_No = rawUsers.Grup_Takvimi_No, Saat_1 = rawUsers.Saat_1, Saat_2 = rawUsers.Saat_2, Saat_3 = rawUsers.Saat_3, Grup_No_1 = rawUsers.Grup_No_1, Grup_No_2 = rawUsers.Grup_No_2, Grup_No_3 = rawUsers.Grup_No_3, Tmp = rawUsers.Tmp, Sureli_Kullanici = rawUsers.Sureli_Kullanici, Bitis_Tarihi = rawUsers.Bitis_Tarihi, Telefon = rawUsers.Telefon, C3_Grup = rawUsers.C3_Grup }; return(user); }
public ActionResult ImportUser(HttpPostedFileBase excelFile, ExcelUserType excelUserType) { if (excelFile == null || excelFile.ContentLength == 0) { ViewBag.Error = "Lütfen Excel Dosyası Seçin!"; return(View("UserImport")); } else { if (excelFile.FileName.EndsWith("xls") || excelFile.FileName.EndsWith("xlsx")) { string path = Server.MapPath("~/ExcelFile/" + Guid.NewGuid() + excelFile.FileName); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } excelFile.SaveAs(path); //Read Data From Excel File Excel.Application application = new Excel.Application(); Excel.Workbook workbook = application.Workbooks.Open(path); Excel.Worksheet worksheet = workbook.ActiveSheet; Excel.Range range = worksheet.UsedRange; List <RawUsers> userList = new List <RawUsers>(); for (int i = 2; i <= range.Rows.Count; i++) { RawUsers user = new RawUsers { ID = int.Parse(((Excel.Range)range.Cells[i, excelUserType.ID]).Text) == null ? 0 : int.Parse(((Excel.Range)range.Cells[i, excelUserType.ID]).Text), Kart_ID = ((Excel.Range)range.Cells[i, excelUserType.Kart_ID]).Text == null ? "" : ((Excel.Range)range.Cells[i, excelUserType.Kart_ID]).Text, Adi = ((Excel.Range)range.Cells[i, excelUserType.Adi]).Text == null ? "" : ((Excel.Range)range.Cells[i, excelUserType.Adi]).Text, Soyadi = ((Excel.Range)range.Cells[i, excelUserType.Soyadi]).Text == null ? "" : ((Excel.Range)range.Cells[i, excelUserType.Soyadi]).Text, Grup_No = int.Parse(((Excel.Range)range.Cells[i, excelUserType.Grup_No]).Text) == null ? 0 : int.Parse(((Excel.Range)range.Cells[i, excelUserType.Grup_No]).Text), Plaka = ((Excel.Range)range.Cells[i, excelUserType.Plaka]).Text == null ? "" : ((Excel.Range)range.Cells[i, excelUserType.Plaka]).Text, Sirket_No = int.Parse(((Excel.Range)range.Cells[i, excelUserType.Sirket_No]).Text) == null ? 0 : int.Parse(((Excel.Range)range.Cells[i, excelUserType.Sirket_No]).Text), Departman_No = int.Parse(((Excel.Range)range.Cells[i, excelUserType.Departman_No]).Text) == null ? 0 : int.Parse(((Excel.Range)range.Cells[i, excelUserType.Departman_No]).Text), Telefon = ((Excel.Range)range.Cells[i, excelUserType.Telefon]).Text == null ? "" : ((Excel.Range)range.Cells[i, excelUserType.Telefon]).Text, TCKimlik = ((Excel.Range)range.Cells[i, excelUserType.TC_Kimlik]).Text == null ? "" : ((Excel.Range)range.Cells[i, excelUserType.TC_Kimlik]).Text, }; userList.Add(user); } application.Workbooks.Close(); _rawUsersService.DeleteAll(); foreach (var item in userList) { if (!_rawUsersService.GetAllRawUsers().Any(x => x.ID == item.ID)) { _rawUsersService.AddRawUsers(item); } else { _rawUsersService.UpdateRawUsers(item); } } return(RedirectToAction("SuccessImportUser")); } else { ViewBag.Error = "Dosya tipi geçersiz!"; return(View("UserImport")); } } }
public RawUsers UpdateRawUsers(RawUsers rawUsers) { return(_rawUsersDal.Update(rawUsers)); }
public void DeleteRawUsers(RawUsers rawUsers) { _rawUsersDal.Delete(rawUsers); }
public RawUsers AddRawUsers(RawUsers rawUsers) { return(_rawUsersDal.Add(rawUsers)); }