public async Task <IActionResult> Edit(int id, [Bind("Id,LakeId,WaterLevel,LakeArea,WaterMassVolume")] BathigraphicAndVolumetricCurveData bathigraphicAndVolumetricCurveData)
        {
            if (id != bathigraphicAndVolumetricCurveData.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(bathigraphicAndVolumetricCurveData);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BathigraphicAndVolumetricCurveDataExists(bathigraphicAndVolumetricCurveData.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(bathigraphicAndVolumetricCurveData));
        }
        public async Task <IActionResult> Create([Bind("Id,LakeId,WaterLevel,LakeArea,WaterMassVolume")] BathigraphicAndVolumetricCurveData bathigraphicAndVolumetricCurveData)
        {
            if (ModelState.IsValid)
            {
                _context.Add(bathigraphicAndVolumetricCurveData);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(bathigraphicAndVolumetricCurveData));
        }
        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 <BathigraphicAndVolumetricCurveData> bathigraphicAndVolumetricCurveDatas = new List <BathigraphicAndVolumetricCurveData>();
                    for (int i = start_row; ; i++)
                    {
                        if (package.Workbook.Worksheets.FirstOrDefault().Cells[i, 1].Value == null)
                        {
                            break;
                        }
                        BathigraphicAndVolumetricCurveData bathigraphicAndVolumetricCurveData = new BathigraphicAndVolumetricCurveData();

                        try
                        {
                            bathigraphicAndVolumetricCurveData.LakeId     = Convert.ToInt32(package.Workbook.Worksheets.FirstOrDefault().Cells[i, 1].Value);
                            bathigraphicAndVolumetricCurveData.WaterLevel = package.Workbook.Worksheets.FirstOrDefault().Cells[i, 2].Value == null ?
                                                                            (decimal?)null :
                                                                            Convert.ToDecimal(package.Workbook.Worksheets.FirstOrDefault().Cells[i, 2].Value);
                            bathigraphicAndVolumetricCurveData.LakeArea = package.Workbook.Worksheets.FirstOrDefault().Cells[i, 3].Value == null ?
                                                                          (decimal?)null :
                                                                          Convert.ToDecimal(package.Workbook.Worksheets.FirstOrDefault().Cells[i, 3].Value);
                            bathigraphicAndVolumetricCurveData.WaterMassVolume = package.Workbook.Worksheets.FirstOrDefault().Cells[i, 4].Value == null ?
                                                                                 (decimal?)null :
                                                                                 Convert.ToDecimal(package.Workbook.Worksheets.FirstOrDefault().Cells[i, 4].Value);
                        }
                        catch (Exception e)
                        {
                            ViewBag.Error = $"{_sharedLocalizer["Row"]} {i.ToString()}: " + e.Message + (e.InnerException == null ? "" : ": " + e.InnerException.Message);
                            break;
                        }

                        bathigraphicAndVolumetricCurveDatas.Add(bathigraphicAndVolumetricCurveData);
                        _context.Add(bathigraphicAndVolumetricCurveDatas.LastOrDefault());
                    }
                    if (string.IsNullOrEmpty(ViewBag.Error))
                    {
                        _context.SaveChanges();
                        ViewBag.Report = $"{_sharedLocalizer["UploadedCount"]}: {bathigraphicAndVolumetricCurveDatas.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());
        }