//
        // GET: /Category/Get/By ID

        public ActionResult Get(int id)
        {
            try
            {
                var categories = Session["categories"];

                var beCategory = new BECategory();
                if (id != 0)
                {
                    beCategory = _db.GetCategory(id);
                }

                if (beCategory != null)
                {
                    var categoryModel = new CategoryModel {
                        CategoryId = beCategory.CategoryId, CategoryName = beCategory.CategoryName
                    };

                    //return PartialView("_Edit", categoryModel);
                    return(PartialView("_Common", categoryModel));
                }
                else
                {
                    return(RedirectToAction("Index", "Category"));
                }
            }
            catch (Exception ex)
            {
                ExceptionHelper.ExceptionMessageFormat(ex);
                return(RedirectToAction("Index", "Category"));
            }
        }
        public ActionResult Save(CategoryModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var beCategory = new BECategory {
                        CategoryId = model.CategoryId, CategoryName = model.CategoryName, UpdatedBy = 2
                    };                                                                                                                   //Temp UpdatedBy

                    beCategory.IsNew = model.CategoryId == 0;

                    //_db.Save(beCategory);

                    return(Content(Boolean.TrueString));
                }

                return(Content(ExceptionHelper.ModelStateErrorFormat(ModelState)));
            }
            catch (Exception ex)
            {
                ExceptionHelper.ExceptionMessageFormat(ex);
                return(Content("Sorry! Unable to edit this category."));
            }
        }
