Exemplo n.º 1
0
 private ProjectLink GenerateProjectLink(Image image, string projectName)
 {
     return(new ProjectLink()
     {
         ProjectName = projectName,
         IId = image.IId
     });
 }
Exemplo n.º 2
0
 private LogLink GenerateLogLink(Image image, Log log)
 {
     return(new LogLink()
     {
         IId = image.IId,
         LId = log.LId
     });
 }
Exemplo n.º 3
0
        public Object SubmitImage([FromBody] Submission submission)
        {
            Log          dbLog  = GenerateLog(submission.Images.Count.ToString() + " images submitted");
            List <Image> images = new List <Image>();

            try
            {
                _context.Add(dbLog);
                _context.SaveChanges();
            }
            catch (Exception e)
            {
                Console.Write(e);
                return(BadRequest("malform request log"));
            }

            foreach (string imageid in submission.Images)
            {
                try
                {
                    Image image = (Image)_context.Image.Where(i => i.IId == imageid).First();
                    image.Submitted = true;
                    ProjectLink dbProjectLink = GenerateProjectLink(image, submission.Project);
                    LogLink     dbLogLink     = GenerateLogLink(image, dbLog);

                    _context.Add(dbLogLink);
                    _context.Add(dbProjectLink);
                    _context.SaveChanges();
                }
                catch (Exception e)
                {
                    Console.Write(e);
                    return(BadRequest("malform request project"));
                }
            }

            try
            {
                var username = HttpContext.User.FindFirstValue("name");
                var logLink  = "https://aeimagehub.azurewebsites.net/logview?src=%22" + dbLog.LId + "%22";
                sendEmail(User.FindFirst(ClaimTypes.Email)?.Value, username, logLink);
            }
            catch (Exception e)
            {
                Console.Write(e.Message);
            }

            return(Ok());
        }