예제 #1
0
        public async Task <IActionResult> PutScretch([FromRoute] int id, [FromBody] Scretch scretch)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(NoContent());
        }
예제 #2
0
        public async Task <IActionResult> PostScretch([FromBody] Scretch scretch)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = await _userManager.FindByEmailAsync(User.Identity.Name);

            scretch.ScretchName      = "Scretch for user " + user.Email;
            scretch.IdentifierOfUser = user.Id;

            _context.Scretches.Add(scretch);
            await _context.SaveChangesAsync();

            return(Ok(scretch.Id));
        }
예제 #3
0
        public async Task <IActionResult> PostScretchWithId([FromBody] Scretch scretch)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var temp = _context.Scretches.FirstOrDefault(x => x.Id == scretch.Id);

            temp.Date = scretch.Date;
            temp.Busy = scretch.Busy;

            var user = await _userManager.FindByEmailAsync(User.Identity.Name);

            temp.IdentifierOfUser = user.Id;

            await _context.SaveChangesAsync();

            return(Ok());
        }