Ejemplo n.º 3
0
        public BECategory ModifierCategory(int idCat, string nom, bool pardef, int idUser)
        {
            CategoryDao categoryDao = new CategoryDao();

            if (!categoryDao.CateogryExisteDeja(idCat))
            {
                throw new ArgumentException("La categorie n'existe pas", "id");
            }

            BECategory category = null;

            try
            {
                category = categoryDao.ModifierCategory(idCat, nom, pardef, idUser);
                if (category == null)
                {
                    throw new Exception("La categorie est null.");
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Une erreur est survenue lors de la modification de la catégorie", ex);
            }

            return(category);
        }
Ejemplo n.º 4
0
        public void Save(SQLHelper sqlHelper, BECategory category)
        {
            string sql = string.Empty;

            try
            {
                if (category.IsNew)
                {
                    // update tblTableCode
                    DATableCode daTableCode = new DATableCode();
                    category.Code = daTableCode.UpdateTableCodeAtSave(sqlHelper, "TblCategory");

                    sql = sqlHelper.MakeSQL(@"INSERT INTO TblCategory(CategoryName,Code,CreatedBy,CreatedDate)"
                                            + " VALUES($s,$s,$n, SYSDATE)", category.CategoryName, category.Code, category.CreatedBy);
                }
                else
                {
                    sql = sqlHelper.MakeSQL(@"UPDATE TblCategory SET CategoryName=$s,Code=$s,UpdatedBy=$n,UpdatedDate=SYSDATE WHERE CATEGORYID=$n",
                                            category.CategoryName, category.Code, category.UpdatedBy, category.CategoryId);
                }

                sqlHelper.ExecuteNonQuery(sql);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Ejemplo n.º 5
0
        public BECategory ModifierCategory(int idCat, string nom, bool pardef, int idUser)
        {
            if (string.IsNullOrWhiteSpace(nom))
            {
                throw new ArgumentException("Veuillez renseigner la category.", "nom");
            }

            using (TodoListUCBLEntities context = new TodoListUCBLEntities())
            {
                Category c = context.CategorySet.FirstOrDefault(cat => cat.Id == idCat);
                if (nom != c.Nom)
                {
                    c.Nom = nom;
                }
                if (pardef != c.ParDefaut)
                {
                    if (context.CategorySet.Include("Utilisateur").Where(cat => cat.Utilisateur.Id == idUser).ToList().Count() == 1)
                    {
                        c.ParDefaut = true;
                    }
                    else
                    {
                        c.ParDefaut = pardef;
                    }
                }

                List <Category> LastCateg = context.CategorySet.Include("Taches").Where(cc => cc.Utilisateur.Id == idUser && cc.ParDefaut == true).ToList();

                if (LastCateg.Count() == 1)
                {
                    Category categ = context.CategorySet.First(nomdevariabletrèschiantadefinirsansconflit => nomdevariabletrèschiantadefinirsansconflit.Utilisateur.Id == idUser && nomdevariabletrèschiantadefinirsansconflit.ParDefaut == false);
                    categ.ParDefaut = true;
                }

                context.SaveChanges();

                BECategory retour = new BECategory();
                retour.Id        = c.Id;
                retour.Nom       = c.Nom;
                retour.ParDefaut = c.ParDefaut;

                Utilisateur u = context.UtilisateurSet.FirstOrDefault(us => us.Id == idUser);

                BEUtilisateur user = new BEUtilisateur();
                user.Id       = u.Id;
                user.Login    = u.Login;
                user.Nom      = u.Nom;
                user.Password = u.Password;
                user.Prenom   = u.Prenom;
                user.Email    = u.Email;

                retour.Utilisateur = user;

                return(retour);
            }
        }
Ejemplo n.º 6
0
 private void RemoveCateg_Click(object sender, RoutedEventArgs e)
 {
     if (this.ListSort.SelectedItem != null)
     {
         BECategory c = this.ListSort.SelectedItem as BECategory;
         this.OriginalCategories.Add(c);
         CategoriesToAdd.Remove(c);
         this.Refresh();
     }
 }
Ejemplo n.º 7
0
        public List <BETache> getTaches(int idUser)
        {
            using (TodoListUCBLEntities context = new TodoListUCBLEntities())
            {
                //Récup de l'utilisateur pour toute la suite
                Utilisateur   userBD = context.UtilisateurSet.First(u => u.Id == idUser);
                BEUtilisateur user   = new BEUtilisateur();
                user.Id       = userBD.Id;
                user.Login    = userBD.Login;
                user.Nom      = userBD.Nom;
                user.Password = userBD.Password;
                user.Prenom   = userBD.Prenom;
                user.Email    = userBD.Email;

                //Récup de la liste des tâches liées a l'utilisateur
                List <BETache> retour = new List <BETache>();
                List <Tache>   list   = context.TacheSet.Include("Categories").Include("Utilisateur").Include("Etat").Where(c => c.Utilisateur.Id == idUser).ToList();

                foreach (Tache t in list)
                {
                    BETache tach = new BETache();
                    tach.Id     = t.Id;
                    tach.Nom    = t.Nom;
                    tach.Debut  = t.Debut;
                    tach.Fin    = t.Fin;
                    tach.Detail = t.Detail;

                    foreach (Category c in t.Categories)
                    {
                        BECategory cat = new BECategory();
                        cat.Id          = c.Id;
                        cat.Nom         = c.Nom;
                        cat.ParDefaut   = c.ParDefaut;
                        cat.Utilisateur = user;

                        tach.Categories.Add(cat);
                    }

                    tach.Utilisateur = user;

                    BEEtat et = new BEEtat();
                    et.Id      = t.Etat.Id;
                    et.Libelle = t.Etat.Libelle;
                    et.Code    = t.Etat.Code;

                    tach.Etat = et;

                    retour.Add(tach);
                }

                return(retour);
            }
        }
Ejemplo n.º 8
0
        private BECategory PreaperCategoryObject(NULLHandler nullHandler)
        {
            BECategory category = new BECategory();

            category.IsNew        = false;
            category.CategoryName = nullHandler.GetString("CategoryName");
            category.CategoryId   = nullHandler.GetInt("CategoryId");
            category.Code         = nullHandler.GetString("Code");
            category.CreatedBy    = nullHandler.GetInt("CreatedBy");
            category.CreatedDate  = nullHandler.GetDateTime("CreatedDate");
            category.UpdatedBy    = nullHandler.GetInt("UpdatedBy");
            category.UpdatedDate  = nullHandler.GetDateTime("UpdatedDate");
            category.IsDeleted    = nullHandler.GetBoolean("IsDeleted");

            return(category);
        }
Ejemplo n.º 9
0
 public void Save(BECategory Category)
 {
     try
     {
         sqlHelper = new SQLHelper(true);
         daCategory.Save(sqlHelper, Category);
         sqlHelper.CommitTran();
     }
     catch (Exception ex)
     {
         RnD.BLTemp.Common.Utility.SaveErrorLog(this.GetType().ToString(), "", ex);
         if (sqlHelper != null)
         {
             sqlHelper.Rollback();
         }
         throw ex;
     }
 }
Ejemplo n.º 10
0
        public BECategory AjouterCategory(int idUser, string nom, bool pardefaut)
        {
            if (string.IsNullOrWhiteSpace(nom))
            {
                throw new ArgumentException("Veuillez renseigner la category.", "nom");
            }

            using (TodoListUCBLEntities context = new TodoListUCBLEntities())
            {
                Category c = new Category();
                c.Nom = nom;
                if (context.CategorySet.Include("Utilisateur").Where(cat => cat.Utilisateur.Id == idUser).ToList().Count() == 0)
                {
                    c.ParDefaut = true;
                }
                else
                {
                    c.ParDefaut = pardefaut;
                }

                c.Utilisateur = context.UtilisateurSet.First(u => u.Id == idUser);

                context.CategorySet.Add(c);

                context.SaveChanges();

                BECategory retour = new BECategory();

                retour.Id        = c.Id;
                retour.Nom       = c.Nom;
                retour.ParDefaut = c.ParDefaut;

                BEUtilisateur user = new BEUtilisateur();
                user.Email         = c.Utilisateur.Email;
                user.Id            = c.Utilisateur.Id;
                user.Login         = c.Utilisateur.Login;
                user.Password      = c.Utilisateur.Password;
                user.Prenom        = c.Utilisateur.Prenom;
                retour.Utilisateur = user;

                return(retour);
            }
        }
Ejemplo n.º 11
0
 public BECategory GetCategory(int CategoryId)
 {
     try
     {
         BECategory category = null;
         sqlHelper = new SQLHelper();
         category  = daCategory.GetCategory(sqlHelper, CategoryId);
         sqlHelper.CommitTran();
         return(category);
     }
     catch (Exception ex)
     {
         RnD.BLTemp.Common.Utility.SaveErrorLog(this.GetType().ToString(), "", ex);
         if (sqlHelper != null)
         {
             sqlHelper.Rollback();
         }
         throw ex;
     }
 }
Ejemplo n.º 12
0
        public List <BECategory> GetCategories(int idUser)
        {
            using (TodoListUCBLEntities context = new TodoListUCBLEntities())
            {
                Utilisateur   userBD = context.UtilisateurSet.First(us => us.Id == idUser);
                BEUtilisateur user   = new BEUtilisateur();
                user.Id       = userBD.Id;
                user.Login    = userBD.Login;
                user.Nom      = userBD.Nom;
                user.Password = userBD.Password;
                user.Prenom   = userBD.Prenom;
                user.Email    = userBD.Email;

                List <BECategory> retour = new List <BECategory>();
                List <Category>   list   = context.CategorySet.Include("Utilisateur").Include("Taches").Where(c => c.Utilisateur.Id == idUser).ToList();

                foreach (Category c in list)
                {
                    BECategory cat = new BECategory();
                    cat.Id          = c.Id;
                    cat.Nom         = c.Nom;
                    cat.ParDefaut   = c.ParDefaut;
                    cat.Utilisateur = user;

                    foreach (Tache t in c.Taches)
                    {
                        BETache tache = new BETache();
                        tache.Id     = t.Id;
                        tache.Nom    = t.Nom;
                        tache.Debut  = t.Debut;
                        tache.Fin    = t.Fin;
                        tache.Detail = t.Detail;

                        cat.Taches.Add(tache);
                    }

                    retour.Add(cat);
                }
                return(retour);
            }
        }
Ejemplo n.º 13
0
        public BECategory AjouterCategory(int id, String nom, bool pardefaut)
        {
            CategoryDao categoryDao = new CategoryDao();

            //On ajoute
            BECategory category = null;

            try
            {
                category = categoryDao.AjouterCategory(id, nom, pardefaut);
                if (category == null)
                {
                    throw new Exception("La categorie est null.");
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Une erreur est survenue lors de l'ajout de la catégorie", ex);
            }

            return(category);
        }
Ejemplo n.º 14
0
        public BETache modifierTache(int id, string nom, string detail, DateTime debut, DateTime fin, int idUser, List <BECategory> categories, BEEtat statement)
        {
            //Contrôle
            if (string.IsNullOrWhiteSpace(nom))
            {
                throw new ArgumentException("Veuillez renseigner le nom de la tache.", "nom");
            }
            if (string.IsNullOrWhiteSpace(detail))
            {
                throw new ArgumentException("Veuillez renseigner le detail de la tache.", "detail");
            }
            if (fin < debut)
            {
                throw new ArgumentException("Veuillez renseigner une date de fin valide.", "fin");
            }

            //Enregistrement
            using (TodoListUCBLEntities context = new TodoListUCBLEntities())
            {
                Tache t = context.TacheSet.Include("Categories").Include("Utilisateur").Include("Etat").FirstOrDefault(p => p.Id == id);
                //Contrôle de modification
                if (nom != t.Nom)
                {
                    t.Nom = nom;
                }
                if (detail != t.Detail)
                {
                    t.Detail = detail;
                }
                if (debut != t.Debut)
                {
                    t.Debut = debut;
                }
                if (fin != t.Fin)
                {
                    t.Fin = fin;
                }

                t.Etat = context.EtatSet.First(e => e.Id == statement.Id);

                //On supprime les liens entre la tache et ses categories
                foreach (Category c in t.Categories)
                {
                    c.Taches.Remove(t);
                }
                t.Categories.Clear();

                //On recréer les liens avec les nouvelles catégories
                foreach (BECategory c in categories)
                {
                    t.Categories.Add(context.CategorySet.First(cat => cat.Id == c.Id));
                    Category categ = context.CategorySet.First(cat => cat.Id == c.Id);
                    categ.Taches.Add(t);
                }

                if (categories.Count() == 0)
                {
                    List <Category> cat = context.CategorySet.Where(c => c.ParDefaut == true).ToList();
                    foreach (Category tmp in cat)
                    {
                        t.Categories.Add(tmp);
                        tmp.Taches.Add(t);
                    }
                }

                context.SaveChanges();

                BETache retour = new BETache();
                retour.Id     = t.Id;
                retour.Nom    = t.Nom;
                retour.Debut  = t.Debut;
                retour.Fin    = t.Fin;
                retour.Detail = t.Detail;

                foreach (Category cat in t.Categories)
                {
                    BECategory categ = new BECategory();
                    categ.Id        = cat.Id;
                    categ.Nom       = cat.Nom;
                    categ.ParDefaut = cat.ParDefaut;

                    retour.Categories.Add(categ);
                }

                BEEtat etat = new BEEtat();
                etat.Id      = t.Etat.Id;
                etat.Libelle = t.Etat.Libelle;
                etat.Code    = t.Etat.Code;

                retour.Etat = etat;

                BEUtilisateur user = new BEUtilisateur();
                user.Id       = t.Utilisateur.Id;
                user.Login    = t.Utilisateur.Login;
                user.Nom      = t.Utilisateur.Nom;
                user.Password = t.Utilisateur.Password;
                user.Prenom   = t.Utilisateur.Prenom;
                user.Email    = t.Utilisateur.Email;

                retour.Utilisateur = user;

                return(retour);
            }
        }
Ejemplo n.º 15
0
        public BETache AjouterTache(int idUser, string nom, System.DateTime debut, System.DateTime fin, string detail, List <BECategory> categories)
        {
            //Contrôle
            if (string.IsNullOrWhiteSpace(nom))
            {
                throw new ArgumentException("Veuillez renseigner le nom de la tache.", "nom");
            }
            if (string.IsNullOrWhiteSpace(detail))
            {
                throw new ArgumentException("Veuillez renseigner le detail de la tache.", "detail");
            }
            if (fin < debut)
            {
                throw new ArgumentException("Veuillez renseigner une date de fin valide.", "fin");
            }

            //Enregistrement

            using (TodoListUCBLEntities context = new TodoListUCBLEntities())
            {
                Tache t = new Tache();
                t.Nom         = nom;
                t.Debut       = debut;
                t.Fin         = fin;
                t.Detail      = detail;
                t.Etat        = context.EtatSet.First(c => c.Libelle == "Créée");
                t.Utilisateur = context.UtilisateurSet.First(u => u.Id == idUser);

                foreach (BECategory cat in categories)
                {
                    t.Categories.Add(context.CategorySet.First(c => c.Id == cat.Id));
                    Category categ = context.CategorySet.First(cc => cc.Id == cat.Id);
                    categ.Taches.Add(t);
                }

                if (categories.Count() == 0)
                {
                    List <Category> cat = context.CategorySet.Where(c => c.ParDefaut == true).ToList();
                    foreach (Category tmp in cat)
                    {
                        t.Categories.Add(tmp);
                        tmp.Taches.Add(t);
                    }
                }

                context.TacheSet.Add(t);
                context.SaveChanges();

                //On retourne la tache

                BETache retour = new BETache();

                retour.Id     = t.Id;
                retour.Nom    = t.Nom;
                retour.Debut  = t.Debut;
                retour.Fin    = t.Fin;
                retour.Detail = t.Detail;

                BEEtat etat = new BEEtat();
                etat.Id      = t.Etat.Id;
                etat.Libelle = t.Etat.Libelle;
                etat.Code    = t.Etat.Code;

                retour.Etat = etat;

                foreach (Category cat in t.Categories)
                {
                    BECategory categ = new BECategory();
                    categ.Id        = cat.Id;
                    categ.Nom       = cat.Nom;
                    categ.ParDefaut = cat.ParDefaut;
                    retour.Categories.Add(categ);
                }

                BEUtilisateur user = new BEUtilisateur();

                user.Email    = t.Utilisateur.Email;
                user.Id       = t.Utilisateur.Id;
                user.Login    = t.Utilisateur.Login;
                user.Password = t.Utilisateur.Password;
                user.Prenom   = t.Utilisateur.Prenom;
                user.Nom      = t.Utilisateur.Nom;

                retour.Utilisateur = user;

                return(retour);
            }
        }