public ActionResult Create(DBhouseMv dBhouseMv)
        {
            if (ModelState.IsValid)
            {
                tbld_distribution_house tbldDistributionHouse = new tbld_distribution_house
                {
                    DB_Id                = dBhouseMv.DbId,
                    DBName               = dBhouseMv.DbName,
                    DBCode               = dBhouseMv.DbCode,
                    DBDescription        = dBhouseMv.DbDescription,
                    OfficeAddress        = dBhouseMv.OfficeAddress,
                    WarehouseAddress     = dBhouseMv.WarehouseAddress,
                    OwnerName            = dBhouseMv.OwnerName,
                    OwnerMoble           = dBhouseMv.OwnerMoble,
                    EmailAddress         = dBhouseMv.EmailAddress,
                    CreateDate           = DateTime.Now,
                    ModifiedDate         = DateTime.Now,
                    Cluster_id           = dBhouseMv.ClusterId,
                    Zone_id              = dBhouseMv.ZoneId,
                    PriceBuandle_id      = dBhouseMv.PriceBuandleId,
                    DeliveryModuleStatus = dBhouseMv.DeliveryModuleStatus,
                    Status               = dBhouseMv.Status,
                    MV     = dBhouseMv.Mv,
                    NMV    = dBhouseMv.Nmv,
                    Remark = dBhouseMv.Remark,
                };

                Db.tbld_distribution_house.Add(tbldDistributionHouse);
                Db.SaveChanges();

                int dBid = tbldDistributionHouse.DB_Id;

                tblt_System tbltSystem = new tblt_System
                {
                    DBid         = dBid,
                    CurrentDate  = DateTime.Now.Date,
                    NextDate     = DateTime.Now.Date.AddDays(1),
                    PreviousDate = DateTime.Now.Date.AddDays(-1),
                    UpdateDate   = DateTime.Now
                };

                Db.tblt_System.Add(tbltSystem);
                Db.SaveChanges();

                TempData["alertbox"]    = "success";
                TempData["alertboxMsg"] = dBhouseMv.DbName + "  Create Successfully";

                return(RedirectToAction("Index"));
            }

            ViewBag.Cluster      = new SelectList(Db.tbld_cluster.ToList(), "id", "name");
            ViewBag.Zone         = new SelectList(Db.tbld_business_zone.Where(x => x.biz_zone_category_id == 4).ToList(), "id", "biz_zone_name");
            ViewBag.PriceBuandle = new SelectList(Db.tbld_bundle_price.ToList(), "Id", "Name");
            ViewBag.isactive     = new SelectList(Db.status.ToList(), "status_Id", "status_code");
            return(View(dBhouseMv));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            tbld_distribution_house tbldDistributionHouse = Db.tbld_distribution_house.Find(id);

            if (tbldDistributionHouse != null)
            {
                Db.tbld_distribution_house.Remove(tbldDistributionHouse);
            }
            Db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tbld_distribution_house tbldDistributionHouse = Db.tbld_distribution_house.Find(id);

            if (tbldDistributionHouse == null)
            {
                return(HttpNotFound());
            }
            return(View(tbldDistributionHouse));
        }
        public ActionResult Edit(DBhouseMv dBhouseMv)
        {
            if (ModelState.IsValid)
            {
                tbld_distribution_house tbldDistributionHouse = new tbld_distribution_house
                {
                    DB_Id                = dBhouseMv.DbId,
                    DBName               = dBhouseMv.DbName,
                    DBCode               = dBhouseMv.DbCode,
                    DBDescription        = dBhouseMv.DbDescription,
                    OfficeAddress        = dBhouseMv.OfficeAddress,
                    WarehouseAddress     = dBhouseMv.WarehouseAddress,
                    OwnerName            = dBhouseMv.OwnerName,
                    OwnerMoble           = dBhouseMv.OwnerMoble,
                    EmailAddress         = dBhouseMv.EmailAddress,
                    CreateDate           = dBhouseMv.CreateDate,
                    ModifiedDate         = DateTime.Now,
                    Cluster_id           = dBhouseMv.ClusterId,
                    Zone_id              = dBhouseMv.ZoneId,
                    PriceBuandle_id      = dBhouseMv.PriceBuandleId,
                    DeliveryModuleStatus = dBhouseMv.DeliveryModuleStatus,
                    Status               = dBhouseMv.Status,
                    MV              = dBhouseMv.Mv,
                    NMV             = dBhouseMv.Nmv,
                    Remark          = dBhouseMv.Remark,
                    LastReplacement = dBhouseMv.LastReplacement
                };

                if (dBhouseMv.IsReplacement == true)
                {
                    tbldDistributionHouse.LastReplacement = DateTime.Today;
                }



                Db.Entry(tbldDistributionHouse).State = EntityState.Modified;
                Db.SaveChanges();

                TempData["alertbox"]    = "success";
                TempData["alertboxMsg"] = dBhouseMv.DbName + "  Edit Successfully";

                return(RedirectToAction("Index"));
            }
            ViewBag.Cluster      = new SelectList(Db.tbld_cluster.ToList(), "id", "name");
            ViewBag.Zone         = new SelectList(Db.tbld_business_zone.Where(x => x.biz_zone_category_id == 4).ToList(), "id", "biz_zone_name");
            ViewBag.PriceBuandle = new SelectList(Db.tbld_bundle_price.ToList(), "Id", "Name");
            ViewBag.isactive     = new SelectList(Db.status.ToList(), "status_Id", "status_code");
            return(View(dBhouseMv));
        }
        // GET: DBhouse/Edit/5

        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tbld_distribution_house tbldDistributionHouse = Db.tbld_distribution_house.Find(id);

            if (tbldDistributionHouse != null)
            {
                DBhouseMv dBhouseMv = new DBhouseMv
                {
                    DbId                 = tbldDistributionHouse.DB_Id,
                    DbName               = tbldDistributionHouse.DBName,
                    DbCode               = tbldDistributionHouse.DBCode,
                    DbDescription        = tbldDistributionHouse.DBDescription,
                    OfficeAddress        = tbldDistributionHouse.OfficeAddress,
                    WarehouseAddress     = tbldDistributionHouse.WarehouseAddress,
                    OwnerName            = tbldDistributionHouse.OwnerName,
                    OwnerMoble           = tbldDistributionHouse.OwnerMoble,
                    EmailAddress         = tbldDistributionHouse.EmailAddress,
                    CreateDate           = tbldDistributionHouse.CreateDate,
                    ModifiedDate         = tbldDistributionHouse.ModifiedDate,
                    ClusterId            = tbldDistributionHouse.Cluster_id,
                    ZoneId               = tbldDistributionHouse.Zone_id,
                    PriceBuandleId       = tbldDistributionHouse.PriceBuandle_id,
                    DeliveryModuleStatus = tbldDistributionHouse.DeliveryModuleStatus,
                    Status               = tbldDistributionHouse.Status,
                    Mv              = tbldDistributionHouse.MV,
                    Nmv             = tbldDistributionHouse.NMV,
                    LastReplacement = tbldDistributionHouse.LastReplacement,
                    Remark          = tbldDistributionHouse.Remark
                };
                dBhouseMv.ModifiedDate = DateTime.Now;
                ViewBag.Cluster        = new SelectList(Db.tbld_cluster.ToList(), "id", "name");
                ViewBag.Zone           = new SelectList(Db.tbld_business_zone.Where(x => x.biz_zone_category_id == 4).ToList(), "id", "biz_zone_name");
                ViewBag.PriceBuandle   = new SelectList(Db.tbld_bundle_price.ToList(), "Id", "Name");
                ViewBag.isactive       = new SelectList(Db.status.ToList(), "status_Id", "status_code");
                return(View(dBhouseMv));
            }
            return(RedirectToAction("Index"));
        }