コード例 #1
0
        public ActionResult CreateTag(TagVM model)

        {
            if (ModelState.IsValid)
            {
                using (ApplicationDbContext db = new ApplicationDbContext())
                {
                    var nameTag = db.Tags.FirstOrDefault(x => x.Name == model.Name && x.IsDelete == false);
                    if (nameTag == null)
                    {
                        Models.DB.Tag tag = new Models.DB.Tag();
                        tag.Name     = model.Name;
                        tag.IsDelete = false;
                        db.Tags.Add(tag);
                        db.SaveChanges();
                        return(RedirectToAction("CompanyTagsList"));
                    }
                    else
                    {
                        TempData["alertMessage"] = "Etykieta o takiej nazwie już istnieje";
                    }
                }
                return(RedirectToAction("CompanyTagsList"));
            }
            TempData["alertMessage"] = "Niepoprawna nazwa etykiety";
            return(RedirectToAction("CompanyTagsList"));
        }
コード例 #2
0
 public ActionResult TagDelete(TagVM model)
 {
     using (ApplicationDbContext db = new ApplicationDbContext())
     {
         Models.DB.Tag tag = db.Tags.FirstOrDefault(t => t.Name == model.Name);
         tag.IsDelete = true;
         db.SaveChanges();
         return(RedirectToAction("TagsList"));
     }
 }