BenefitsAllocationUpload.Controllers.ReportsController.Upload C# (CSharp) Method

Upload() public method

public Upload ( string id ) : System.Web.Mvc.ActionResult
id string
return System.Web.Mvc.ActionResult
        public ActionResult Upload(string id)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                TempData["Message"] = "Unable to upload file.  No file was selected. Please select a file and try again.";
                return RedirectToAction("Index");
            }

            var file = GetNamedFile(id);
            string filename = file.FileName;

            //var user = BenefitsAllocation.Core.Domain.User.GetByLoginId(Repository, User.Identity.Name);
            var user = Models.User.FindByLoginId(System.Web.HttpContext.Current.User.Identity.Name);
            var unit = user.Units.FirstOrDefault();
            var schoolCode = unit.DeansOfficeSchoolCode;

            _sftpService.UploadFile(filename, schoolCode);

            var unitFile = _unitFileRepository.Queryable.FirstOrDefault(x => x.Filename == filename);

            if (unitFile == null)
            {
                //var user = BenefitsAllocation.Core.Domain.User.GetByLoginId(Repository, User.Identity.Name);
                //var unit = user.Units.FirstOrDefault();
                unitFile = new UnitFile()
                    {
                        Filename = filename,
                        SchoolCode = unit.DeansOfficeSchoolCode,
                        UnitId = unit.UnitID
                    };
            }

            unitFile.Uploaded = DateTime.Now;
            unitFile.UploadedBy = User.Identity.Name;

            _unitFileRepository.EnsurePersistent(unitFile);

            Message = String.Format("File \"{0}\" has been uploaded.", filename);
            return RedirectToAction("Index");
        }