public ActionResult Create([Bind(Include = "License_No,Expiry_Date,Notes")] License license, [Bind(Include = "Name")] Country c)
        {
            if (ModelState.IsValid)
            {
                db.Licenses.Add(license);
                //   foreach(var i in country_id)
                {
                    var n    = new License_Country();
                    var c_id = from a in db.Countries
                               where a.Name == c.Name
                               select a.Id;
                    n.Country_Id = Convert.ToInt32(c_id.FirstOrDefault());


                    var no = from a in db.Licenses
                             where a.License_No == license.License_No
                             select a.Id;
                    n.License_Id = Convert.ToInt32(no.FirstOrDefault());
                    db.License_Country.Add(n);
                }
                // db.Countries.Add(country);
                // db.Items.Add(item);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(license));
        }
        public ActionResult Deleteitem(int?Lic_id, List <int> itemCheckedIds, List <int> countryCheckboxes)
        {
            var model = new LicenseEditView();

            if (Lic_id == null)
            {
                return(Content("lic not found "));
            }
            model.Lic_details = db.Licenses.Where(x => x.Id == Lic_id.Value).Single();



            if (itemCheckedIds != null)
            {
                foreach (var itm_id in itemCheckedIds)
                {
                    License_Item lic_item = db.License_Item.Find(itm_id);
                    db.License_Item.Remove(lic_item);
                    db.SaveChanges();
                }

                var item = db.Licenses.Where(x => x.Id == Lic_id.Value).Include(z => z.License_Item.Select(y => y.Item));

                model.item = item;
                return(PartialView("LicItemEdit", model));
            }
            if (countryCheckboxes != null)
            {
                foreach (var c_id in countryCheckboxes)
                {
                    License_Country c_item = db.License_Country.Find(c_id);
                    db.License_Country.Remove(c_item);
                    db.SaveChanges();
                }

                var country = db.Licenses.Where(x => x.Id == Lic_id.Value).Include(z => z.License_Country.Select(y => y.Country));

                model.country = country;


                return(PartialView("LicCounEdit", model));
            }

            return(PartialView("LicCounEdit", model));
        }
示例#3
0
        public ActionResult Create(LicenseAdd licenseadd)
        {
            if (ModelState.IsValid)
            {
                License l = new License();
                l.License_No  = licenseadd.License_No;
                l.Expiry_Date = licenseadd.Expiry_Date;
                l.Notes       = licenseadd.Notes;
                l.UserId      = User.Identity.GetUserId();

                db.Licenses.Add(l);
                db.SaveChanges();
                var license_id = from a in db.Licenses
                                 where a.License_No == licenseadd.License_No
                                 select a.Id;
                var val = Convert.ToInt32(license_id.FirstOrDefault());
                TempData["ID"] = Convert.ToInt32(license_id.FirstOrDefault());
                if (licenseadd.SelectedCountries != null)
                {
                    foreach (var i in licenseadd.SelectedCountries)
                    {
                        var n = new License_Country();
                        n.Country_Id = i;
                        n.License_Id = Convert.ToInt32(license_id.FirstOrDefault());
                        db.License_Country.Add(n);
                    }
                }


                db.SaveChanges();



                return(RedirectToAction("Additem", new { lic_id = val }));
            }

            return(View(licenseadd));
        }
        public JsonResult Additem(LicenseEditView Licvalues)
        {
            var           lic_id = Licvalues.Lic_id;
            ViewExportAdd model  = new ViewExportAdd();

            if (Licvalues.SelectedCountries != null)
            {
                foreach (var i in Licvalues.SelectedCountries)
                {
                    var c_add      = new License_Country();
                    var item_found = from itm in db.License_Country where itm.Country_Id == i && itm.License_Id == lic_id select itm;

                    if (item_found.Any())
                    {
                        var item_name = from itm in db.Countries where itm.Id == i select itm.Name;
                        model.msg = "Item - " + item_name.FirstOrDefault() + "item already added ";
                        //view.msg = model.msg;
                        //return RedirectToAction("GetExpDetails",new { exp_id = exp_id.Value, msg = model.msg });
                        break;
                    }


                    else
                    {
                        c_add.Country_Id = i;

                        c_add.License_Id = lic_id;
                        db.License_Country.Add(c_add);
                        db.SaveChanges();
                        model.msg = "country Added";
                    }
                }
            }
            if (Licvalues.SelectedItems != null)
            {
                foreach (var i in Licvalues.SelectedItems)
                {
                    var items_add = new License_Item();


                    var item_found = from itm in db.License_Item where itm.Item_Id == i && itm.License_Id == lic_id select itm;

                    if (item_found.Any())
                    {
                        item_found.First().No_Units = Licvalues.No_Of_Units;
                        db.SaveChanges();
                        var item_name = from itm in db.Items where itm.Id == i select itm.Name;
                        model.msg = "Item - " + item_name.FirstOrDefault() + "item updated ";
                        //view.msg = model.msg;
                        //return RedirectToAction("GetExpDetails",new { exp_id = exp_id.Value, msg = model.msg });
                        break;
                    }


                    else
                    {
                        items_add.Item_Id    = i;
                        items_add.No_Units   = Licvalues.No_Of_Units;
                        items_add.License_Id = lic_id;
                        db.License_Item.Add(items_add);
                        db.SaveChanges();
                        model.msg = "item Added";
                    }
                }
            }


            model.lic_id = lic_id;

            return(Json(new { msg = model.msg }, JsonRequestBehavior.AllowGet));
        }