public ActionResult Create([Bind(Include = "userID,firstName,lastName,email,userType")] user user) { this.userEmail = User.Identity.GetUserName(); bool isAdministrator = false; foreach (user u in db.users) { if (u.email == this.userEmail) { if (u.userType == 2) { isAdministrator = true; } } } if (isAdministrator == false) { return(View("NotAuthorized")); } if (ModelState.IsValid) { db.users.Add(user); var maxValue = db.users.Max(u => u.userID); user.userID = maxValue + 1; db.SaveChanges(); db.users.ToList(); return(RedirectToAction("tickets/Index")); } return(View(user)); }
public ActionResult Create([Bind(Include = "ticketID,userID,date,description,status,type")] ticket ticket) { if (ModelState.IsValid) { this.userEmail = User.Identity.GetUserName(); //Gets the current highest value of any ticketID. var maxValue = db.tickets.Max(t => t.ticketID); //Sets the ticketID of the new ticket to 1 + the current highest ticketId. So as new tickets are created, they always //have an ID one higher than the last one. You can see this when you run the program and look at ticket details. ticket.ticketID = maxValue + 1; ticket.userID = (from users in db.users where users.email == this.userEmail select users.userID).Single(); //ticket.user.firstName = fName; //ticket.user.lastName = this.lName; //Sets the ticket's status to 1 (unopen). I will be changing this to display words rather than numbers soon. ticket.status = Status.UnOpen; //The rest of the values are the values the user enters on the create ticket page. This next line adds this new ticket to the DB. ticket.date = DateTime.Now.ToShortDateString(); ViewBag.email = this.userEmail; db.tickets.Add(ticket); db.SaveChanges(); //Takes us back to tickets/Index. return(RedirectToAction("Index")); } ViewBag.userID = new SelectList(db.users, "userID", "firstName", ticket.userID); return(View(ticket)); }
public ActionResult Create([Bind(Include = "IDBraider,FnameBraider,MnameBraider,LnameBraider,PhoneBraider,CelBraider,StreetBraider,CountyBraider,ZipCodeBraider,EmailBraider,IDUserBraider")] BRAIDER bRAIDER) { if (ModelState.IsValid) { db.BRAIDERs.Add(bRAIDER); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(bRAIDER)); }
public ActionResult Create([Bind(Include = "IDComp,TitleComp,PhoneOffice,PhoneOwner,StreetComp,CountyComp,ZipcodeComp,EmailComp,WebsiteComp,PartPayeBraid,IDOwnerBraider,CostHairDeduct,PercentBrader,PriceTakeOff")] COMPANY cOMPANY) { if (ModelState.IsValid) { db.COMPANies.Add(cOMPANY); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(cOMPANY)); }
public ActionResult Create([Bind(Include = "IDAppoint,IDClientAppoint,IDStypeAppoint,DateAppoint,AddTakeOffAppoint,BeginnTimeAppoint")] APPOINTMENT aPPOINTMENT) { if (ModelState.IsValid) { db.APPOINTMENTs.Add(aPPOINTMENT); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.IDClientAppoint = new SelectList(db.CLIENTs, "IDClient", "FnameClient", aPPOINTMENT.IDClientAppoint); ViewBag.IDStypeAppoint = new SelectList(db.STYLEs, "IDStyle", "DesigStyle", aPPOINTMENT.IDStypeAppoint); return(View(aPPOINTMENT)); }
public ActionResult Create([Bind(Include = "IDClient,FnameClient,MnameClient,LnameClient,PhoneClient,CelClient,StreetClient,CountyClient,ZipCodeClient,EmailClient,IDUserClient,StateClient")] CLIENT cLIENT) { //There needs to be a way to get the UserID from the user table for IDUserClient attribute //this doesn't have a value for it so you get an error if (ModelState.IsValid) { String email = User.Identity.Name; cLIENT.EmailClient = email; var UserID = from u in db.AspNetUsers where u.UserName.Equals(email) select u.Id as string; //System.Data.Entity.Infrastructure.DbRawSqlQuery UserID = Database.SqlQuery("SELECT Id FROM dbo.AspNetUsers WHERE Email = @p0", email); //String uID = UserID.ToString(); var query = db.AspNetUsers.Where(x => x.UserName == email).First(); String uID = query.Id; cLIENT.IDUserClient = uID; db.CLIENTs.Add(cLIENT); try { // Your code... // Could also be before try if you know the exception occurs in SaveChanges db.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { System.Diagnostics.Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } return(RedirectToAction("Index")); } return(View(cLIENT)); }
public ActionResult Create([Bind(Include = "IDClient,FnameClient,MnameClient,LnameClient,PhoneClient,CelClient,StreetClient,CountyClient,ZipCodeClient,EmailClient,IDUserClient,StateClient")] CLIENT cLIENT) { //There needs to be a way to get the UserID from the user table for IDUserClient attribute //this doesn't have a value for it so you get an error if (ModelState.IsValid) { String email = User.Identity.Name; cLIENT.EmailClient = email; var query = db.AspNetUsers.Where(x => x.UserName == email).First(); String uID = query.Id; cLIENT.IDUserClient = uID; db.CLIENTs.Add(cLIENT); /*try * { * // Your code... * // Could also be before try if you know the exception occurs in SaveChanges */ db.SaveChanges(); /*} * catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) * { * foreach (var validationErrors in dbEx.EntityValidationErrors) * { * foreach (var validationError in validationErrors.ValidationErrors) * { * System.Diagnostics.Trace.TraceInformation("Property: {0} Error: {1}", * validationError.PropertyName, * validationError.ErrorMessage); * } * } * }*/ return(RedirectToAction("Index")); } return(View(cLIENT)); }