public void DeleteUser(User user) { if (user.Id == 0) return; user.FirstName = "DeletedUser" + user.Id.ToString(); user.LastName = null; user.Institute = null; user.Password = Encryption.EncryptPassword(DateTime.Now.ToString()); var perm = new Permission {Id = 1}; user.Permission = perm; user.PermissionPermissionId = perm.Id; user.Picture = null; user.PhoneNumber = null; user.Email = null; using (var db = new TSPDSContext()) { db.Entry(user).State = EntityState.Modified; db.User.AddOrUpdate(user); db.SaveChanges(); } }
private void ValidateUser(User user) { if (user.Email == null) throw new DALInfoNotSpecifiedException("User email was not specified"); if (user.Password == null) throw new DALInfoNotSpecifiedException("User password was not specified"); if (user.FirstName == null) throw new DALInfoNotSpecifiedException("User Firstname was not specified"); if (user.LastName == null) throw new DALInfoNotSpecifiedException("User Lastname was not specified"); }
private void InsertRevision(Dataset dataset, Revision rev, User user, Revision prevRevision = null) { using (var db = new TSPDSContext()) { if (user.Id == 0) throw new DALInfoNotSpecifiedException("User id was not specified"); if (dataset.Id == 0) throw new DALInfoNotSpecifiedException("Dataset id was not specified"); if (rev.Id != 0) rev.Id = 0; ValidateUser(user); var query = from b in db.Revision where b.Dataset.Id == dataset.Id select b; if (query.Any()) throw new DALAlreadyExistsException("Dataset already exists"); rev.User = user; rev.Dataset = dataset; rev.UserUserId = user.Id; rev.Dataset_Id = dataset.Id; if (prevRevision != null) { if (prevRevision.Id == 0) throw new DALInfoNotSpecifiedException("Previous revision was not null, but the id was not specified"); prevRevision.HeadRevision = rev; prevRevision.HeadRevision_Id = rev.Id; rev.HeadRevision_Id = prevRevision.Id; db.Entry(prevRevision).State = EntityState.Modified; } db.Entry(dataset).State = EntityState.Modified; db.Entry(user).State = EntityState.Modified;; db.Revision.Add(rev); db.SaveChanges(); } }
public void UpdateUserPermission(User user, Permission perm) { ValidateUser(user); ValidatePermission(perm); if (perm == null) throw new DALInfoNotSpecifiedException("User permission was not specified"); if (perm.Id == 0) throw new DALInfoNotSpecifiedException("Permission id was not speciified"); if (user.Id == 0) throw new DALInfoNotSpecifiedException("User id was not speciified"); var param = new ParametersForUsers(); param.Email = user.Email; var temp = GetUsers(param)[0]; if (temp.Email != user.Email) { throw new DALInfoNotSpecifiedException("The user was not found in the databse"); } using (var db = new TSPDSContext()) { user.Permission = perm; user.PermissionPermissionId = perm.Id; db.User.AddOrUpdate(user); db.SaveChanges(); } }
public void InsertUser(User user, Permission perm) { ValidateUser(user); ValidatePermission(perm); using (var db = new TSPDSContext()) { var query = from s in db.User where s.Email.ToLower() == user.Email.ToLower() select s; if (query.Any()) throw new DALAlreadyExistsException("User already exists"); user.Permission = perm; user.PermissionPermissionId = perm.Id; db.Entry(user).State = EntityState.Modified; db.User.Add(user); db.SaveChanges(); } }
public void InsertDataset(List<DataPoint> dataPoints, TargetMaterial impactMaterial, Projectile projectile, Dataformat orginalDataformat, Dataformat converteDataformat, Revision rev, User user, Revision prevRevision = null, ArticleReferences AR = null, Method method = null, StateOfAggregation stateOfAggregation = null) { if (impactMaterial.Id == 0) throw new DALInfoNotSpecifiedException("impactmaterial id was not specified"); if (projectile.Id == 0) throw new DALInfoNotSpecifiedException("Projectile id was not specified"); if (AR != null) { if (AR.Id == 0) throw new DALInfoNotSpecifiedException("ArtivleReference id was not specified"); } if (method != null) { if (method.Id == 0) throw new DALInfoNotSpecifiedException("Method id was not specified"); } if (stateOfAggregation != null) { if (stateOfAggregation.Id == 0) { throw new DALInfoNotSpecifiedException("State Of Aggregation Id was not specified"); } } foreach (var item in dataPoints) { if (item.ConvertetData == null) { throw new DALInfoNotSpecifiedException( "One or more DataPoints had unspecificed converted data"); } if (item.EqEnergy == null) { throw new DALInfoNotSpecifiedException("One or more DataPoints had unspecificed eqEnergy"); } if (item.StoppingPower == null) { throw new DALInfoNotSpecifiedException("One or more DataPoints had unspecificed StoppingPower"); } } var tempCollection = new List<ArticleReferences>(); tempCollection.Add(AR); var dataset = new Dataset() { Projectile_Id = projectile.Id, TargetMaterial_Id = impactMaterial.Id, ArticleReferences = AR, Projectile = projectile, Method = method, StateOfAggregation = stateOfAggregation, TargetMaterial = impactMaterial, }; if (AR != null) dataset.ArticleReferences_Id = AR.Id; if (method != null) dataset.Method_Id = method.Id; if (stateOfAggregation != null) dataset.StateOfAggregation_Id = stateOfAggregation.Id; using (var db = new TSPDSContext()) { db.Entry(dataset).State = EntityState.Modified; db.Dataset.Add(dataset); db.SaveChanges(); } InsertDataPoint(dataPoints, dataset, orginalDataformat, converteDataformat); InsertRevision(dataset, rev, user, prevRevision); }
/// <summary> /// Method creates user and inserts it into database /// </summary> /// <param name="email">User email</param> /// <param name="confirmEmail">user email confirmed</param> /// <param name="Pass">user password</param> /// <param name="confirmPass">user password confirmed</param> /// <param name="fName">user first name</param> /// <param name="lName">user last name</param> public bool Create(string email, string confirmEmail, string pass, string confirmPass, string fName, string lName) { if (_confirmPass != _Pass) { return false; } try { IDalUserManagement dalUserManage = new MSSQLModelDAL(); ParametersForUsers parameters = new ParametersForUsers() { Email = email }; if (dalUserManage.GetUsers(parameters).Any()) { return false; } User user = new User() { Email = email, FirstName = fName, LastName = lName, Password = pass }; Permission perm = dalUserManage.GetPermByAccessLevel(AccessLevel.Submitter); dalUserManage.InsertUser(user, perm); return true; } catch (NullReferenceException e) { return false; } }