public string SaveForm(Blankett b1) { KrimmDBEntities2 db = new KrimmDBEntities2(); string username = CreateAccount(b1); if (!username.Equals("Error")) { Form form = new Form(); int id = db.Users.Where(s => s.Username == username).Select(s => s.UserId).FirstOrDefault(); form.User = id; form.Email = b1.EMail; form.VisitorFName = b1.VisitorFName; form.VisitorLName = b1.VisitorLName; form.Status = "Pending"; form.Phonenumber = b1.PhoneNumber; form.PersonOfInterest = b1.InmateSSN; db.Form.Add(form); db.SaveChanges(); string pass = db.Users.Where(s => s.Username == username).Select(s => s.Password).FirstOrDefault(); return("Blanketten är mottagen. Du har fått ett konto med" + " användarnamn: " + username + " och lösenord: " + pass + " Skriv ner dina uppgifter"); } else { return("Error"); } }
public string CreateAccount(Blankett b1) { bool b = true; while (b) { Random rnd = new Random(); KrimmDBEntities2 db = new KrimmDBEntities2(); int username = rnd.Next(0000000, 99999999); string sUsername = username.ToString(); string password = rnd.Next(0000000, 99999999).ToString(); string result = db.Users.Where(u => u.Username == sUsername).Select(u => u.Username).FirstOrDefault(); if (result != sUsername) { var inmateSSN = db.Inmates.Where(i => i.InmateSSN == b1.InmateSSN).Select(i => i.InmateSSN); int intInmateSSN = (int)inmateSSN.FirstOrDefault(); if (intInmateSSN == b1.InmateSSN) { int admin = 0; Users create = new Users(); create.Username = sUsername; create.Password = password; create.PersonOfInterest = intInmateSSN; create.Admin = admin; db.Users.Add(create); db.SaveChanges(); b = false; return(sUsername); } else { b = false; return("Error"); } } else { b = true; //FORTSÄTT LOOP TILLS KONTO SKAPAS } } return("Error"); }
public void ChangeStatusForm(Blankett b1, string newStatus) { b1.Status = newStatus; KrimmDBEntities2 db = new KrimmDBEntities2(); int result = db.Form.Where(f => f.FormId == b1.FormId).Select(f => f.FormId).FirstOrDefault(); if (result == b1.FormId) { Form updateStatus = db.Form.Single(s => s.FormId == b1.FormId); updateStatus.Status = b1.Status; db.SaveChanges(); } //Save db; //0 = Declined //1 = Accepted //2 = Pending }
public Blankett GetFormWithId(int formId) { KrimmDBEntities2 db = new KrimmDBEntities2(); Blankett blank = new Blankett(); blank.FormId = formId; blank.InmateSSN = db.Form.Where(s => s.FormId == formId).Select(s => s.PersonOfInterest).FirstOrDefault(); blank.VisitorFName = db.Form.Where(s => s.FormId == formId).Select(s => s.VisitorFName).FirstOrDefault(); blank.VisitorLName = db.Form.Where(s => s.FormId == formId).Select(s => s.VisitorLName).FirstOrDefault(); int inmateID = db.Form.Where(s => s.FormId == formId).Select(s => s.PersonOfInterest).FirstOrDefault(); blank.PersonOfInterestFName = db.Inmates.Where(s => s.InmateSSN == inmateID).Select(s => s.Firstname).FirstOrDefault(); blank.PersonOfInterestLName = db.Inmates.Where(s => s.InmateSSN == inmateID).Select(s => s.Surname).FirstOrDefault(); blank.PhoneNumber = db.Form.Where(s => s.FormId == formId).Select(s => s.Phonenumber).FirstOrDefault(); blank.EMail = db.Form.Where(s => s.FormId == formId).Select(s => s.Email).FirstOrDefault(); blank.Status = db.Form.Where(s => s.FormId == formId).Select(s => s.Status).FirstOrDefault(); return(blank); }
public Blankett GetDataUsingDataContract(Blankett b1) { return(b1); }
public void UpdateForm(Blankett b1) { //casesatts med int inparameter i framtiden throw new NotImplementedException(); }