public bool SubmitNewGame(string title, string filepath, int sizekb, DateTime submissiondate, int price, string genre, string submittername) { try { ArchiveDatabaseContext ArchiveContext = new ArchiveDatabaseContext(); SubmitterAccount submitter = ArchiveContext.Submitters.Where(s => s.UserName == submittername).FirstOrDefault(); Game g = new Game(); g.Title = title; g.FilePath = @"Archive\" + submittername + @"\" + filepath.Split('\\').Last(); g.SizeKB = sizekb; g.SubmissionDate = submissiondate; g.Price = price; g.Genre = genre; g.Submitter = submitter; g.SubmitterID = submitter.AccountID; ArchiveContext.Games.Add(g); ArchiveContext.SaveChanges(); var rootPath = Directory.GetCurrentDirectory(); if (File.Exists(rootPath + @"\Archive\" + submittername)) { File.Move(filepath, rootPath + @"\Archive\" + submittername + @"\" + filepath.Split('\\').Last()); } return(true); } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); return(false); } }
//Accounts public bool CreateAccount(string _username, string _password, int _accountType) { using (ArchiveDatabaseContext dbContext = new ArchiveDatabaseContext()) { try { var account = dbContext.Accounts.Where(a => a.UserName == _username).FirstOrDefault(); if (account != null) { MessageBox.Show("Username taken!"); return(false); } Account acc = new Account(); if (_accountType == -1) { throw new Exception("Error unexpected Account Type"); } //set acc to proper account type if (_accountType == 1) { acc = new CustomerAccount(); } if (_accountType == 2) { acc = new SubmitterAccount(); } //fill in account type independent data acc.AccountCreated = DateTime.Now; var saltedPassword = _password + Helper.GetEncryptionKey(acc.AccountCreated.Day); HMACSHA256 hashed = new HMACSHA256(Helper.GetEncryptionKey()); acc.PasswordHash = Convert.ToBase64String(hashed.ComputeHash(Encoding.Unicode.GetBytes(saltedPassword))); acc.UserName = _username; //add acc to proper table if (_accountType == 1) { dbContext.Customers.Add((CustomerAccount)acc); } if (_accountType == 2) { dbContext.Submitters.Add((SubmitterAccount)acc); } dbContext.SaveChanges(); return(true); } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } } return(false); }
public SubmitterAccount GetSubmitterAccountByName(string _username) { try { using (ArchiveDatabaseContext dbContext = new ArchiveDatabaseContext()) { SubmitterAccount acc = dbContext.Submitters.Where(a => a.UserName == _username).FirstOrDefault(); if (acc != null) { return(acc); } else { MessageBox.Show("Error: Account missing with Username: "******"Error: " + ex.Message); } return(null); }
public SubmitterArchive(SubmitterAccount _archiveSubmitter, string root) : base(root) //in this case submitter directory should be used as root { ArchiveSubmitter = _archiveSubmitter; }
public SubmitterArchive(SubmitterAccount _archiveSubmitter) : base() { ArchiveSubmitter = _archiveSubmitter; }