public async Task <IActionResult> PutPlant([FromRoute] decimal id, [FromBody] Plant plant)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutChatroom([FromRoute] string id, [FromBody] Chatroom chatroom)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != chatroom.UserChat)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
示例#3
0
        public async Task <IActionResult> DeleteUsers([FromRoute] String username)
        {
            IList <String> role = await GetUsersRoles();

            if (role.Contains("Admin"))
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var uti = await _context.ApplicationUser.SingleOrDefaultAsync(m => m.UserName == username);

                if (uti == null)
                {
                    return(NotFound());
                }

                _context.ApplicationUser.Remove(uti);
                await _context.SaveChangesAsync();

                return(Ok(uti));
            }
            return(Unauthorized());
        }
示例#4
0
        public async Task <IActionResult> PutResponsible([FromRoute] decimal id, [FromBody] Responsible responsible)
        {
            IList <String> role = await GetUsersRoles();

            if (role.Contains("Admin"))
            {
                using (var transaction = _context.Database.BeginTransaction())
                {
                    if (!ModelState.IsValid)
                    {
                        return(BadRequest(ModelState));
                    }

                    if (id != responsible.RegistrationNumber)
                    {
                        return(BadRequest());
                    }

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

                    try
                    {
                        await _context.SaveChangesAsync();

                        transaction.Commit();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!ResponsibleExists(id))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }

                    return(NoContent());
                }
            }
            return(Unauthorized());
        }