Exemplo n.º 1
0
        public ActionResult TagNew(TagViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {

                    using (UnitOfWork uow = new UnitOfWork())
                    {
                        TagRepository tr = new TagRepository(uow.Current);
                        Tag t = new Tag(model.Nome);

                        tr.SaveOrUpdate(t);
                        uow.Commit();

                        model.Message = "Salvataggio eseguito correttamente!";
                    }
                }
                return View(model);
            }
            catch (Exception ex)
            {
                return Error(ex);
            }
        }
Exemplo n.º 2
0
 public ActionResult TagDetail(int id)
 {
     try
     {
         TagViewModel cvm = new TagViewModel();
         using (UnitOfWork uow = new UnitOfWork())
         {
             TagRepository tr = new TagRepository(uow.Current);
             Tag t = tr.GetById(id);
             if (t != null)
             {
                 cvm.Nome = t.Name;
                 cvm.Id = t.Id;
             }
         }
         return View(cvm);
     }
     catch (Exception ex)
     {
         return Error(ex);
     }
 }
Exemplo n.º 3
0
        public ActionResult TagDetail(TagViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (UnitOfWork uow = new UnitOfWork())
                    {
                        TagRepository tr = new TagRepository(uow.Current);
                        Tag t = tr.GetById(model.Id);

                        if (t != null)
                        {
                            t.ModifyName(model.Nome);

                            tr.SaveOrUpdate(t);
                            uow.Commit();

                            model.Message = "Modifica eseguita con successo!";
                        }
                        else
                            model.Message = "Si è verificato un errore durante l'aggiornamento dei dati! Recupero entità da modifica non avvenuto con successo!";
                    }
                }
                return View(model);
            }
            catch (Exception ex)
            {
                return Error(ex);
            }
        }
Exemplo n.º 4
0
        public ActionResult Tags()
        {
            try
            {
                IList<TagViewModel> tagList = null;
                using (UnitOfWork uow = new UnitOfWork())
                {
                    TagRepository tr = new TagRepository(uow.Current);
                    IList<Tag> tmpList = tr.FindAll().ToList();
                    if (tmpList != null)
                    {
                        tagList = new List<TagViewModel>();
                        foreach (var c in tmpList)
                        {
                            TagViewModel cvm = new TagViewModel();

                            cvm.Nome = c.Name;
                            cvm.Id = c.Id;

                            tagList.Add(cvm);
                        }
                    }
                }
                return View(tagList);
            }
            catch (Exception ex)
            {
                return Error(ex);
            }
        }