コード例 #1
0
        public async Task <IActionResult> PutApplicationProgram(int id, ApplicationProgram applicationProgram)
        {
            if (id != applicationProgram.ID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #2
0
        public async Task <IActionResult> PutInstitucion(int id, Institucion institucion)
        {
            if (id != institucion.IdInstitucion)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #3
0
        public async Task <IActionResult> PutParameter(int id, Parameter parameter)
        {
            if (id != parameter.ID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #4
0
        public async Task <IActionResult> PutViewapplicationData(int id, ViewapplicationData viewapplicationData)
        {
            if (id != viewapplicationData.ID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #5
0
        public async Task <IActionResult> PutMovie(int id, Movie movie)
        {
            if (id != movie.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #6
0
        public async Task <IActionResult> PutGrupo(int id, Grupo grupo)
        {
            if (id != grupo.IdGrupo)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #7
0
        public async Task <IActionResult> PutCategoriaSubCategoria(int id, CategoriaSubCategoria categoriaSubCategoria)
        {
            if (id != categoriaSubCategoria.IdCategoriaSubCategoria)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #8
0
        public async Task <IActionResult> PutReport(int id, Report report)
        {
            if (id != report.ID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #9
0
        public async Task <bool> CreateCategoryAsync(Category category)
        {
            await _context.Categories.AddAsync(category);

            var created = await _context.SaveChangesAsync();

            return(created > 0);
        }
コード例 #10
0
        public async Task <bool> CreateProductAsync(Product product)
        {
            await _context.Products.AddAsync(product);

            var created = await _context.SaveChangesAsync();

            return(created > 0);
        }
コード例 #11
0
ファイル: GenerosController.cs プロジェクト: damiandar/Series
        public async Task <ActionResult> Post([FromBody] GeneroCreacionDTO generoCreacionDTO)
        {
            var genero = mapper.Map <Genero>(generoCreacionDTO);

            context.Add(genero);
            await context.SaveChangesAsync();

            return(NoContent());
        }
コード例 #12
0
        public async Task <IActionResult> Create([Bind("Id,Title,Runtime,Synopsis,Rating")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movie);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(movie));
        }
コード例 #13
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description,Date,MovieId")] Comment comment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(comment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MovieId"] = new SelectList(_context.Movies, "Id", "Id", comment.MovieId);
            return(View(comment));
        }
コード例 #14
0
ファイル: ActoresController.cs プロジェクト: damiandar/Series
        public async Task <ActionResult> Post([FromForm] ActorCreacionDTO actorCreacionDTO)
        {
            var actor = mapper.Map <Actor>(actorCreacionDTO);

            if (actorCreacionDTO.Foto != null)
            {
                actor.Foto = await almacenadorArchivos.GuardarArchivo(contenedor, actorCreacionDTO.Foto);
            }

            context.Add(actor);
            await context.SaveChangesAsync();

            return(NoContent());
        }
コード例 #15
0
        public async Task Combination_of_FirstName_LastName_and_DOB_must_be_unique()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbcontext>()
                          .UseInMemoryDatabase(databaseName: "Database")
                          .Options;

            var email       = Email.Create("*****@*****.**").Value;
            var phoneNumber = PhoneNumber.Create("+989391818607").Value;

            var newCustomer =
                new Customer
                (
                    firstName: "Ali",
                    lastName: "Bayat",
                    dateOfBirth: new DateTime(1988, 2, 20),
                    email: email,
                    phoneNumber: phoneNumber,
                    bankAccountNumber: "123456"
                );

            using (var context = new ApplicationDbcontext(options))
            {
                context.Customers.Add(newCustomer);
                await context.SaveChangesAsync();
            }

            using (var context = new ApplicationDbcontext(options))
            {
                context.Customers.Add(newCustomer);

                Assert.Throws <ArgumentException>(() => { context.SaveChangesAsync().GetAwaiter().GetResult(); });
            }
        }
コード例 #16
0
ファイル: SeriesController.cs プロジェクト: damiandar/Series
        public async Task <ActionResult <int> > Post([FromForm] SerieCreacionDTO serieCreacionDTO)
        {
            var serie = mapper.Map <Serie>(serieCreacionDTO);

            if (serieCreacionDTO.Imagen != null)
            {
                serie.Imagen = await almacenadorArchivos.GuardarArchivo(contenedor, serieCreacionDTO.Imagen);
            }

            EscribirOrdenActores(serie);

            context.Add(serie);
            await context.SaveChangesAsync();

            return(serie.Id);
        }
コード例 #17
0
        /// <summary>
        /// Update customer
        /// </summary>
        /// <param name="id">Customer id</param>
        /// <param name="customerViewModel"></param>
        /// <returns>Rerurn success or failure</returns>
        public async Task <Result> UpdateCustomerAsync(int id, CustomerViewModel customerViewModel)
        {
            var customer = _context.Customers.Find(id);

            if (customer == null)
            {
                return(Result.Failure("NotFound"));
            }

            // ToDo: Use Automapper
            customer.FirstName         = customerViewModel.FirstName;
            customer.LastName          = customerViewModel.LastName;
            customer.DateOfBirth       = customerViewModel.DateOfBirth;
            customer.PhoneNumber       = PhoneNumber.Create(customerViewModel.PhoneNumber).Value;
            customer.Email             = Email.Create(customerViewModel.Email).Value;
            customer.BankAccountNumber = customerViewModel.BankAccountNumber;

            await _context.SaveChangesAsync();

            return(Result.Success());
        }
コード例 #18
0
        public async Task <Order> CreateOrderAsync(string userID, int productID)
        {
            var newOrder = new Order();

            newOrder.UserID = userID;

            await _context.Orders.AddAsync(newOrder);

            var newOrderProduct = new OrderProduct();

            newOrderProduct.OrderID   = newOrder.OrderID;
            newOrderProduct.ProductID = productID;
            newOrder.OrderProducts    = new List <OrderProduct>();
            newOrder.OrderProducts.Add(newOrderProduct);

            var created = await _context.SaveChangesAsync();

            if (created <= 0)
            {
                return(null);
            }

            return(newOrder);
        }
コード例 #19
0
        public async Task <Contact> AddContactAsync(string userID, string address, string city)
        {
            var newContact = new Contact
            {
                Address = address,
                City    = city,
                UserID  = userID,
            };

            await _context.Contacts.AddAsync(newContact);

            var created = await _context.SaveChangesAsync();

            if (created <= 0)
            {
                return(null);
            }

            return(newContact);
        }