Exemplo n.º 1
0
        public ActionResult SalaryDetails(SalaryDetailsViewModel inputModel)
        {
            SalaryDetailsViewModel outputModel = new SalaryDetailsViewModel();

            if (ModelState.IsValidField("Month") && ModelState.IsValidField("UploadedFile"))
            {
                string localFileFullName = Path.GetTempFileName();
                try
                {
                    string[] arr           = inputModel.Month.Split("/".ToArray(), StringSplitOptions.RemoveEmptyEntries);
                    string   selectedYear  = arr[1];
                    string   selectedMonth = arr[0];
                    if (inputModel.UploadedFile.ContentLength == 0)
                    {
                        ViewBag.ErrorMsg = "The uploaded file is empty";
                        return(View(inputModel));
                    }
                    else
                    {
                        Stream uploadFileStream     = inputModel.UploadedFile.InputStream;
                        string uploadFileFullName   = inputModel.UploadedFile.FileName;
                        string TableName            = uploadFileFullName.Split(".".ToArray())[0];
                        SalaryUploadService service = new SalaryUploadService(uploadFileFullName, uploadFileStream, selectedYear, selectedMonth, LoginName);
                        ReturnResultTable   rrt     = service.ReadFile();

                        if (rrt.Succeeded)
                        {
                            DataTable dt = rrt.SalaryTable;
                            outputModel.SalaryTable = dt;
                            outputModel.TableName   = TableName;
                            ViewBag.showTable       = true;
                        }
                        else
                        {
                            ViewBag.ErrorMsg = rrt.ErrorMsg;
                        }
                    }
                }
                catch (Exception ex)
                {
                    ViewBag.ErrorMsg = ex.Message;
                }
                ModelState.Clear();
                return(View(outputModel));
            }
            else
            {
                ViewBag.ErrorMsg = "the month or upload file is required";
            }
            return(View(outputModel));
        }
Exemplo n.º 2
0
 public ActionResult SalaryMail(SalaryFileModel sfViewModel)
 {
     if (ModelState.IsValid)
     {
         ViewBag.salaryDetail = false;
         if (sfViewModel.FileLoaded.ContentLength == 0)
         {
             ViewBag.ErrorMsg = "The upload file is empty.";
             return(View());
         }
         string   month, year;
         string   tempFileName = Path.GetTempFileName();
         string[] arr          = sfViewModel.Date.Split("/".ToArray(), StringSplitOptions.RemoveEmptyEntries);
         month = arr[0];
         year  = arr[1];
         try
         {
             SalaryUploadService fileService   = new SalaryUploadService(sfViewModel.FileLoaded.InputStream, sfViewModel.FileLoaded.FileName, year, month);
             SalaryFileModel     salaryService = fileService.ReadFile();
             sfViewModel.SalaryData = salaryService.SalaryData;
             ViewBag.salaryDetail   = true;
             return(View(sfViewModel));
         }
         catch (Exception ex)
         {
             ViewBag.ErrorMsg = ex.Message;
         }
         return(View());
     }
     else
     {
         StringBuilder sbErrors = new StringBuilder();
         foreach (var key in ModelState.Values)
         {
             foreach (var values in key.Errors)
             {
                 sbErrors.AppendLine(string.Format("{0}", values.ErrorMessage));
             }
         }
         ViewBag.ErrorMsg = sbErrors;
         return(View());
     }
 }