Ejemplo n.º 1
0
        public async Task <IHttpActionResult> PutEmployee(int id, Employee employee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != employee.BusinessEntityID)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IActionResult> PutAddress([FromRoute] int id, [FromBody] Address address)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != address.AddressId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutSalesOrderHeader([FromRoute] int id, [FromBody] SalesOrderHeader salesOrderHeader)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != salesOrderHeader.SalesOrderId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> PutErrorLog([FromRoute] int id, [FromBody] ErrorLog errorLog)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != errorLog.ErrorLogId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> PutProductCategory([FromRoute] int id, [FromBody] ProductCategory productCategory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != productCategory.ProductCategoryId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IHttpActionResult> PutProduct(int id, Product product)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != product.ProductID)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> PutCustomer(int id, Customer customer)
        {
            if (id != customer.CustomerId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task AddAsync(TEntity entity)
        {
            _context
            .Entry(entity)
            .State = EntityState.Added;

            await _context
            .SaveChangesAsync()
            .ConfigureAwait(false);
        }
        public async Task <IActionResult> Create([Bind("DepartmentId,Name,GroupName,ModifiedDate")] Department department)
        {
            if (ModelState.IsValid)
            {
                _context.Add(department);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(department));
        }
        public async Task <IActionResult> Create([Bind("BusinessEntityId,Rowguid,ModifiedDate")] BusinessEntity businessEntity)
        {
            if (ModelState.IsValid)
            {
                _context.Add(businessEntity);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(businessEntity));
        }
        public async Task <IActionResult> Create([Bind("CreditCardId,CardType,CardNumber,ExpMonth,ExpYear,ModifiedDate")] CreditCard creditCard)
        {
            if (ModelState.IsValid)
            {
                _context.Add(creditCard);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(creditCard));
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> Create([Bind("SystemInformationId,DatabaseVersion,VersionDate,ModifiedDate")] AwbuildVersion awbuildVersion)
        {
            if (ModelState.IsValid)
            {
                _context.Add(awbuildVersion);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(awbuildVersion));
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> Create([Bind("DatabaseLogId,PostTime,DatabaseUser,Event,Schema,Object,Tsql,XmlEvent")] DatabaseLog databaseLog)
        {
            if (ModelState.IsValid)
            {
                _context.Add(databaseLog);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(databaseLog));
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> Create([Bind("ContactTypeId,Name,ModifiedDate")] ContactType contactType)
        {
            if (ModelState.IsValid)
            {
                _context.Add(contactType);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(contactType));
        }
Ejemplo n.º 15
0
        public async Task <IActionResult> Create([Bind("CustomerId,NameStyle,Title,FirstName,MiddleName,LastName,Suffix,CompanyName,SalesPerson,EmailAddress,Phone,PasswordHash,PasswordSalt,Rowguid,ModifiedDate")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
Ejemplo n.º 16
0
        public async Task <IActionResult> Create([Bind("TerritoryId,Name,CountryRegionCode,Group,SalesYtd,SalesLastYear,CostYtd,CostLastYear,Rowguid,ModifiedDate")] SalesTerritory salesTerritory)
        {
            if (ModelState.IsValid)
            {
                _context.Add(salesTerritory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CountryRegionCode"] = new SelectList(_context.CountryRegion, "CountryRegionCode", "CountryRegionCode", salesTerritory.CountryRegionCode);
            return(View(salesTerritory));
        }
        public async Task <ActionResult> Create([Bind(Include = "DepartmentID,Name,GroupName,ModifiedDate")] Department department)
        {
            if (ModelState.IsValid)
            {
                db.Departments.Add(department);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(department));
        }
Ejemplo n.º 18
0
        public async Task <IActionResult> Create([Bind("AddressId,AddressLine1,AddressLine2,City,StateProvinceId,PostalCode,Rowguid,ModifiedDate")] Address address)
        {
            if (ModelState.IsValid)
            {
                _context.Add(address);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["StateProvinceId"] = new SelectList(_context.StateProvince, "StateProvinceId", "CountryRegionCode", address.StateProvinceId);
            return(View(address));
        }
Ejemplo n.º 19
0
        public async Task <IActionResult> Create([Bind("BusinessEntityId,NationalIdnumber,LoginId,OrganizationLevel,JobTitle,BirthDate,MaritalStatus,Gender,HireDate,SalariedFlag,VacationHours,SickLeaveHours,CurrentFlag,Rowguid,ModifiedDate")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                _context.Add(employee);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BusinessEntityId"] = new SelectList(_context.People, "BusinessEntityId", "FirstName", employee.BusinessEntityId);
            return(View(employee));
        }
        public async Task <IActionResult> Create([Bind("StateProvinceId,StateProvinceCode,CountryRegionCode,IsOnlyStateProvinceFlag,Name,TerritoryId,Rowguid,ModifiedDate")] StateProvince stateProvince)
        {
            if (ModelState.IsValid)
            {
                _context.Add(stateProvince);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CountryRegionCode"] = new SelectList(_context.CountryRegion, "CountryRegionCode", "CountryRegionCode", stateProvince.CountryRegionCode);
            ViewData["TerritoryId"]       = new SelectList(_context.SalesTerritory, "TerritoryId", "CountryRegionCode", stateProvince.TerritoryId);
            return(View(stateProvince));
        }
        public async Task <IActionResult> Create([Bind("CountryRegionCode,CurrencyCode,ModifiedDate")] CountryRegionCurrency countryRegionCurrency)
        {
            if (ModelState.IsValid)
            {
                _context.Add(countryRegionCurrency);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CountryRegionCode"] = new SelectList(_context.CountryRegion, "CountryRegionCode", "CountryRegionCode", countryRegionCurrency.CountryRegionCode);
            ViewData["CurrencyCode"]      = new SelectList(_context.Currency, "CurrencyCode", "CurrencyCode", countryRegionCurrency.CurrencyCode);
            return(View(countryRegionCurrency));
        }
        public async Task <IActionResult> Create([Bind("CurrencyRateId,CurrencyRateDate,FromCurrencyCode,ToCurrencyCode,AverageRate,EndOfDayRate,ModifiedDate")] CurrencyRate currencyRate)
        {
            if (ModelState.IsValid)
            {
                _context.Add(currencyRate);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["FromCurrencyCode"] = new SelectList(_context.Currency, "CurrencyCode", "CurrencyCode", currencyRate.FromCurrencyCode);
            ViewData["ToCurrencyCode"]   = new SelectList(_context.Currency, "CurrencyCode", "CurrencyCode", currencyRate.ToCurrencyCode);
            return(View(currencyRate));
        }
Ejemplo n.º 23
0
        public async Task <IActionResult> Create([Bind("BusinessEntityId,AddressId,AddressTypeId,Rowguid,ModifiedDate")] BusinessEntityAddress businessEntityAddress)
        {
            if (ModelState.IsValid)
            {
                _context.Add(businessEntityAddress);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AddressId"]        = new SelectList(_context.Address, "AddressId", "AddressLine1", businessEntityAddress.AddressId);
            ViewData["AddressTypeId"]    = new SelectList(_context.AddressType, "AddressTypeId", "Name", businessEntityAddress.AddressTypeId);
            ViewData["BusinessEntityId"] = new SelectList(_context.BusinessEntity, "BusinessEntityId", "BusinessEntityId", businessEntityAddress.BusinessEntityId);
            return(View(businessEntityAddress));
        }
Ejemplo n.º 24
0
        public async Task <IActionResult> Create([Bind("BusinessEntityId,PersonId,ContactTypeId,Rowguid,ModifiedDate")] BusinessEntityContact businessEntityContact)
        {
            if (ModelState.IsValid)
            {
                _context.Add(businessEntityContact);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BusinessEntityId"] = new SelectList(_context.BusinessEntity, "BusinessEntityId", "BusinessEntityId", businessEntityContact.BusinessEntityId);
            ViewData["ContactTypeId"]    = new SelectList(_context.ContactType, "ContactTypeId", "Name", businessEntityContact.ContactTypeId);
            ViewData["PersonId"]         = new SelectList(_context.Person, "BusinessEntityId", "FirstName", businessEntityContact.PersonId);
            return(View(businessEntityContact));
        }
        public async Task <IActionResult> Create([Bind("BillOfMaterialsId,ProductAssemblyId,ComponentId,StartDate,EndDate,UnitMeasureCode,Bomlevel,PerAssemblyQty,ModifiedDate")] BillOfMaterials billOfMaterials)
        {
            if (ModelState.IsValid)
            {
                _context.Add(billOfMaterials);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ComponentId"]       = new SelectList(_context.Product, "ProductId", "Name", billOfMaterials.ComponentId);
            ViewData["ProductAssemblyId"] = new SelectList(_context.Product, "ProductId", "Name", billOfMaterials.ProductAssemblyId);
            ViewData["UnitMeasureCode"]   = new SelectList(_context.UnitMeasure, "UnitMeasureCode", "UnitMeasureCode", billOfMaterials.UnitMeasureCode);
            return(View(billOfMaterials));
        }
        public async Task <IActionResult> Create([Bind("CustomerId,PersonId,StoreId,TerritoryId,AccountNumber,Rowguid,ModifiedDate")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PersonId"]    = new SelectList(_context.Person, "BusinessEntityId", "FirstName", customer.PersonId);
            ViewData["StoreId"]     = new SelectList(_context.Store, "BusinessEntityId", "Name", customer.StoreId);
            ViewData["TerritoryId"] = new SelectList(_context.SalesTerritory, "TerritoryId", "CountryRegionCode", customer.TerritoryId);
            return(View(customer));
        }
Ejemplo n.º 27
0
        public async Task <IActionResult> Create([Bind("ProductId,Name,ProductNumber,MakeFlag,FinishedGoodsFlag,Color,SafetyStockLevel,ReorderPoint,StandardCost,ListPrice,Size,SizeUnitMeasureCode,WeightUnitMeasureCode,Weight,DaysToManufacture,ProductLine,Class,Style,ProductSubcategoryId,ProductModelId,SellStartDate,SellEndDate,DiscontinuedDate,Rowguid,ModifiedDate")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductModelId"]        = new SelectList(_context.ProductModels, "ProductModelId", "Name", product.ProductModelId);
            ViewData["ProductSubcategoryId"]  = new SelectList(_context.ProductSubcategories, "ProductSubcategoryId", "Name", product.ProductSubcategoryId);
            ViewData["SizeUnitMeasureCode"]   = new SelectList(_context.UnitMeasures, "UnitMeasureCode", "UnitMeasureCode", product.SizeUnitMeasureCode);
            ViewData["WeightUnitMeasureCode"] = new SelectList(_context.UnitMeasures, "UnitMeasureCode", "UnitMeasureCode", product.WeightUnitMeasureCode);
            return(View(product));
        }
Ejemplo n.º 28
0
        public static async Task <int> PostCustomerAsync(Customer customer)
        {
            AdventureWorksContext context = new AdventureWorksContext();

            context.Customer.Add(customer);
            int x = await context.SaveChangesAsync();

            return(x);
        }
Ejemplo n.º 29
0
        public async Task <IActionResult> Put([FromBody] ProductUpdateModel model, [FromRoute][Required] int id)
        {
            var product = await _context.Product
                          .FirstOrDefaultAsync(p => p.ProductId == id);

            if (product == null)
            {
                throw new EntryNotFoundException(id);
            }

            _mapper.Map(model, product);

            product.ModifiedDate = DateTime.UtcNow;
            _context.Update(product);

            await _context.SaveChangesAsync();

            return(NoContent());
        }
        protected override async Task Handle(UpdateCustomerCommand request, CancellationToken cancellationToken)
        {
            var customer = await _ctx.Customers.Include(c => c.Person)
                           .SingleOrDefaultAsync(c => c.CustomerId == request.CustomerId, cancellationToken);

            if (customer != null)
            {
                _mapper.Map(request, customer);
                await _ctx.SaveChangesAsync(cancellationToken);
            }
        }