public ActionResult Edit(AgentCollectionRateVM v)
        {
            tblAgentCollectionRate a = new tblAgentCollectionRate();

            a.ID          = v.ID;
            a.AgentID     = v.AgentID;
            a.ZoneChartID = v.ZoneID;

            int countryid = Convert.ToInt32(Session["depotcountry"].ToString());

            a.CountryID        = countryid;
            a.CourierServiceID = v.ProductTypeID;
            a.BaseWeight       = v.BaseWeight;
            a.BaseRate         = v.BaseRate;

            db.Entry(a).State = EntityState.Modified;
            db.SaveChanges();

            var data = (from c in db.tblAgentCollectionRateDetails where c.AgentCollectionRateID == v.ID select c).ToList();

            foreach (var item in data)
            {
                db.tblAgentCollectionRateDetails.Remove(item);
                db.SaveChanges();
            }
            foreach (var item in v.AgentCollectionRateDetailVM)
            {
                tblAgentCollectionRateDetail b = new tblAgentCollectionRateDetail();

                b.AgentCollectionRateID = a.ID;
                b.AdditionalWeightFrom  = item.AddWtFrom;
                b.AdditionalWeightTo    = item.AddWtTo;
                b.IncrementalWeight     = item.IncrWt;
                b.AdditionalRate        = item.AddRate;

                db.tblAgentCollectionRateDetails.Add(b);


                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
        public ActionResult Create(AgentCollectionRateVM v)
        {
            tblAgentCollectionRate a = new tblAgentCollectionRate();

            int max = (from d in db.tblAgentCollectionRates orderby d.ID descending select d.ID).FirstOrDefault();

            a.ID          = max + 1;
            a.AgentID     = v.AgentID;
            a.ZoneChartID = v.ZoneID;

            int countryid = Convert.ToInt32(Session["depotcountry"].ToString());

            a.CountryID        = countryid;
            a.CourierServiceID = v.ProductTypeID;
            a.BaseWeight       = v.BaseWeight;
            a.BaseRate         = v.BaseRate;

            db.tblAgentCollectionRates.Add(a);
            db.SaveChanges();

            foreach (var item in v.AgentCollectionRateDetailVM)
            {
                tblAgentCollectionRateDetail b = new tblAgentCollectionRateDetail();

                b.AgentCollectionRateID = a.ID;
                b.AdditionalWeightFrom  = item.AddWtFrom;
                b.AdditionalWeightTo    = item.AddWtTo;
                b.IncrementalWeight     = item.IncrWt;
                b.AdditionalRate        = item.AddRate;

                db.tblAgentCollectionRateDetails.Add(b);


                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }