public async Task <IActionResult> AddCategoryWithExcel(Exel CategoryExel, CancellationToken cancellationToken) { if (CategoryExel.File.Length < 1) { AddNotification(NotifyType.Warning, OperationMessage.SelectFile.ToDisplay(), true); return(RedirectToAction("Index")); } try { string fName = Guid.NewGuid().ToString("D") + CategoryExel.File.FileName; using (var fileStream = new FileStream(Path.Combine(webHostEnvironment.WebRootPath, ApplicationPathes.CategoryExel.VirtualFolder, fName), FileMode.Create)) { await CategoryExel.File.CopyToAsync(fileStream); List <Category> CategoryExcel = new List <Category>(); using (var reader = ExcelReaderFactory.CreateOpenXmlReader(fileStream: fileStream)) { var items = reader.AsDataSet().Tables[index : 0].AsEnumerable().Skip(count : 0).ToList(); CategoryExcel = items.Select(x => new Category() { Title = x[columnIndex: 0]?.ToString(), Description = "", IsActive = true, ParentCategoryId = null, Image = x[columnIndex: 1]?.ToString(), }).ToList(); } var Listcategory = _CategoryService.TableNoTracking.Where(e => e.ParentCategoryId == null).ToList(); List <Category> resultlist = new List <Category>(); foreach (var item in CategoryExcel) { string name = item.Title; if (!Listcategory.Any(e => e.Title.Equals(name.Trim(), StringComparison.OrdinalIgnoreCase))) { item.Title = name.Trim(); resultlist.Add(item); } } await _CategoryService.AddRangeAsync(resultlist, cancellationToken); SuccessNotification(OperationMessage.FileSaved.ToDisplay(), true); return(RedirectToAction("Index")); } } catch (Exception ex) { ErrorNotification(OperationMessage.OperationFailed.ToDisplay(), true); return(RedirectToAction("Index")); } }
public async Task <IActionResult> AddProvinceToCountryWithExcel(Exel ProvinceExel, int CountryId, CancellationToken cancellationToken) { if (ProvinceExel.File.Length < 1) { AddNotification(NotifyType.Warning, OperationMessage.SelectFile.ToDisplay(), true); return(RedirectToAction("Province", new { CountryId = CountryId })); } try { string fName = Guid.NewGuid().ToString("D") + ProvinceExel.File.FileName; using (var fileStream = new FileStream(Path.Combine(webHostEnvironment.WebRootPath, ApplicationPathes.LocationExel.VirtualFolder, fName), FileMode.Create)) { await ProvinceExel.File.CopyToAsync(fileStream); List <Province> ProvinceExcel = new List <Province>(); using (var reader = ExcelReaderFactory.CreateOpenXmlReader(fileStream: fileStream)) { var items = reader.AsDataSet().Tables[index : 0].AsEnumerable().Skip(count : 0).ToList(); ProvinceExcel = items.Select(x => new Province() { Name = x[columnIndex: 0]?.ToString(), CountryId = CountryId }).ToList(); } var ListProvince = _ProvinceService.TableNoTracking.Where(e => e.CountryId == CountryId) .ToList(); List <Province> resultlist = new List <Province>(); foreach (var item in ProvinceExcel) { string name = item.Name; if (!ListProvince.Any(e => e.Name.Equals(name.Trim(), StringComparison.OrdinalIgnoreCase))) { item.Name = name.Trim(); resultlist.Add(item); } } await _ProvinceService.AddRangeAsync(resultlist, cancellationToken); SuccessNotification(OperationMessage.FileSaved.ToDisplay(), true); return(RedirectToAction("Province", new { CountryId = CountryId })); } } catch (Exception ex) { ErrorNotification(OperationMessage.OperationFailed.ToDisplay(), true); return(RedirectToAction("Province", new { CountryId = CountryId })); } }
public ProvinceDto() { ProvinceListDto = new HashSet <ProvinceListDto>(); City = new List <City>(); ProvinceExel = new Exel(); }
public CityDto() { CityListDto = new HashSet <CityListDto>(); CityExel = new Exel(); }
public SubCategoryDto() { SubCategoryListDto = new HashSet <SubCategoryListDto>(); Child = new List <Category>(); SubCategoryExel = new Exel(); }
public CategoryDto() { CategoryListDto = new HashSet <CategoryListDto>(); CategoryExel = new Exel(); }