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; }
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; }
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); } }
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; } }