Exemplo n.º 1
0
        public static bool Create(T_Notification notification, T_User user, T_Event myevent)
        {
            using (ConcertFinderEntities bdd = new ConcertFinderEntities())
            {
                try
                {
                    T_Event a_event = bdd.T_Event.Where(x => x.Id == myevent.Id).FirstOrDefault();
                    T_User a_user = bdd.T_User.Where(x => x.Id == user.Id).FirstOrDefault();

                    bdd.Attach(a_event);
                    bdd.Attach(a_user);

                    notification.T_Event.Add(a_event);
                    notification.T_User.Add(a_user);

                    bdd.T_Notification.AddObject(notification);
                    bdd.SaveChanges();
                }
                catch (Exception)
                {
                    throw;
                   
                }
            }
            return true;
        }
Exemplo n.º 2
0
 public static bool Create(T_Tag tag)
 {
     using (ConcertFinderEntities bdd = new ConcertFinderEntities())
     {
         try
         {
             bdd.AddToT_Tag(tag);
             bdd.SaveChanges();
         }
         catch (Exception)
         {
             return false;
         }
     }
     return true;
 }
Exemplo n.º 3
0
 static public bool Delete(long id)
 {
     using (ConcertFinderEntities bdd = new ConcertFinderEntities())
     {
         try
         {
             bdd.DeleteObject(bdd.T_Location.Where(x => x.Id == id).FirstOrDefault());
             bdd.SaveChanges();
         }
         catch (Exception)
         {
             return false;
         }
     }
     return true;
 }
Exemplo n.º 4
0
 static public bool Update(T_Tag tag)
 {
     using (ConcertFinderEntities bdd = new ConcertFinderEntities())
     {
         try
         {
             var n_tag = new T_Tag { Id = tag.Id };
             bdd.T_Tag.Attach(n_tag);
             bdd.ApplyCurrentValues("T_Tag", tag);
             bdd.SaveChanges();
         }
         catch (Exception)
         {
             return false;
         }
     }
     return true;
 }
Exemplo n.º 5
0
 static public bool Update(T_Location location)
 {
     using (ConcertFinderEntities bdd = new ConcertFinderEntities())
     {
         try
         {
             var n_location = new T_Location { Id = location.Id };
             bdd.T_Location.Attach(n_location);
             bdd.ApplyCurrentValues("T_Location", location);
             bdd.SaveChanges();
         }
         catch (Exception)
         {
             return false;
         }
     }
     return true;
 }
Exemplo n.º 6
0
 public static Boolean Update(T_User upUser)
 {
     using (ConcertFinderEntities bdd = new ConcertFinderEntities ())
     {
         try
         {
             var user = new T_User { Id = upUser.Id };
             bdd.T_User.Attach(user);
             bdd.ApplyCurrentValues("T_User", upUser);
             bdd.SaveChanges();
         }
         catch (Exception)
         {
             throw;
         }
         return true;
     }
 }
Exemplo n.º 7
0
 public static List<DataAccess.T_Notification> Get(string pseudo)
 {
     List<DataAccess.T_Notification> notifs = new List<T_Notification>();
     using (ConcertFinderEntities bdd = new ConcertFinderEntities())
     {
         try
         {
             notifs = bdd.T_Notification.Include("T_User").Include("T_Event").ToList().Where(x => x.T_User.FirstOrDefault().Pseudo == pseudo).OrderByDescending(x => x.Date).Take(6).ToList();
             foreach (T_Notification notif in bdd.T_Notification.Include("T_User").ToList().Where(x => x.T_User.FirstOrDefault().Pseudo == pseudo && x.Check == false).ToList())
             {
                 notif.Check = true;
             }
             bdd.SaveChanges();
         }
         catch (Exception)
         {
             throw;
         }
     }
     return notifs;
 }
Exemplo n.º 8
0
        public static bool Create(T_Notification notification, long id)
        {
            using (ConcertFinderEntities bdd = new ConcertFinderEntities())
            {
                try
                {
                    T_User user = bdd.T_User.Where(x => x.Id == id).FirstOrDefault();
                    bdd.Attach(user);
                    notification.T_User.Add(user);

                    bdd.AddToT_Notification(notification);
                    bdd.SaveChanges();
                }
                catch (Exception)
                {
                    throw;

                }
            }
            return true;
        }
Exemplo n.º 9
0
        public static Boolean Delete(long idUser)
        {
            using (ConcertFinderEntities bdd = new ConcertFinderEntities())
            {
                try
                {
                    T_User user = bdd.T_User.Where(u => u.Id == idUser).FirstOrDefault();

                    user.Role = "deactivated";

                    bdd.AddToT_User(user);
                    bdd.SaveChanges();
                }
                catch (Exception)
                {
                    return false;
                }

                return true;
            }
        }
Exemplo n.º 10
0
 public static Boolean Create(T_User user, List<T_Tag> tags)
 {
     using (ConcertFinderEntities bdd = new ConcertFinderEntities())
     {
         try
         {
             foreach (T_Tag tag in tags)
             {
                 bdd.Attach(tag);
                 user.T_Tag.Add(tag);
             }
             bdd.AddToT_User(user);
             bdd.SaveChanges();
         }
         catch (Exception)
         {
             throw;
            
         }
         return (true);
     }
 }
Exemplo n.º 11
0
 public static bool Deny(T_Notification notif, long idEvent)
 {
     using (ConcertFinderEntities bdd = new ConcertFinderEntities())
     {
         try
         {
             T_Event myevent = bdd.T_Event.Include("T_User").Where(x => x.Id == idEvent).FirstOrDefault();
             notif.T_Event.Add(myevent);
             notif.T_User.Add(myevent.T_User);
             bdd.AddToT_Notification(notif);
             bdd.SaveChanges();
             return true;
         }
         catch (Exception)
         {
             throw;
             return false;
         }
     }
 }
Exemplo n.º 12
0
        public static Boolean Update(string pseudo, Models.ParameterModel form)
        {
            using (ConcertFinderEntities bdd = new ConcertFinderEntities())
            {
                try
                {

                    SimpleAES encryptor = new SimpleAES();
            
                    T_User user = bdd.T_User.Include("T_Tag").Include("T_Event").Where(x => x.Pseudo == pseudo).FirstOrDefault();

                    if (user.Ville != form.MyCity && form.MyCity != null)
                    {
                        user.Ville = form.MyCity;
                    }

                    if ((form.NewPassword != null) && (form.OldPassword != null) && (form.ConfirmPassword != null))
                    {
                        if (User.ValidateUser(pseudo, encryptor.EncryptToString(form.OldPassword)) && encryptor.EncryptToString(form.NewPassword) != user.Password)
                        {
                            user.Password = encryptor.EncryptToString(form.NewPassword);
                        }
                    }

                    if (user.Mail != form.Email && (form.Email != null))
                    {
                        user.Mail = form.Email;
                    }

                    List<DataAccess.T_Tag> listTag = new List<DataAccess.T_Tag>();
                    if (form.Tag != null)
                    {
                        
                        string[] split = form.Tag.Split(new Char[] { ' ', ',', '.', ';' });
                        foreach (string str in split)
                        {
                            if (str.Length > 2)
                            {
                                Regex r = new Regex("[a-z1-9*]");
                                Match m = r.Match(str);
                                if (m.Success)
                                {
                                    str.ToLower();
                                    DataAccess.T_Tag tag = new DataAccess.T_Tag()
                                    {
                                        Name = str
                                    };
                                    if (bdd.T_Tag.Where(t => t.Name == tag.Name).FirstOrDefault() == null)
                                    {
                                        DataAccess.Tag.Create(tag);
                                    }

                                    tag = bdd.T_Tag.Where(t => t.Name == tag.Name).FirstOrDefault();


                                    listTag.Add(tag);

                                }
                            }
                        }
                    }

                    
                    user.T_Tag.Clear();
                    foreach (T_Tag tag in listTag)
                    {
                        bdd.Attach(tag);
                        user.T_Tag.Add(tag);
                    }

                    var uuser = new T_User { Id = user.Id };
                   
                    bdd.ApplyCurrentValues("T_User", user);
                    bdd.SaveChanges();
                }
                catch (System.Data.UpdateException ex)
                {
                    throw;
                }
                return true;
            }
        }