Ejemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("SupplierID,SupplierName,SupplierAbbr,SupplierClassify,SupplierCompetentProducts,SupplierBuyer,SupplierProvince,SupplierCity,SupplierAddress,SupplierEnable,SupplierAuditStatus,SupplierRemarks,SupplierOrganization,SupplierWorkFlow")] Supplier supplier, string SupplierType)
        {
            var supplierType = await _context.SupplierType.SingleOrDefaultAsync(m => m.TypeCode == SupplierType);

            var sup = new Supplier();

            if (sup == null)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                if (SupplierExists(supplier.SupplierID))
                {
                    ViewData.ModelState.AddModelError("SupplierID", "供应商名不能重复!");
                }
                else
                {
                    try
                    {
                        sup.SupplierID           = supplier.SupplierID;
                        sup.SupplierName         = supplier.SupplierName;
                        sup.SupplierAbbr         = supplier.SupplierAbbr;
                        sup.SupplierProvince     = supplier.SupplierProvince;
                        sup.SupplierCity         = supplier.SupplierCity;
                        sup.SupplierAddress      = supplier.SupplierAddress;
                        sup.SupplierEnable       = supplier.SupplierEnable;
                        sup.SupplierRemarks      = supplier.SupplierRemarks;
                        sup.SupplierWorkFlow     = supplier.SupplierWorkFlow;
                        sup.SupplierOrganization = supplier.SupplierOrganization;
                        sup.SupplierAuditStatus  = supplier.SupplierAuditStatus;
                        sup.SupplierClassify     = supplier.SupplierClassify;
                        sup.SupplierType         = null;
                        sup.SupplierType         = supplierType;
                        _context.Supplier.Add(sup);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!SupplierExists(supplier.SupplierID))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    return(RedirectToAction(nameof(Index)));
                }
            }
            GetSupplierTypeList();
            return(View(supplier));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("SupplierId,SupplierName,SupplierAbbr,SupplierClassify,SupplierCompetentProducts,SupplierBuyer,SupplierProvince,SupplierCity,SupplierAddress,SupplierEnable")] Supplier supplier)
        {
            if (ModelState.IsValid)
            {
                _context.Add(supplier);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(supplier));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var supplier = await _context.Suppliers.FindAsync(id);

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

            try
            {
                _context.Suppliers.Remove(supplier);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.)
                return(RedirectToAction("./Delete",
                                        new { id, saveChangesError = true }));
            }
        }
Ejemplo n.º 4
0
 public async Task InsertSupplier(Supplier supplier)
 {
     _context.Suppliers.Add(new Supplier {
         Id = supplier.Id, Title = supplier.Title, FirstName = supplier.FirstName, LastName = supplier.LastName
     });
     await _context.SaveChangesAsync();
 }
Ejemplo n.º 5
0
        public async static Task SeedSupplierRegDB(SupplierContext supplierContext)
        {
            if (supplierContext.Companies.Any())
            {
                return;
            }

            var company = new Company("CompanyA", new UF("SC"), new CNPJ("83841875000143"), new Guid("0822f500-edb6-400b-856d-b01d4a67695d"));

            supplierContext.Companies.Add(company);
            supplierContext.Companies.Add(new Company("CompanyB", new UF("RJ"), new CNPJ("38389185000140"), Guid.NewGuid()));
            supplierContext.Companies.Add(new Company("CompanyC", new UF("SP"), new CNPJ("27569276000141"), Guid.NewGuid()));
            supplierContext.Companies.Add(new Company("CompanyPR", new UF("PR"), new CNPJ("84730514000192"), new Guid("0b1b65bb-d799-47c4-876f-aafc4ae0b93e")));

            await supplierContext.SaveChangesAsync();

            supplierContext.Suppliers.Add(new Supplier("SupplierA", new CPFCNPJ("81777787000102"), null, company, Guid.NewGuid()));
            supplierContext.Suppliers.Add(new Supplier("SupplierB", new CPFCNPJ("95582539000102"), null, company, Guid.NewGuid()));

            await supplierContext.SaveChangesAsync();
        }
Ejemplo n.º 6
0
        public async Task <ActionResult <Suppliers> > PostSuppliers([FromForm] Suppliers suppliers)
        {
            ActionResponses actionResponses;

            if (User.IsInRole("Admin"))
            {
                if (SuppliersExists(suppliers.fSupplierCode))
                {
                    actionResponses = _actionContext.tActionResponses.FirstOrDefault(x => x.fErrorCode == "1");
                    InsertLog("Create Item", "Execution Failed", "1");
                    return(CreatedAtAction("GetSupplier", actionResponses));
                }
                else
                {
                    suppliers.fCreatedAt   = Utilities.GetIp();
                    suppliers.fCreatedBy   = "Admin";
                    suppliers.fCreatedDate = DateTime.Now;

                    suppliers.fModifiedBy   = "Admin";
                    suppliers.fModifiedAt   = Utilities.GetIp();
                    suppliers.fModifiedDate = DateTime.Now;
                    _context.tSupplier.Add(suppliers);
                    await _context.SaveChangesAsync();

                    actionResponses = _actionContext.tActionResponses.FirstOrDefault(x => x.fErrorCode == "0");
                    InsertLog("Create Item", "Execution Success", "0");
                    return(CreatedAtAction("GetSupplier", actionResponses));
                }
            }
            else
            {
                InsertLog("Create Item", "Execution Failed", "4");
                actionResponses = _actionContext.tActionResponses.FirstOrDefault(x => x.fErrorCode == "4");
                return(CreatedAtAction("GetSupplier", actionResponses));
            }
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> OnPostAsync(int id)
        {
            var supplierToUpdate = await _context.Suppliers.FindAsync(id);

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

            if (await TryUpdateModelAsync <Supplier>(
                    supplierToUpdate,
                    "supplier",
                    s => s.CompanyName, s => s.ContactName, s => s.ContactTitle, s => s.Address, s => s.City, s => s.Region, s => s.PostalCode, s => s.Country, s => s.Phone, s => s.Fax, s => s.HomePage))
            {
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }

            return(Page());
        }
Ejemplo n.º 8
0
        //// To protect from overposting attacks, enable the specific properties you want to bind to, for
        //// more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var emptySupplier = new Supplier();

            if (await TryUpdateModelAsync <Supplier>(
                    emptySupplier,
                    "supplier", // Prefix for form value.
                    s => s.CompanyName, s => s.ContactName, s => s.ContactTitle, s => s.Address, s => s.City, s => s.Region, s => s.PostalCode, s => s.Country, s => s.Phone, s => s.Fax, s => s.HomePage))
            {
                _context.Suppliers.Add(emptySupplier);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }

            return(Page());
        }
Ejemplo n.º 9
0
 public async Task <int> SaveChangesAsync()
 {
     return(await Context.SaveChangesAsync());
 }
 public async Task InsertSupplier(Supplier supplier)
 {
     _context.Suppliers.Add(supplier);
     await _context.SaveChangesAsync();
 }
Ejemplo n.º 11
0
        public async Task <bool> SaveAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            var result = await _dbContext.SaveChangesAsync(cancellationToken);

            return(true);
        }