public async Task <IActionResult> UploadNewFile(
            [Bind("FirstName", "LastName", "SupervisorId", "ProgrammeId")] UploadApplicationModel uploadApplication,
            IEnumerable <IFormFile> file,
            List <string> title)
        {
            /* Create a new object application with attributes from the HttpPost to add to the database */
            var application = new Application
            {
                FirstName         = uploadApplication.FirstName,
                LastName          = uploadApplication.LastName,
                Programme         = _programme.GetProgrammeById(uploadApplication.ProgrammeId),
                Supervisor        = _user.GetSupervisorById(uploadApplication.SupervisorId),
                ApplicationStatus = "Pending_Supervisor_Approval"
            };



            _application.Add(application);


            int i = 0;

            foreach (var f in file)
            {
                /* Get all titles from frontend */
                string fileTitle = title.ElementAt(i);
                i = i + 1;

                /* Send the connection string and the name of the container on Azure Blob Storage */
                string azureConnection = _config.GetConnectionString("AzureStorageConnectionString");
                var    container       = _applicationFiles.GetBlobContainer(azureConnection, "applicationfiles");
                var    content         = ContentDispositionHeaderValue.Parse(f.ContentDisposition);

                /* Returns name without quotes */
                var fileName = content.FileName.Trim('"');

                /* Get a reference to a block blob */
                var blockBlob = container.GetBlockBlobReference(fileName);
                await blockBlob.UploadFromStreamAsync(f.OpenReadStream());

                await _applicationFiles.SetFile(fileTitle, blockBlob.Uri);
            }


            /* Use service to send email to supervisor */
            _email.sendEmail(application.Supervisor.Email, application.Supervisor.FirstName, "Pending Supervisor approval", "Please view https://pgasystem.azurewebsites.net/ViewFiles/?applicationId=" + _application.GetLastApplicationId());
            return(RedirectToAction("Create"));
        }
Esempio n. 2
0
 public void Post([FromBody] Client value)
 {
     _app.Add(value);
 }
Esempio n. 3
0
 /// <summary>
 /// 添加一条数据
 /// </summary>
 /// <param name="model">数据实体</param>
 /// <returns></returns>
 public int Add(Models.APP.Application model)
 {
     return(dal.Add(model));
 }