コード例 #1
0
        private List<AssignedProductData> PopulateAssignedProductData(ProductOwner productowner)
        {
            var allProducts = db.ProductNew;
            var endUserProducts = new HashSet<int>(productowner.ProductNews.Select(c => c.ProductID));
            var viewModel = new List<AssignedProductData>();
            foreach (var product in allProducts)
            {
                if (endUserProducts.Contains(product.ProductID))
                {
                    viewModel.Add(new AssignedProductData
                    {
                        ProductID = product.ProductID,
                        ProductName = product.ProductName,
                        Assigned = endUserProducts.Contains(product.ProductID)
                    });
                }
            }

            return viewModel;
        }
コード例 #2
0
        public IHttpActionResult PostEveryBody(OwnerRequest or)
        {
            if (ModelState.IsValid)
            {
                var req = db.ProductOwner.Where(d => d.Email == or.Email).ToList().Count;
                if (req == 0)
                {
                    ProductOwner po = new ProductOwner()
                    {
                        Email = or.Email,
                        CompanyName = or.CompanyName,
                        OwnerName = or.OwnerName,
                        Approval = false
                    };
                    db.ProductOwner.Add(po);
                    db.SaveChanges();
                    return CreatedAtRoute("DefaultApi", new { id = or.ID }, or);
                }
                else
                {
                    return Ok("Email is already taken.");
                }
            }
            else
            {
                return BadRequest(ModelState);
            }

            // return CreatedAtRoute("DefaultApi", new { id = or.ID }, or);
            return null;
        }