Exemplo n.º 1
0
        public ActionResult Delete(int id, Code_EquipViewModel collection)
        {
            try
            {
                using (OnlineShopDbContext db = new OnlineShopDbContext())
                {
                    Code_EquipViewModel model = new Code_EquipViewModel();
                    Code_Equip          Exsiting_Code_Equip = db.Code_Equip.Find(id);
                    db.Code_Equip.Remove(Exsiting_Code_Equip);
                    db.SaveChanges();

                    //--------Add Dropdown for MainProjectName-------------------//
                    model.Code_Group     = db.Code_Group.OrderBy(m => m.ID).ToList();
                    model.Code_Group_All = new List <SelectListItem>();
                    var items = new List <SelectListItem>();
                    foreach (var Code_Group in model.Code_Group)
                    {
                        items.Add(new SelectListItem()
                        {
                            Value = Code_Group.ID.ToString(),
                            Text  = Code_Group.Code,
                        });
                    }
                    model.Code_Group_All = items;
                    //--------Add Dropdown for MainProjectName-------------------//

                    return(View("Finish", model));
                }
            }
            catch
            {
                return(View());
            }
        }
Exemplo n.º 2
0
        public ActionResult Create(Code_EquipViewModel collection)
        {
            try
            {
                using (OnlineShopDbContext db = new OnlineShopDbContext())
                {
                    Code_Equip          obj   = new Code_Equip();
                    Code_EquipViewModel model = new Code_EquipViewModel();
                    model.Code_Equip = db.Code_Equip.OrderBy(m => m.ID).ToList();

                    obj.ID_Code = collection.Code_EquipSelect.ID_Code;
                    obj.Equip   = collection.Code_EquipSelect.Equip;

                    db.Code_Equip.Add(obj);
                    db.SaveChanges();

                    //--------Add Dropdown for MainProjectName-------------------//
                    model.Code_Group     = db.Code_Group.OrderBy(m => m.ID).ToList();
                    model.Code_Group_All = new List <SelectListItem>();
                    var items = new List <SelectListItem>();
                    foreach (var Code_Group in model.Code_Group)
                    {
                        items.Add(new SelectListItem()
                        {
                            Value = Code_Group.ID.ToString(),
                            Text  = Code_Group.Code,
                        });
                    }
                    model.Code_Group_All = items;
                    //--------Add Dropdown for MainProjectName-------------------//

                    return(View("Create", model));
                }
            }
            catch
            {
                using (OnlineShopDbContext db = new OnlineShopDbContext())
                {
                    Code_EquipViewModel model = new Code_EquipViewModel();
                    model.Code_Equip = db.Code_Equip.OrderBy(m => m.ID).ToList();

                    //--------Add Dropdown for MainProjectName-------------------//
                    model.Code_Group     = db.Code_Group.OrderBy(m => m.ID).ToList();
                    model.Code_Group_All = new List <SelectListItem>();
                    var items = new List <SelectListItem>();
                    foreach (var Code_Group in model.Code_Group)
                    {
                        items.Add(new SelectListItem()
                        {
                            Value = Code_Group.ID.ToString(),
                            Text  = Code_Group.Code,
                        });
                    }
                    model.Code_Group_All = items;
                    //--------Add Dropdown for MainProjectName-------------------//

                    return(View("Create", model));
                }
            }
        }