예제 #1
0
        public IHttpActionResult CreateSupplier(SupplierTelFaxViewModel supplierTelFaxViewModel)
        {
            var subCats = new List <int>();

            foreach (var sc in supplierTelFaxViewModel.subCategories)
            {
                subCats.Add(sc.ID);
            }

            //if (!ModelState.IsValid)
            //    return BadRequest();

            if (subCats.Count == 0)
            {
                return(BadRequest());
            }

            var supplier = new Supplier(supplierTelFaxViewModel.Supplier);

            supplier.Susspended = "NO";

            _context.Suppliers.Add(supplier);

            var supplierPhone = new SupplierPhones()
            {
                Phone      = supplierTelFaxViewModel.SupplierPhone,
                SupplierID = supplier.ID,
                Supplier   = supplier
            };

            _context.SupplierPhones.Add(supplierPhone);

            var supplierFax = new SupplierFaxes()
            {
                Fax        = supplierTelFaxViewModel.SupplierFax,
                SupplierID = supplier.ID,
                Supplier   = supplier
            };

            _context.SupplierFaxes.Add(supplierFax);

            var login = new Login()
            {
                //Susspended = "NO",
                CompanyCode = supplier.CompanyCode,
                Password    = supplier.Password
            };

            //login.Susspended = "NO";

            var listOfSubCats = supplierTelFaxViewModel.subCategories;

            var subCatSupp = new SubCategory();

            foreach (var subCat in listOfSubCats)
            {
                subCatSupp    = subCat;
                subCatSupp.ID = subCat.ID;

                _context.SupplierSubCategories.Add(new SupplierSubCategories()
                {
                    SubCategoryID = subCat.ID,
                    SupplierID    = supplier.ID
                });
            }

            var listOfPublicTenders = new List <PublicTender>();

            var publicTendersInDB = _context.PublicTenders.ToList();

            for (var i = 0; i < publicTendersInDB.Count; i++)
            {
                if (publicTendersInDB[i].SubCategoryID == subCatSupp.ID)
                {
                    listOfPublicTenders.Add(publicTendersInDB[i]);
                }
            }

            _context.SaveChanges();

            for (var i = 0; i < listOfPublicTenders.Count; i++)
            {
                _context.SupplierPublicTenders.Add(
                    new SupplierPublicTender
                {
                    Date           = DateTime.Now,
                    SupplierID     = supplier.ID,
                    Supplier       = supplier,
                    PublicTenderID = listOfPublicTenders[i].ID,
                    PublicTender   = listOfPublicTenders[i]
                });
                _context.SaveChanges();
            }


            //_context.Logins.Add(login);

            return(Created("", supplier));
        }
예제 #2
0
        public IHttpActionResult post(SupplierTelFaxViewModel supplierTelFaxViewModel)
        {
            var subCats = new List <int>();

            foreach (var sc in supplierTelFaxViewModel.subCategories)
            {
                subCats.Add(sc.ID);
            }

            //if (!ModelState.IsValid)
            //    return BadRequest();

            if (subCats.Count == 0)
            {
                return(BadRequest());
            }

            var supplier = new Supplier(supplierTelFaxViewModel.Supplier);

            _context.Suppliers.Add(supplier);
            _context.SaveChanges();

            var supplierPhone = new SupplierPhones()
            {
                Phone      = supplierTelFaxViewModel.SupplierPhone,
                SupplierID = supplier.ID
            };

            var supplierFax = new SupplierFaxes()
            {
                Fax        = supplierTelFaxViewModel.SupplierFax,
                SupplierID = supplier.ID
            };

            var login = new Login()
            {
                CompanyCode = supplier.CompanyCode,
                Password    = supplier.Password
            };

            _context.Logins.Add(login);


            _context.SupplierPhones.Add(supplierPhone);
            _context.SaveChanges();

            _context.SupplierFaxes.Add(supplierFax);
            _context.SaveChanges();

            var listOfSubCats = supplierTelFaxViewModel.subCategories;

            foreach (var subCat in listOfSubCats)
            {
                _context.SupplierSubCategories.Add(new SupplierSubCategories()
                {
                    SubCategoryID = subCat.ID,
                    SupplierID    = supplier.ID
                });
            }

            _context.SaveChanges();

            return(Created("", supplier));
        }