Esempio n. 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,LakeId,FishId,SurveyYear,ZooplanktonBiomass,BenthosBiomass,SpeciesWealthIndex,FishCatchLimit,CurrentCommercialFishProductivity,PotentialFishProducts,PotentialGrowingVolume,CurrentUsage,RecommendedUse")] GeneralHydrobiologicalIndicator generalHydrobiologicalIndicator)
        {
            if (id != generalHydrobiologicalIndicator.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(generalHydrobiologicalIndicator);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GeneralHydrobiologicalIndicatorExists(generalHydrobiologicalIndicator.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(generalHydrobiologicalIndicator));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([Bind("Id,LakeId,FishId,SurveyYear,ZooplanktonBiomass,BenthosBiomass,SpeciesWealthIndex,FishCatchLimit,CurrentCommercialFishProductivity,PotentialFishProducts,PotentialGrowingVolume,CurrentUsage,RecommendedUse")] GeneralHydrobiologicalIndicator generalHydrobiologicalIndicator)
        {
            if (ModelState.IsValid)
            {
                _context.Add(generalHydrobiologicalIndicator);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(generalHydrobiologicalIndicator));
        }
Esempio n. 3
0
        public async Task <IActionResult> Upload(bool FirstRowHeader, IFormFile File)
        {
            try
            {
                string sContentRootPath = _hostingEnvironment.WebRootPath;
                sContentRootPath = Path.Combine(sContentRootPath, "Uploads");
                DirectoryInfo di = new DirectoryInfo(sContentRootPath);
                foreach (FileInfo filed in di.GetFiles())
                {
                    try
                    {
                        filed.Delete();
                    }
                    catch
                    {
                    }
                }
                string path_filename = Path.Combine(sContentRootPath, Path.GetFileName(File.FileName));
                using (var stream = new FileStream(Path.GetFullPath(path_filename), FileMode.Create))
                {
                    await File.CopyToAsync(stream);
                }
                FileInfo fileinfo = new FileInfo(Path.Combine(sContentRootPath, Path.GetFileName(path_filename)));
                using (ExcelPackage package = new ExcelPackage(fileinfo))
                {
                    int start_row = 1;
                    if (FirstRowHeader)
                    {
                        start_row++;
                    }
                    List <GeneralHydrobiologicalIndicator> waterBalances = new List <GeneralHydrobiologicalIndicator>();
                    for (int i = start_row; ; i++)
                    {
                        if (package.Workbook.Worksheets.FirstOrDefault().Cells[i, 1].Value == null)
                        {
                            break;
                        }
                        GeneralHydrobiologicalIndicator waterBalance = new GeneralHydrobiologicalIndicator();

                        try
                        {
                            waterBalance.LakeId             = Convert.ToInt32(package.Workbook.Worksheets.FirstOrDefault().Cells[i, 1].Value);
                            waterBalance.FishId             = Convert.ToInt32(package.Workbook.Worksheets.FirstOrDefault().Cells[i, 2].Value);
                            waterBalance.SurveyYear         = Convert.ToInt32(package.Workbook.Worksheets.FirstOrDefault().Cells[i, 3].Value);
                            waterBalance.ZooplanktonBiomass = package.Workbook.Worksheets.FirstOrDefault().Cells[i, 4].Value == null ?
                                                              (decimal?)null :
                                                              Convert.ToDecimal(package.Workbook.Worksheets.FirstOrDefault().Cells[i, 4].Value);
                            waterBalance.SpeciesWealthIndex = package.Workbook.Worksheets.FirstOrDefault().Cells[i, 5].Value == null ?
                                                              (decimal?)null :
                                                              Convert.ToDecimal(package.Workbook.Worksheets.FirstOrDefault().Cells[i, 5].Value);
                            waterBalance.FishCatchLimit = package.Workbook.Worksheets.FirstOrDefault().Cells[i, 6].Value == null ?
                                                          (decimal?)null :
                                                          Convert.ToDecimal(package.Workbook.Worksheets.FirstOrDefault().Cells[i, 6].Value);
                            waterBalance.CurrentCommercialFishProductivity = package.Workbook.Worksheets.FirstOrDefault().Cells[i, 7].Value == null ?
                                                                             (decimal?)null :
                                                                             Convert.ToDecimal(package.Workbook.Worksheets.FirstOrDefault().Cells[i, 7].Value);
                            waterBalance.PotentialFishProducts = package.Workbook.Worksheets.FirstOrDefault().Cells[i, 8].Value == null ?
                                                                 (decimal?)null :
                                                                 Convert.ToDecimal(package.Workbook.Worksheets.FirstOrDefault().Cells[i, 8].Value);
                            waterBalance.PotentialGrowingVolume = package.Workbook.Worksheets.FirstOrDefault().Cells[i, 9].Value == null ?
                                                                  (decimal?)null :
                                                                  Convert.ToDecimal(package.Workbook.Worksheets.FirstOrDefault().Cells[i, 9].Value);
                            waterBalance.CurrentUsage = package.Workbook.Worksheets.FirstOrDefault().Cells[i, 10].Value == null ?
                                                        (decimal?)null :
                                                        Convert.ToDecimal(package.Workbook.Worksheets.FirstOrDefault().Cells[i, 10].Value);
                            waterBalance.RecommendedUse = package.Workbook.Worksheets.FirstOrDefault().Cells[i, 11].Value == null ?
                                                          (decimal?)null :
                                                          Convert.ToDecimal(package.Workbook.Worksheets.FirstOrDefault().Cells[i, 11].Value);
                        }
                        catch (Exception e)
                        {
                            ViewBag.Error = $"{_sharedLocalizer["Row"]} {i.ToString()}: " + e.Message + (e.InnerException == null ? "" : ": " + e.InnerException.Message);
                            break;
                        }

                        waterBalances.Add(waterBalance);
                        _context.Add(waterBalances.LastOrDefault());
                    }
                    if (string.IsNullOrEmpty(ViewBag.Error))
                    {
                        _context.SaveChanges();
                        ViewBag.Report = $"{_sharedLocalizer["UploadedCount"]}: {waterBalances.Count()}";
                    }
                }
                foreach (FileInfo filed in di.GetFiles())
                {
                    try
                    {
                        filed.Delete();
                    }
                    catch
                    {
                    }
                }
            }
            catch (Exception e)
            {
                if (File != null)
                {
                    ViewBag.Error = e.Message + (e.InnerException == null ? "" : ": " + e.InnerException.Message);
                }
            }
            return(View());
        }