Exemple #1
0
        // POST: Customer/SaveCustomerAndProductRelation
        public ActionResult SaveCustomerAndProductRelation(CustomerProductFormViewModel viewModel)
        {
            ChemAnalystContext _context = new ChemAnalystContext();

            foreach (var item in viewModel.SA_Product)
            {
                if (item.IsSelected)
                {
                    CustomerAndProducRelation customerAndProducRelation = new CustomerAndProducRelation();
                    customerAndProducRelation.Lead_MasterId = viewModel.Lead_Master.Id;
                    customerAndProducRelation.SA_ProductId  = item.id;
                    _context.CustomerAndProducRelation.Add(customerAndProducRelation);
                }
            }
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #2
0
        // GET: Customer/AddCustomerAndProduct/5
        public ActionResult AddCustomerAndProduct(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            ChemAnalystContext _context = new ChemAnalystContext();
            var customer = _context.Lead_Master.SingleOrDefault(c => c.Id == id);

            if (customer == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }

            var viewModel = new CustomerProductFormViewModel()
            {
                Lead_Master = customer,
                SA_Product  = _context.SA_Product.ToList()
            };

            return(View(viewModel));
        }