public ActionResult ImportGroup(HttpPostedFileBase excelFile, ExcelGroupType excelGroupType) { if (excelFile == null || excelFile.ContentLength == 0) { ViewBag.Error = "Lütfen Excel Dosyası Seçin!"; return(View("GroupImport")); } 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 <RawGroups> groupList = new List <RawGroups>(); for (int i = 2; i <= range.Rows.Count; i++) { RawGroups group = new RawGroups { Grup_No = int.Parse(((Excel.Range)range.Cells[i, excelGroupType.Grup_No]).Text) == null ? 0 : int.Parse(((Excel.Range)range.Cells[i, excelGroupType.Grup_No]).Text), Grup_Adi = ((Excel.Range)range.Cells[i, excelGroupType.Grup_Adi]).Text == null ? "" : ((Excel.Range)range.Cells[i, excelGroupType.Grup_Adi]).Text, }; groupList.Add(group); } foreach (var item in groupList) { if (!_rawGroupsService.GetAllRawGroups().Any(x => x.Grup_No == item.Grup_No)) { _rawGroupsService.AddRawGroups(item); } else { _rawGroupsService.UpdateRawGroups(item); } } return(RedirectToAction("SuccessImportGroup")); } else { ViewBag.Error = "Dosya tipi geçersiz!"; return(View("GroupImport")); } } }
public void DeleteRawGroups(RawGroups rawGroups) { _rawGroupsDal.Delete(rawGroups); }
public RawGroups UpdateRawGroups(RawGroups rawGroups) { return(_rawGroupsDal.Update(rawGroups)); }
public RawGroups AddRawGroups(RawGroups rawGroups) { return(_rawGroupsDal.Add(rawGroups)); }