public static Boolean create(RegisterModel form) { string role = ""; if (form.Pseudo.Equals("superadmin")) { role = UserModel.GetRoleType((int)eRole.Admin); } else { role = UserModel.GetRoleType((int)eRole.User); } SimpleAES encryptor = new SimpleAES(); DataAccess.T_User user = new DataAccess.T_User() { Name = form.Name, Firstname = form.Firstname, Pseudo = form.Pseudo, Mail = form.Email, Ville = form.City, Password = encryptor.EncryptToString(form.Password), Role = role, Deleted = false, T_Event = null, T_Notification = null, T_Tag = null }; List<DataAccess.T_Tag> listTag = new List<DataAccess.T_Tag>(); if (form.Tags != null && form.Tags != "") { string[] split = form.Tags.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 (DataAccess.Tag.Get(str) == null) { DataAccess.Tag.Create(tag); } tag = DataAccess.Tag.Get(str); listTag.Add(tag); } } } } return DataAccess.User.Create(user, listTag); }
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; } }