public async Task <IHttpActionResult> Putcursistcursus(int id, cursistcursus cursistcursus)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != cursistcursus.CURSUSCODE)
            {
                return(BadRequest());
            }

            db.Entry(cursistcursus).State = EntityState.Modified;

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IActionResult> PutObjetoCalculo(int id, ObjetoCalculo objetoCalculo)
        {
            if (id != objetoCalculo.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Beispiel #3
0
        public async Task <IActionResult> PutLibro(Guid id, Libro libro)
        {
            if (id != libro.IdLibro)
            {
                return(BadRequest());
            }

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

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

            return(Ok(new { status = true }));
        }
        public async Task <IActionResult> PutEditorial(Guid id, Editorial editorial)
        {
            if (id != editorial.IdEditoria)
            {
                return(BadRequest());
            }

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

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

            return(Ok(new { status = true }));
        }
        public async Task <IActionResult> PutProject([FromRoute] int id, [FromBody] Project project)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(NoContent());
        }
Beispiel #6
0
        public async Task <IHttpActionResult> Putschipklasse(int id, schipklasses schipklasse)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != schipklasse.KLASSEID)
            {
                return(BadRequest());
            }

            db.Entry(schipklasse).State = EntityState.Modified;

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #7
0
        public async Task <IActionResult> PutCliente(int id, Cliente cliente)
        {
            if (id != cliente.ClienteId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Beispiel #8
0
        public async Task <IActionResult> PutEndereco(int id, Endereco endereco)
        {
            if (id != endereco.EnderecoId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutBicicleta(int id, Bicicleta bicicleta)
        {
            if (id != bicicleta.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Beispiel #10
0
        public async Task <IActionResult> Create([Bind("Id,Nome,Sobrenome,Email,DataDeNascimento")] Autor autor)
        {
            try
            {
                if (ModelState.IsValid == false)
                {
                    return(View(autor));
                }


                var client  = new RestClient();
                var request = new RestRequest("https://localhost:5001/api/autors", DataFormat.Json);
                request.AddJsonBody(autor);

                var response = client.Post <AutorViewModel>(request);
                _context.Add(autor);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            catch (System.Exception ex)
            {
                ModelState.AddModelError("APP_ERROR", ex.Message);
                return(View(autor));
            }
        }
Beispiel #11
0
        public async Task <IActionResult> UpdateWebApiItem(long id, WebApiDTO webApiItemDTO)
        {
            if (id != webApiItemDTO.Id)
            {
                return(BadRequest());
            }

            var webApiItem = await _context.WebApiItems.FindAsync(id);

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

            webApiItem.Name       = webApiItemDTO.Name;
            webApiItem.IsComplete = webApiItemDTO.IsComplete;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException) when(!webApiItemExists(id))
            {
                return(NotFound());
            }

            return(NoContent());
        }
Beispiel #12
0
        public async Task <ActionResult <User> > Post(User item)
        {
            _context.Users.Add(item);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(Get), new { id = item.Id }, item));
        }
Beispiel #13
0
        public async Task <string> Seed()
        {
            int numberOfCars = 0;

            if (_context.Car.Count() == 0)
            {
                Car car1 = new Car {
                    Make = "Toyota", Model = "Corolla", Colour = "Blue", Year = 2011, VIN = 123
                };
                Car car2 = new Car {
                    Make = "Honda", Model = "Civic", Colour = "Red", Year = 2012, VIN = 456
                };
                Car car3 = new Car {
                    Make = "Nissan", Model = "Altima", Colour = "Green", Year = 2018, VIN = 789
                };
                Car car4 = new Car {
                    Make = "Mazda", Model = "Mazda3", Colour = "Silver", Year = 2010, VIN = 321
                };

                _context.AddRange(car1, car2, car3, car4);
                await _context.SaveChangesAsync();

                numberOfCars = 4;
            }

            return($"{numberOfCars} Cars Added");
        }
Beispiel #14
0
        public async Task GetSpecificNonExistingUser()
        {
            await using var context = new WebApiContext(_seeder.DbContextOptions);
            var controller = CreateController(context);

            var maxId = await context.Users.MaxAsync(u => u.Id);

            var getResult = await controller.GetUser(maxId + 1);

            getResult.Result.ShouldBeAssignableTo <NotFoundResult>();

            getResult = await controller.GetUser(-1);

            getResult.Result.ShouldBeAssignableTo <NotFoundResult>();

            var blockedUser = await context.Users.FirstAsync();

            blockedUser.StateId = _blockedState.Id;
            await context.SaveChangesAsync();

            getResult = await controller.GetUser(blockedUser.Id);

            getResult.Result.ShouldBeAssignableTo <NotFoundResult>();

            blockedUser.StateId = _activeState.Id;
            await context.SaveChangesAsync();
        }
Beispiel #15
0
        public async Task <IActionResult> PutRegistration(int id, Registration registration)
        {
            if (id != registration.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Beispiel #16
0
        public async Task <IActionResult> PutImovel(int id, Imovel imovel)
        {
            if (id != imovel.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Beispiel #17
0
        public async Task <IHttpActionResult> PutCompraGado(int id, CompraGado compraGado)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            db.Entry(compraGado).State = EntityState.Modified;

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IActionResult> PutShopList(int id, ShopList shopList)
        {
            if (id != shopList.ID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Beispiel #19
0
        public async Task <IActionResult> PutProprietario(int id, Proprietario proprietario)
        {
            if (id != proprietario.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Beispiel #20
0
        public async Task <IActionResult> Create([Bind("Id,Nome,Sobrenome,TurmaId")] Aluno aluno)
        {
            if (ModelState.IsValid)
            {
                _context.Add(aluno);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(aluno));
        }
Beispiel #21
0
        public async Task <IActionResult> Create([Bind("ID,Name,Email,PhoneNumber")] Dealership dealership)
        {
            if (ModelState.IsValid)
            {
                _context.Add(dealership);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(dealership));
        }
Beispiel #22
0
        public async Task <IActionResult> Create([Bind("Id,Titulo,ISBN,Ano,AutorId")] Livro livro)
        {
            if (ModelState.IsValid)
            {
                _context.Add(livro);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(livro));
        }
Beispiel #23
0
        public async Task <ActionResult <User> > Post(User user)
        {
            if (user == null)
            {
                return(BadRequest());
            }

            _context.Users.Add(user);
            await _context.SaveChangesAsync();

            return(Ok(user));
        }
Beispiel #24
0
        public async Task <IActionResult> PutUser(int id, UserPutDto user)
        {
            if (id != user.Id)
            {
                return(BadRequest());
            }

            await using var transaction = await _context.Database.BeginTransactionAsync(IsolationLevel.Serializable);

            try
            {
                var entity = await _context.GetActiveUsers()
                             .FirstOrDefaultAsync(u => u.Id == user.Id);

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

                if (await _context.UserGroups.FindAsync(user.GroupId) == null)
                {
                    return(BadRequest());
                }

                if (!await _adminElevation.CanEnterGroup(user.GroupId, user.Id))
                {
                    return(BadRequest());
                }

                entity.Login   = user.Login;
                entity.GroupId = user.GroupId;

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

                await _context.SaveChangesAsync();

                await transaction.CommitAsync();

                return(Ok());
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(id))
                {
                    return(NotFound());
                }

                return(Conflict());
            }
        }
Beispiel #25
0
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> Create([FromBody] userLogin userLogin)
        {
            if (ModelState.IsValid)
            {
                //Encriptar pass
                userLogin.Password = Seguridad.Encriptarpass(userLogin.Password);


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

                return(RedirectToAction(nameof(Index)));
            }
            return(View(userLogin));
        }
Beispiel #26
0
        public async Task <ActionResult <Users> > Delete(int id)
        {
            _logger.LogInformation(LoggingEvents.DeleteItem, "DELETE USER");
            try
            {
                using (var db = new WebApiContext())
                {
                    var item = await db.Users.FindAsync(id);

                    if (item == null)
                    {
                        _logger.LogInformation(LoggingEvents.GetItemNotFound, "DELETE NOT FOUND");
                        return(NotFound());
                    }

                    db.Users.Remove(item);
                    await db.SaveChangesAsync();

                    _logger.LogInformation(LoggingEvents.DeleteItem, "DELETE Successful");
                    return(NoContent());
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(LoggingEvents.Error, ex, "AN ERROR OCCURRED.");
                return(null);
            }
        }// THE END DELETE
Beispiel #27
0
        public async Task AddUserWithSameLoginImmediately()
        {
            await using var context = new WebApiContext(_seeder.DbContextOptions);
            var controller = CreateController(context);

            var result = await controller.PostUser(new UserPostDto
            {
                Login    = "******",
                Password = "******",
                GroupId  = _userGroup.Id
            });

            var createdUser = (UserGetDto)((CreatedAtActionResult)result.Result).Value;

            result = await controller.PostUser(new UserPostDto
            {
                Login    = "******",
                Password = "******",
                GroupId  = _userGroup.Id
            });

            result.Result.ShouldBeAssignableTo <ConflictResult>();

            context.Users.Count().ShouldBe(11);

            context.Users.Remove(await context.Users.FindAsync(createdUser.Id));
            await context.SaveChangesAsync();
        }
Beispiel #28
0
        public async Task <ActionResult <Users> > Put(int id, Users item)
        {
            _logger.LogInformation(LoggingEvents.UpdateItem, "PUT USER");
            try
            {
                if (id != item.User_ID)
                {
                    return(BadRequest());
                }

                using (var db = new WebApiContext())
                {
                    db.Entry(item).State = EntityState.Modified;
                    await db.SaveChangesAsync();

                    _logger.LogInformation(LoggingEvents.UpdateItem, "PUT Successful");
                    return(NoContent());
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(LoggingEvents.Error, ex, "AN ERROR OCCURRED.");
                return(null);
            }
        }// THE END PUT
Beispiel #29
0
        public async Task <IHttpActionResult> PostManufacturer(ManufacturerRequest manufacturerRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var now = DateTime.Now;

            var manufacturer = new Manufacturer
            {
                Name                  = manufacturerRequest.Name,
                AuditCreatedBy        = UserResolver.CurrentUserId,
                AuditCreatedDate      = now,
                AuditLastModifiedBy   = UserResolver.CurrentUserId,
                AuditLastModifiedDate = now
            };

            WebApiContext.Manufacturers.Add(manufacturer);
            await WebApiContext.SaveChangesAsync();

            var response = new ManufacturerResponse
            {
                ManufacturerId = manufacturer.ManufacturerId,
                Name           = manufacturer.Name
            };

            return(CreatedAtRoute(nameof(GetManufacturer), new { manufacturerId = response.ManufacturerId }, response));
        }
Beispiel #30
0
        public void Put(RoleViewModel roleViewModel)
        {
            var role        = _mapper.Map <RoleViewModel, Role>(roleViewModel);
            var permissions = _mapper.Map <List <PermissionViewModel>, List <Permission> >(roleViewModel.Permissions.ToList());

            _context.Roles.Update(role);

            role = _context.Roles.Where(x => x.RoleId == role.RoleId).Include(x => x.RolePermissions).ThenInclude(x => x.Permission).FirstOrDefault();

            foreach (var rolePermission in role.RolePermissions.ToList())
            {
                // Remove the rolepermission which are not in the list of new permission
                if (!permissions.Any(x => x.PermissionId == rolePermission.Permission.PermissionId))
                {
                    role.RolePermissions.Remove(rolePermission);
                }
            }

            foreach (var permission in permissions)
            {
                // Add the permission which are not in the list of roles's permission
                if (!role.RolePermissions.Any(r => r.PermissionId == permission.PermissionId))
                {
                    var newRolePermission = new RolePermission {
                        RoleId = role.RoleId, PermissionId = permission.PermissionId
                    };
                    role.RolePermissions.Add(newRolePermission);
                }
            }

            _context.SaveChangesAsync();
        }