示例#1
0
        public IHttpActionResult CreateCategory(Category category)
        {
            //if (!ModelState.IsValid)
            //    return BadRequest();

            _context.Categories.Add(category);

            _context.SaveChanges();

            return(Created(Request.RequestUri, category));
        }
示例#2
0
        public IHttpActionResult SusspendSupplier(Login login)
        {
            var loginInDB = _context.Logins.SingleOrDefault(l => l.CompanyCode == login.CompanyCode);

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

            var supplierInDB = _context.Suppliers.SingleOrDefault(s => s.CompanyCode == login.CompanyCode);

            if (loginInDB.Susspended == "YES")
            {
                loginInDB.Susspended    = "NO";
                supplierInDB.Susspended = "NO";
            }

            else
            {
                loginInDB.Susspended    = "YES";
                supplierInDB.Susspended = "YES";
            }

            _context.SaveChanges();

            return(Ok(loginInDB));
        }
示例#3
0
        public IHttpActionResult ConfirmPayment(SupplierPublicTender supplierPublicTender)
        {
            //    var supplierTenderInDB = _context.SupplierPublicTenders
            //        .ToList().FindAll(s => s.SupplierID == supplierPublicTender.SupplierID);

            var supplierTenderInDB = _context.SupplierPublicTenders
                                     .FirstOrDefault(s => s.PublicTenderID == supplierPublicTender.PublicTenderID &&
                                                     s.SupplierID == supplierPublicTender.SupplierID);

            if (supplierTenderInDB != null)
            {
                if (supplierTenderInDB.Paid == "YES")
                {
                    supplierTenderInDB.Paid = "NO";
                    _context.SaveChanges();
                }
                else
                {
                    supplierTenderInDB.Paid = "YES";
                    _context.SaveChanges();
                }

                return(Ok(supplierTenderInDB));
            }

            //for(var i = 0; i < supplierTenderInDB.Count; i++)
            //{
            //    if(supplierTenderInDB[i].PublicTenderID == supplierPublicTender.PublicTenderID)
            //    {
            //        if (supplierTenderInDB[i].Paid == "YES")
            //        {
            //            supplierTenderInDB[i].Paid = "NO";
            //        }
            //        else
            //        {
            //            supplierTenderInDB[i].Paid = "YES";
            //        }
            //        return Ok();
            //    }
            //}
            return(NotFound());
        }
        public IHttpActionResult UpdateTender(int id, PrivateTender tender)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var tenderInDB = _context.PrivateTenders.SingleOrDefault(t => t.ID == id);

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

            tenderInDB.SupplierID = tender.SupplierID;

            _context.SaveChanges();

            return(Ok(tenderInDB));
        }
        public IHttpActionResult DeleteNewSupplier(int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var newSupplierInDB = _context.NewSuppliers.SingleOrDefault(ns => ns.ID == id);

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

            _context.NewSuppliers.Remove(newSupplierInDB);

            _context.SaveChanges();

            return(Ok());
        }
示例#6
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));
        }