예제 #1
0
        public async Task <IActionResult> PutTeam([FromRoute] Guid id, [FromBody] Team team)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != team.Id)
            {
                return(BadRequest());
            }

            _context.Entry(team).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TeamExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #2
0
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> Post(PhotoInputModel input)
        {
            var challenge = await _context.Challenges.Where(c => c.Id == input.Challenge).FirstOrDefaultAsync();

            if (challenge == null)
            {
                return(BadRequest("Challenge not found"));
            }
            Team team = await _context.Teams.Where(t => t.Id == input.Team).FirstOrDefaultAsync();

            if (team == null)
            {
                return(BadRequest("Team not found"));
            }

            var guid = Guid.NewGuid();

            var photo = new Photo
            {
                Team = team,
                //Text = input.Text,
                Challenge = challenge,
                Id        = guid
            };

            if (_context.Photos.Include(t => t.Team).Include(c => c.Challenge)
                .Count(t => t.Team.Id == team.Id && t.Challenge.Id == challenge.Id) > 0)
            {
                return(BadRequest("Allready posted"));
            }
            if (ModelState.IsValid)
            {
                var filePathPhoto = Path.GetTempFileName();

                using (var stream = new FileStream(filePathPhoto, FileMode.Create))
                {
                    await input.Photo.CopyToAsync(stream);
                }

                //var filePathPhotoResized = ResizeImage(filePathPhoto);

                var photoResizedBlobPath = await uploadToAzureBlob(guid, filePathPhoto);

                photo.BlobPath = photoResizedBlobPath;
                _context.Add(photo);
                await _context.SaveChangesAsync();

                System.IO.File.Delete(filePathPhoto);
                //System.IO.File.Delete(filePathPhotoResized);
            }
            return(Ok());
        }
        public async Task <IActionResult> Post([FromBody] ChallengeInputModel input)
        {
            var challenge = new Challenge()
            {
                Id              = new Guid(),
                Description     = input.Text,
                ReleaseDateTime = input.ReleaseDate
            };

            _context.Add(challenge);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("Get", new { id = challenge.Id }, challenge));
        }