public ActionResult ManageWorkPackages(Models.SoftwareReqtsModel S, string id)
        {
            Models.DataBaseTableClassesDataContext db=new Models.DataBaseTableClassesDataContext();
            S.SelectedId = id;
            var query = from ws in db.WpsForSrs
                        where ws.Sr_ID == Int32.Parse(S.SelectedId)
                        select ws.WorkPackageDescription;
            foreach (var m in query)
            {
                SelectListItem li = new SelectListItem();
                li.Text = m.Wp_Title;
                li.Value = m.Wp_Id.ToString();
                S.Wp_used.Add(li);
            }

            foreach (Models.WorkPackageDescription wp in db.WorkPackageDescriptions)
            {
                int k;
                SelectListItem li = new SelectListItem();
                li.Text = wp.Wp_Title;
                li.Value = wp.Wp_Id.ToString();

                    for ( k = 0; k < S.Wp_used.Count; k++)
                    {
                        if (S.Wp_used[k].Value == li.Value)
                            break;
                    }
                    if (k < S.Wp_used.Count)
                        continue;
                S.Wp_unused.Add(li);
            }

            return View(S);
        }
 public ActionResult DetailedView(Models.SoftwareReqtsModel S,string id)
 {
     Models.DataBaseTableClassesDataContext db = new Models.DataBaseTableClassesDataContext();
     S.SelectedId = id;
     var query = from ws in db.WpsForSrs
                 where ws.Sr_ID == Int32.Parse(S.SelectedId)
                 select ws.WorkPackageDescription;
     foreach (var q in query)
     {
         SelectListItem li = new SelectListItem();
         li.Text = q.Wp_Title;
         li.Value = q.Wp_Id.ToString();
         S.Wp_used.Add(li);
     }
     return View(S);
 }
        public ActionResult WpSubmit(Models.SoftwareReqtsModel S, FormCollection coll)
        {
            S.SelectedId = Session["srid"].ToString();
            try
            {

                Models.DataBaseTableClassesDataContext db = new Models.DataBaseTableClassesDataContext();
                var query = from ws in db.WpsForSrs
                            where ws.Sr_ID == Int32.Parse(S.SelectedId)
                            select ws.WorkPackageDescription;
                foreach (var m in query)
                {
                    SelectListItem li = new SelectListItem();
                    li.Text = m.Wp_Title;
                    li.Value = m.Wp_Id.ToString();
                    S.Wp_used.Add(li);
                }
                string[] selected = coll.GetValues("SelectedPackages");
                if (selected != null)
                {
                    foreach (string s in selected)
                    {
                        int i;
                        for (i = 0; i < S.Wp_used.Count; i++)
                        {
                            if (s == S.Wp_used[i].Value)
                                break;
                        }
                        if (i == S.Wp_used.Count)
                        {

                            var que = from srs in db.WpsForSrs
                                        where srs.Wp_Id.ToString() == s && S.SelectedId == srs.Sr_ID.ToString()
                                        select srs;
                            db.WpsForSrs.DeleteAllOnSubmit(que);
                        }
                    }
                    db.SubmitChanges();
                }
                else
                {
                    foreach (SelectListItem s in S.Wp_used)
                    {
                        var que = from srp in db.WpsForSrs
                                    where srp.Wp_Id == Int32.Parse(s.Value) && srp.Sr_ID == Int32.Parse(S.SelectedId)
                                    select srp;
                        db.WpsForSrs.DeleteAllOnSubmit(que);
                    }
                    db.SubmitChanges();
                }
                selected = coll.GetValues("UnselectedPackages");
                if (selected != null)
                {
                    foreach (string s in selected)
                    {
                        Models.WpsForSr ws=new Models.WpsForSr();
                        ws.Sr_ID=Int32.Parse(S.SelectedId);
                        ws.Wp_Id=Int32.Parse(s);
                        db.WpsForSrs.InsertOnSubmit(ws);

                    }
                    db.SubmitChanges();
                }
            }
            catch
            {
                Session["ErrorMessage"] = "Failed To Submit Changes";
                return RedirectToAction("ErrorPage", "Home");
            }
            return RedirectToAction("DetailedView/" + S.SelectedId);
        }