Пример #1
0
        public async Task <IActionResult> Create([Bind("SourceName,SourceCode,NameFile,FormatFile,HasFile,Id")] SourceSanction sourceSanction)
        {
            if (ModelState.IsValid)
            {
                _context.Add(sourceSanction);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(sourceSanction));
        }
Пример #2
0
        public async Task <IActionResult> Create(SourceSanctionModel model, IFormFile formFile)
        {
            if (ModelState.IsValid)
            {
                SourceSanction sourceSanction = new SourceSanction();
                sourceSanction.FormatFile = model.FormatFile;
                sourceSanction.HasFile    = model.HasFile;
                model.NameFile            = model.NameFile;
                sourceSanction.SourceName = model.SourceName;

                //if (model.FormFile != null)
                //{
                //    string importFolder = Path.Combine(_hostingEnvironment.WebRootPath, "ImportFiles");
                //    string filePath = Path.Combine(importFolder, model.FormFile.FileName);
                //    Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
                //    var excelDataTable = GetDataTableFromExcel(filePath);

                //    List<Sanction> sanctions = new List<Sanction>();
                //    sanctions = excelDataTable.AsEnumerable().Select(c => new Sanction
                //    {
                //        AdditionalInformation = Convert.ToString(c["AdditionalInformation"]),
                //        Address = Convert.ToString(c["Address"]),
                //        Citizenship = Convert.ToString(c["Citizenship"]),
                //        Committees = Convert.ToString(c["Committees"]),
                //        ControlDate = Convert.ToString(c["ControlDate"]),
                //        CountryRelated = Convert.ToString(c["CountryRelated"]),
                //        DateofBirth = Convert.ToString(c["DateofBirth"]),
                //        EntityType = Convert.ToString(c["Type"]),
                //        InsertDate = Convert.ToString(DateTime.Now.Date),
                //        IsActive = Convert.ToByte(1),
                //        LegalName = Convert.ToString(c["NameofIndividualorEntity"]),
                //        ListingInformation = Convert.ToString(c["ListingInformation"]),
                //        NameType = Convert.ToString(c["NameType"]),
                //        PlaceofBirth = Convert.ToString(c["PlaceofBirth"]),
                //        SactionUID = new Guid(),
                //    }).ToList();
                //}
                _context.SourceSanctions.Add(sourceSanction);
                await _context.SaveChangesAsync();

                //return RedirectToAction("Index");
            }
            return(View(model));
        }