Ejemplo n.º 1
0
        public async Task <IActionResult> AddEmployee([FromBody] InputEmployee input)
        {
            var existing = await _context.Employees.FindAsync(Misc.StripCpf(input.Cpf));

            var exists = existing != null;

            if (exists)
            {
                ModelState.AddModelError(nameof(InputEmployee.Cpf), "CPF já existente");

                return(Conflict(ModelState));
            }

            var occupation = await _context.Occupations.FindAsync(input.OccupationId);

            if (occupation == null)
            {
                ModelState.AddModelError(nameof(InputEmployee.OccupationId), "Ocupação não encontrada");

                return(NotFound(ModelState));
            }

            Employee employee = input.ToModel(occupation, _passwordHash);

            await _context.Users.AddAsync(employee.User);

            await _context.Employees.AddAsync(employee);

            await _context.SaveChangesAsync();

            return(Ok(new OutputEmployee(employee)));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PutFilmGenres(int id, FilmGenres filmGenres)
        {
            if (id != filmGenres.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> AddEquipmentDetails([FromBody] InputEquipmentDetails input)
        {
            if (!ModelState.IsValid)
            {
                return(new BadRequestObjectResult(input));
            }

            var type = await _context.EquipmentTypes.FindAsync(input.TypeId);

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

            var details = input.ToModel();

            await _context.EquipmentDetails.AddAsync(details);

            await _context.SaveChangesAsync();

            return(CreatedAtAction(
                       nameof(GetDetails),
                       new { id = details.Id },
                       await _detailsHandler.OutputFor(details)
                       ));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> PostProduct(InputPackage input)
        {
            var package = input.ToModel();

            await _context.Packages.AddAsync(package);

            await _context.SaveChangesAsync();

            return(Ok(_packageHandler.OutputFor(package)));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("ID,Key")] Song song)
        {
            if (ModelState.IsValid)
            {
                _context.Add(song);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(song));
        }
        public async Task <IActionResult> Create([Bind("ID,SSN,FirstName,LastName")] Musician musician)
        {
            if (ModelState.IsValid)
            {
                _context.Add(musician);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(musician));
        }
        public async Task <IActionResult> Create([Bind("ID,StreetNumber,StreetName,City,State,PostalCode,Phone")] Address address)
        {
            if (ModelState.IsValid)
            {
                _context.Add(address);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(address));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Create([Bind("ID")] Album album)
        {
            if (ModelState.IsValid)
            {
                album.ID = Guid.NewGuid();
                _context.Add(album);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(album));
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> Create([Bind("ID,MusicianID,SongID,Instrument")] Performance performance)
        {
            if (ModelState.IsValid)
            {
                _context.Add(performance);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MusicianID"] = new SelectList(_context.Musicians, "ID", "Discriminator", performance.MusicianID);
            ViewData["SongID"]     = new SelectList(_context.Songs, "ID", "ID", performance.SongID);
            return(View(performance));
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> Add([FromBody] InputOrder input)
        {
            var currentCustomer = await _currentUser.GetCurrentUser();

            if (currentCustomer == null)
            {
                return(Unauthorized());
            }

            var package = await _context.Packages.FindAsync(input.PackageId);

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

            if (!IsValidQuantity(input.ImageQuantity, package))
            {
                return(BadRequest("Invalid quantity"));
            }

            var price = CalculatePrice(package, input.ImageQuantity);

            Order order = input.ToModel(currentCustomer, package, price);

            await _context.Orders.AddAsync(order);

            await _context.SaveChangesAsync();

            return(Ok(await _handler.OutputFor(order)));
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> PostUser(InputUser inputUser,
                                                   [FromServices] IOptions <ApiBehaviorOptions> apiBehaviorOptions)
        {
            inputUser.HashPassword(_passwordHash);
            var user = inputUser.ToModel();

            if (await CpfExists(user.Cpf))
            {
                ModelState.AddModelError(nameof(user.Cpf), "User Cpf already in use");
            }

            if (await EmailExists(user.Email))
            {
                ModelState.AddModelError(nameof(user.Email), "User Email already in use");
            }

            if (!ModelState.IsValid)
            {
                return(apiBehaviorOptions.Value.InvalidModelStateResponseFactory(ControllerContext));
            }

            await _context.Users.AddAsync(user);

            await _context.SaveChangesAsync();

            return(Ok(_outputHandler.OutputFor(user)));
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> AddWithdraw(InputWithdraw input)
        {
            var references = await FindReferences(input);

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

            var withdraw = input.ToModel(references.Value);

            await _context.EquipmentWithdraws.AddAsync(withdraw);

            await _context.SaveChangesAsync();

            return(Ok(await _withdrawHandler.OutputFor(withdraw)));
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> Add([FromBody] InputPhotoShoot input)
        {
            var shot = input.ToPhotoShoot();

            if (await _context.Orders.FindAsync(shot.OrderId) == null)
            {
                return(NotFound());
            }

            await _context.PhotoShoots.AddAsync(shot);

            await _context.SaveChangesAsync();

            var output = new OutputPhotoShoot(shot, true);

            return(CreatedAtAction("GetById", new { id = shot.ResourceId }, output));
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> Create([Bind("InstrumentoID, Nome, Marca, Modelo, Serie, Cor ")] Instrumento instrumento)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(instrumento);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(IndexInstrumento)));
                }
            }
            catch (DbUpdateException)
            {
                ModelState.AddModelError("", "Não foi possível inserir dados.");
            }
            return(View(instrumento));
        }
Ejemplo n.º 15
0
        public async Task <IActionResult> Create([Bind(" MusicoId,Nome, Telefone, Endereço, Numero, Estado, Cidade, Bairro")] Musico musico)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(musico);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Indexmusico)));
                }
            }
            catch (DbUpdateException)
            {
                ModelState.AddModelError("", "Não foi possível inserir dados.");
            }
            return(View(musico));
        }
Ejemplo n.º 16
0
        public async Task <IActionResult> Create([Bind("FaixaID, Nome, Autor, DataLancamento,Volume ")] Faixa faixa)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(faixa);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException)
            {
                ModelState.AddModelError("", "Não foi possível inserir dados.");
            }
            return(View(faixa));
        }
Ejemplo n.º 17
0
        public async Task <IActionResult> CreateAlbum([Bind("AlbumID, Nome, DataAlbum, Formato,Foto,Genero")] Album album)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(album);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(IndexAlbum)));
                }
            }
            catch (DbUpdateException)
            {
                ModelState.AddModelError("", "Não foi possível inserir dados.");
            }
            return(View(album));
        }
Ejemplo n.º 18
0
        public async Task <IActionResult> AddEquipment(InputEquipment input)
        {
            var details = await _context.EquipmentDetails.FindAsync(input.DetailsId);

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

            var equipment = input.ToModel();

            equipment.Details = details;

            await _context.Equipments.AddAsync(equipment);

            await _context.SaveChangesAsync();

            return(Ok(_equipmentHandler.OutputFor(equipment)));
        }