public async Task <IActionResult> PostAwsS3([FromBody] dynamic data)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //Parse Data
            Newtonsoft.Json.Linq.JToken[] dataArray = ((Newtonsoft.Json.Linq.JContainer)data).ToArray();
            string imageData = dataArray[0].First.ToString();
            string unquieID  = dataArray[1].First.ToString();
            string name      = dataArray[2].First.ToString();


            string link = S3Items.uploadS3Object(imageData, unquieID);


            if (link != null)
            {
                AwsS3 awsS3 = new AwsS3()
                {
                    UniqueCode            = unquieID,
                    Name                  = name,
                    Filename              = "",
                    EmailStatus           = "Sent",
                    UploadedDate          = DateTime.Now.ToShortDateString(),
                    ImageLink             = link,
                    ApprovalStatus        = "Pending",
                    ApprovalDecisionNotes = ""
                };

                _context.AwsS3.Add(awsS3);

                try
                {
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateException)
                {
                    if (AwsS3Exists(awsS3.Id))
                    {
                        return(new StatusCodeResult(StatusCodes.Status409Conflict));
                    }
                    else
                    {
                        throw;
                    }
                }
                return(CreatedAtAction("GetAwsS3", new { id = awsS3.Id }, awsS3));
            }
            return(BadRequest());
        }
Exemple #2
0
        public async Task <IActionResult> PostAwsS3([FromBody] dynamic data)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //Parse Data
            Newtonsoft.Json.Linq.JToken[] dataArray = ((Newtonsoft.Json.Linq.JContainer)data).ToArray();
            string imageData = "";
            string unquieID  = "";
            string name      = "";

            foreach (var item in dataArray)
            {
                if (item.Path.ToString().Equals("data"))
                {
                    imageData = item.First.ToString();
                }
                else if (item.Path.ToString().Equals("filename"))
                {
                    name = item.First.ToString();
                }
                else if (item.Path.ToString().Equals("id"))
                {
                    unquieID = item.First.ToString();
                }
            }

            var awsS3 = await _context.AwsS3.SingleOrDefaultAsync(m => m.UniqueCode == unquieID);

            if (awsS3 == null)
            {
                return(NotFound());
            }
            string link = S3Items.uploadS3Object(imageData, unquieID);

            if (link != null)
            {
                awsS3.UniqueCode            = unquieID;
                awsS3.Filename              = name;
                awsS3.UploadedDate          = DateTime.Now.ToString("G");
                awsS3.ImageLink             = link;
                awsS3.ApprovalStatus        = "Pending";
                _context.Entry(awsS3).State = EntityState.Modified;
                try
                {
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AwsS3Exists(awsS3.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(NoContent());
            }
            return(BadRequest());
        }