public ActionResult Create(ViewExportAdd exportvalues) { if (ModelState.IsValid) { Export export = new Export(); export.Reference_No = exportvalues.Export.Reference_No; export.Export_Date = exportvalues.Export.Export_Date; export.License_Id = exportvalues.Selectedlicense.FirstOrDefault(); db.Exports.Add(export); db.SaveChanges(); var export_id = from a in db.Exports where a.Reference_No == exportvalues.Export.Reference_No select a.Id; TempData["id"] = Convert.ToInt32(export_id.FirstOrDefault()); if (exportvalues.Selectedcountrylist != null) { foreach (var i in exportvalues.Selectedcountrylist) { var exp_country = new Export_Country(); exp_country.Country_Id = i; exp_country.Export_Id = Convert.ToInt32(export_id.FirstOrDefault()); db.Export_Country.Add(exp_country); } } db.SaveChanges(); return(RedirectToAction("AddExportitem", new { exp_id = Convert.ToInt32(export_id.FirstOrDefault()), lic_id = exportvalues.Selectedlicense.FirstOrDefault() })); } return(Content("done")); }
public ActionResult DeleteExportitem(int exp_id, List <int> itemCheckedIds, List <int> countryCheckboxes) { var model = new Export_view(); if (itemCheckedIds != null) { foreach (var itm_id in itemCheckedIds) { Export_Item exp_item = db.Export_Item.Find(itm_id); db.Export_Item.Remove(exp_item); db.SaveChanges(); } } if (countryCheckboxes != null) { foreach (var c_id in countryCheckboxes) { Export_Country c_item = db.Export_Country.Find(c_id); db.Export_Country.Remove(c_item); db.SaveChanges(); } var country = db.Exports.Where(x => x.Id == exp_id).Include(z => z.Export_Country.Select(y => y.Country)); model.exp_country = country; // ViewBag.t_id = exp_id.Value; return(PartialView("Displaycountry", model)); } var items = db.Exports.Where(x => x.Id == exp_id).Include(z => z.Export_Item.Select(y => y.Item)); model.exp_item = items; return(PartialView("Itemdisplay", model)); }
public JsonResult Additem(ViewExportAdd exportvalues) { var exp_id = exportvalues.exp_id; ViewExportAdd model = new ViewExportAdd(); Export_view view = new Export_view(); var lic_id = db.Exports.Where(z => z.Id == exp_id).Include(x => x.License).Single(); if (exportvalues.Selectedcountrylist != null) { foreach (var i in exportvalues.Selectedcountrylist) { var c_add = new Export_Country(); var item_found = from itm in db.Export_Country where itm.Country_Id == i && itm.Export_Id == exp_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.Export_Id = exp_id; db.Export_Country.Add(c_add); db.SaveChanges(); model.msg = "country Added"; } } } if (exportvalues.SelectedItems != null) { foreach (var i in exportvalues.SelectedItems) { var items_add = new Export_Item(); var units_total = from itm in db.License_Item where itm.Item_Id == i && itm.License_Id == lic_id.License_Id select itm.No_Units; var exp_ids = db.Exports.Where(z => z.License_Id == lic_id.License_Id).Select(y => y.Id); var sum_units = from f in db.Export_Item where exp_ids.Contains(f.Exporter_Id) group f by f.Item_Id into g orderby g.Sum(x => x.No_Of_Units) select new { item_code = g.Key, //item_value = g.First()., total = g.Sum(x => x.No_Of_Units) }; var sum = 0; foreach (var n in sum_units) { if (n.item_code == i) { sum = n.total; break; } } var units_allowed = (units_total.SingleOrDefault()) - sum; if (( units_allowed) < exportvalues.No_Of_Units) { model.msg = "no of units can't exceed than" + ( units_allowed); view.msg = model.msg; break; // return RedirectToAction("GetExpDetails", new { exp_id = exp_id.Value, msg = model.msg }); } var item_found = from itm in db.Export_Item where itm.Item_Id == i && itm.Exporter_Id == exp_id select itm; if (item_found.Any()) { item_found.First().No_Of_Units = exportvalues.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_Of_Units = exportvalues.No_Of_Units; items_add.Exporter_Id = exp_id; db.Export_Item.Add(items_add); db.SaveChanges(); model.msg = "item Added"; } } } model.exp_id = exp_id; // model.Items= new SelectListItem(item_list.ToList(), "Id", "Name") // db.SaveChanges(); // return PartialView("EdititemPartialView", model); // return View(model); // return RedirectToAction("GetExpDetails", new { exp_id = exp_id.Value, msg = "item added" }); return(Json(new { msg = model.msg }, JsonRequestBehavior.AllowGet)); }