Exemplo n.º 1
0
 public ActionResult Edit([Bind(Include = "ID,FirstName,LastName,BirthLocation,Bio")] Folk folk)
 {
     if (ModelState.IsValid)
     {
         db.Entry(folk).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(folk));
 }
Exemplo n.º 2
0
        public ActionResult DeleteConfirmed(int id)
        {
            Folk folk = db.Folks.Find(id);

            if (folk != null)
            {
                db.Folks.Remove(folk);
            }
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 3
0
        public ActionResult Create([Bind(Include = "ID,FirstName,LastName,BirthLocation,Bio")] Folk folk)
        {
            if (ModelState.IsValid)
            {
                db.Folks.Add(folk);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(folk));
        }
Exemplo n.º 4
0
        //var query = db.Folks
        //        .Where(r => searchTerm == null || r.LastName.StartsWith(searchTerm))
        //        .OrderBy(r => r.LastName)
        //        .Take(100)
        //    .Select(r => new FolksListViewModel
        //    {
        //        Id = r.ID,
        //        FirstName = r.FirstName,
        //        LastName = r.LastName,
        //        BirthLocation = r.BirthLocation,
        //        Bio = r.Bio
        //    });

        //    return View(query);

        //    //return View(db.Folks.ToList());

        //}

        // GET: Folks/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Folk folk = db.Folks.Find(id);

            if (folk == null)
            {
                return(HttpNotFound());
            }
            return(View(folk));
        }
Exemplo n.º 5
0
        public int DeleteConfirmed(string[] inputCheck)
        {
            //System.Windows.Forms.DialogResult dailogresult = System.Windows.Forms.MessageBox.Show("Bạn có chắc chắn xóa!", "Thông báo", System.Windows.Forms.MessageBoxButtons.YesNo);
            int rowFinish = 0;

            if (inputCheck == null)
            {
                return(rowFinish);
            }
            foreach (var s in inputCheck)
            {
                try
                {
                    int  idMenu = Convert.ToInt32(DefineFuntion.Decrypt(s));
                    Folk obj    = db.Folks.Find(idMenu);
                    //1-them, 2- sua, 3-xoa, 4- khac
                    shared.CreateHistory(new History()
                    {
                        Name    = "Xóa Dân Tộc",
                        Contens = JsonConvert.SerializeObject(obj, Formatting.Indented, new JsonSerializerSettings()
                        {
                            ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
                        }),
                        ItemId = obj.FolkId,
                        Type   = (int)DefineFuntion.TypeHistory.Folk,
                    });
                    db.Folks.Remove(obj);
                    db.SaveChanges();
                    rowFinish++;
                }
                catch (Exception)
                {
                    int  idMenu = Convert.ToInt32(DefineFuntion.Decrypt(s));
                    Folk obj    = db.Folks.Find(idMenu);
                    obj.Status = 3;
                    db.SaveChanges();
                }
            }
            return(rowFinish);
        }
Exemplo n.º 6
0
        public ActionResult Edit(Folk folk, string codeSystem, string typeName)
        {
            folk.FolkId = Convert.ToInt32(DefineFuntion.Decrypt(codeSystem));
            int ms = 0;
            var me = db.Folks.Find(folk.FolkId);

            try
            {
                me.Name   = folk.Name;
                me.Status = folk.Status;
                me.Note   = folk.Note;
                db.SaveChanges();
                ms = 3;//Nếu cập nhật thành công
                //1-them, 2- sua, 3-xoa, 4- khac
                shared.CreateHistory(new History()
                {
                    Name    = "Cập Nhật Dân Tộc",
                    Contens = JsonConvert.SerializeObject(me, Formatting.Indented, new JsonSerializerSettings()
                    {
                        ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
                    }),
                    ItemId = me.FolkId,
                    Type   = (int)DefineFuntion.TypeHistory.Folk,
                });
            }
            catch (Exception)
            {
                ms = 4;//Nếu cập nhật không thành công
            }
            if (typeName == "savenew" || typeName == "")
            {
                return(RedirectToAction("Create", new { mess = ms }));
            }
            else
            {
                return(RedirectToAction("Edit", new { id = codeSystem, mess = ms }));
            }
        }
Exemplo n.º 7
0
        public ActionResult Create(Folk folk, string typeName)
        {
            var shared = new SharedFuntionController();
            int ms     = 0;

            try
            {
                db.Folks.Add(folk);
                db.SaveChanges();
                ms = 1;
                //1-them, 2- sua, 3-xoa, 4- khac
                shared.CreateHistory(new History()
                {
                    Name    = "Thêm Dân Tộc",
                    Contens = "",
                    ItemId  = folk.FolkId,
                    Type    = (int)DefineFuntion.TypeHistory.Folk,
                });
            }
            catch (Exception)
            {
                ms = 2;
            }
            if (ms != 2)
            {
                if (typeName == "savenew" || typeName == "")
                {
                    return(RedirectToAction("Create", new { mess = ms }));
                }
                else
                {
                    return(RedirectToAction("Edit", new { id = DefineFuntion.Encrypt(folk.FolkId), mess = ms }));
                }
            }
            ViewBag.Status = new SelectList(DefineFuntion.ListStatus, "Value", "Text", folk.Status);
            return(View("Create", "Folk"));
        }