public ActionResult Create(Meeting meeting) { //TODO: check for permissions //set created datetime to current datetime meeting.CreatedDate = DateTime.Now; //make sure no duplicate meeting exists. if (db.Meeting.Find(meeting.Comm_CommOwn_ID, meeting.Comm_ID, meeting.DateTime) != null) { ModelState.AddModelError("DateTime", "A meeting already exists at this date and time"); } else { //if data is valid save and return to meeting parent if (ModelState.IsValid) { db.Meeting.Add(meeting); db.SaveChanges(); return(RedirectToAction("Details", "Meetings", new { primaryKey1 = meeting.Comm_CommOwn_ID, primaryKey2 = meeting.Comm_ID, primaryKey3 = meeting.DateTime.ToString("MM-dd-yyyy h.mm.ss t\\M") })); } } //data is invalid so we return to the create page ViewBag.CommitteeName = db.Comm.Find(meeting.Comm_CommOwn_ID, meeting.Comm_ID).Name; //send committee name back name for view to display return(View(meeting)); }
public ActionResult Create(Comm comm, string txtCharge, string txtConstitution) { if (!db.CommSuperAdmin.Any(csa => csa.SysUser_Email == User.Identity.Name && csa.StartDate <= DateTime.Today && (csa.EndDate ?? DateTime.MaxValue) >= DateTime.Today && csa.CommOwn_ID == comm.CommOwn_ID)) { return(RedirectToAction("login", "account", null)); } //make sure an active committee with the same name doesn't exist for this division already. if (db.Comm.Any(c => c.Name == comm.Name && c.CommOwn_ID == comm.CommOwn_ID && c.IsArchived == "N")) { ModelState.AddModelError("Name", "An active committee with this name already exists for this division"); return(View(comm)); } comm.CreatedDate = DateTime.Now; comm.CreatedBy = User.Identity.Name; comm.IsArchived = "N"; CommCharge commCharge = new CommCharge(); CommConstitution commCon = new CommConstitution(); if (ModelState.IsValid) { //save new committee so we can get the new autonumber for comm.ID db.Comm.Add(comm); db.SaveChanges(); // Start adding Committees Charges into the database commCharge.Comm_CommOwn_ID = comm.CommOwn_ID; commCharge.Comm_ID = comm.ID; commCharge.Charges = txtCharge; commCharge.CreatedBy = User.Identity.Name; commCharge.CreatedDate = DateTime.Now.Date; commCharge.EffectiveDate = comm.EffectiveDate; db.CommCharge.Add(commCharge); // Finish adding Committees Charges into the database // Start adding Committees Constitution into the database commCon.Comm_CommOwn_ID = comm.CommOwn_ID; commCon.Comm_ID = comm.ID; commCon.Constitution = txtConstitution; commCon.EffectiveDate = comm.EffectiveDate; commCon.CreatedDate = DateTime.Now.Date; commCon.CreatedBy = User.Identity.Name; db.CommConstitution.Add(commCon); // Finish adding Committees Constitution into the database db.SaveChanges(); //AuditLogController.Add("Add", User.Identity.Name, "New committee name: " + comm.Name + " is added"); //Not needed since created by/date is maintained by comm return(RedirectToAction("details", "committees", new { primaryKey1 = comm.CommOwn_ID, primaryKey2 = comm.ID })); } return(View(comm)); }
public ActionResult Create(CommDocument commdocument) { commdocument.UploadedDate = DateTime.Now; HttpPostedFileBase file = Request.Files["myFile"]; //make sure no duplicate document exists. if (db.CommDocument.Find(commdocument.Comm_CommOwn_ID, commdocument.Comm_ID, commdocument.Title) != null) { ModelState.AddModelError("Title", "A document already exists with this title."); ViewBag.Category = new SelectList(db.Category, "Type", "Description", commdocument.Category); return(View(commdocument)); } else if (file.ContentLength > 0) // checks if file was uploaded to the form { // set protected to no if public, protected to yes if not public if (commdocument.IsPublic == "Y") { commdocument.IsProtected = "N"; } else if (commdocument.IsPublic == "N") { commdocument.IsProtected = "Y"; } // getting size of file int fileLen = file.ContentLength; // create write buffer byte[] byteFile = new byte[fileLen]; file.InputStream.Read(byteFile, 0, fileLen); // write file to commdocument commdocument.FileImage = byteFile; commdocument.Filename = file.FileName; commdocument.ContentType = file.ContentType; if (ModelState.IsValid) { db.CommDocument.Add(commdocument); db.SaveChanges(); return(RedirectToAction("Details", "Committees", new { primaryKey1 = commdocument.Comm_CommOwn_ID, primaryKey2 = commdocument.Comm_ID })); } ViewBag.Category = new SelectList(db.Category, "Type", "Description", commdocument.Category); return(View(commdocument)); } // No file ViewBag.Category = new SelectList(db.Category, "Type", "Description", commdocument.Category); ModelState.AddModelError("FileImage", "Select a file to upload"); return(View(commdocument)); }
public ActionResult Create(int primaryKey1, int primaryKey2, CommMember commmember) { ViewBag.Comm_CommOwn_ID = primaryKey1; ViewBag.Comm_ID = primaryKey2; Comm comm = db.Comm.Find(primaryKey1, primaryKey2); ViewBag.CommName = comm.Name; //Set Variables commmember.Comm_CommOwn_ID = primaryKey1; commmember.Comm_ID = primaryKey2; commmember.LastAssignedBy = User.Identity.Name; commmember.LastAssignedDate = DateTime.Now; commmember.StartDate = commmember.StartDate.Date; commmember.EndDate = commmember.EndDate.Date; commmember.Representing = db.SysUser.Find(commmember.Member_Email).Employer_ID; switch (commmember.MemberRole_Role) { case "Chair": commmember.IsAdministrator = "Y"; commmember.IsConvener = "N"; break; case "Co-chair": commmember.IsAdministrator = "Y"; commmember.IsConvener = "N"; break; case "Convener": commmember.IsConvener = "Y"; commmember.IsAdministrator = "N"; break; case "Member": commmember.IsAdministrator = "N"; commmember.IsConvener = "N"; break; } /* TODO */ //Determine Permissions Based on Roles if (ModelState.IsValid) { db.CommMember.Add(commmember); db.SaveChanges(); return(RedirectToAction("Details", "Committees", new { primaryKey1 = primaryKey1, primaryKey2 = primaryKey2 })); } ViewBag.MemberRoles = new SelectList(db.MemberRole, "Role", "Role"); //ViewBag.Representing = new SelectList(db.CommOwn, "ID", "ID"); ViewBag.Member_Email = new SelectList(db.SysUser, "Email", "Email"); return(View(commmember)); }
public static void Add(string action, string sysUser_Email, string actionDescription = "") { jashdownEntities db = new jashdownEntities(); var auditlog = db.AuditLog.Include(a => a.SysUser); AuditLog newAuditLog = new AuditLog(); newAuditLog.Action = action; newAuditLog.ActionDescription = actionDescription; newAuditLog.SysUser_Email = sysUser_Email; newAuditLog.ActionDateTime = DateTime.Now; db.AuditLog.Add(newAuditLog); db.SaveChanges(); db.Dispose(); }
public ActionResult Create(int primaryKey1, CommSuperAdmin commsuperadmin) { commsuperadmin.CommOwn_ID = primaryKey1; commsuperadmin.CreatedBy = User.Identity.Name; commsuperadmin.CreatedDate = DateTime.Now; if (db.CommSuperAdmin.Any(CSA => CSA.CommOwn_ID == primaryKey1 && CSA.SysUser_Email == commsuperadmin.SysUser_Email && CSA.StartDate == commsuperadmin.StartDate)) { ModelState.AddModelError("StartDate", "User already has this start date for this Division"); } else if (ModelState.IsValid) { db.CommSuperAdmin.Add(commsuperadmin); db.SaveChanges(); return(RedirectToAction("Index", "Divisions", new { primaryKey1 = primaryKey1 })); } ViewBag.CommOwn_ID = primaryKey1; ViewBag.SysUser_Email = new SelectList(db.SysUser, "Email", "Email"); return(View(commsuperadmin)); }
public ActionResult Edit(int primaryKey1, int primaryKey2, CommCharge commcharge) { //get charge from database. //compare for changes. //make new charge //add to database. if (db.CommConstitution.Any(cc => cc.EffectiveDate == commcharge.EffectiveDate)) { ModelState.AddModelError("EffectiveDate", "Charges with this effective date already exist."); return(View(commcharge)); } CommCharge oldCommCharge = db.CommCharge.Where(cc => cc.Comm_CommOwn_ID == primaryKey1 && cc.Comm_ID == primaryKey2) .OrderByDescending(cc => cc.EffectiveDate).First(); if (commcharge.EffectiveDate > DateTime.Now) { ModelState.AddModelError("EffectiveDate", "Effective date may not occur in the future."); } if (!ModelState.IsValid) { return(View(commcharge)); } if (oldCommCharge.Charges == commcharge.Charges && oldCommCharge.EffectiveDate == commcharge.EffectiveDate) { //no change return(RedirectToAction("details", "committees", new { primaryKey1, primaryKey2 })); } else { CommCharge newCommCharge = new CommCharge(); newCommCharge.Charges = commcharge.Charges; newCommCharge.CreatedBy = User.Identity.Name; newCommCharge.CreatedDate = DateTime.Today; newCommCharge.EffectiveDate = commcharge.EffectiveDate; newCommCharge.Comm_CommOwn_ID = primaryKey1; newCommCharge.Comm_ID = primaryKey2; db.CommCharge.Add(newCommCharge); db.SaveChanges(); return(RedirectToAction("details", "committees", new { primaryKey1, primaryKey2 })); } }
public ActionResult Create(DiscItem discItem, String Tags, string[] voteTypes) { discItem.CreatedDate = DateTime.Now; var di = db.DiscItem.Include(d => d.Meeting).ToList(); if (ModelState.IsValid) { db.DiscItem.Add(discItem); // Add vote types to DiscItemVoteType table if discussion item is votable. if (discItem.IsVoted == "Y") { if (voteTypes == null) { ModelState.AddModelError("VoteType", "You must select the vote types"); ViewData["voteTypes"] = new SelectList(db.VoteType, "Type", "Type"); ViewBag.MeetingTime = discItem.Meeting_DateTime; return(View(discItem)); } VoteType newVoteType; foreach (string vt in voteTypes) { newVoteType = new VoteType { Type = vt }; db.VoteType.Attach(newVoteType); discItem.VoteType.Add(newVoteType); } } // Check if the title is valid if (db.DiscItem.Any(disc => disc.Meeting_Comm_CommOwn_ID == discItem.Meeting_Comm_CommOwn_ID && disc.Meeting_Comm_ID == discItem.Meeting_Comm_ID && disc.Meeting_DateTime == discItem.Meeting_DateTime && disc.Title == discItem.Title)) { ModelState.AddModelError("Title", "A discussion item already exists with this title"); ViewData["voteTypes"] = new SelectList(db.VoteType, "Type", "Type"); return(View(discItem)); } HttpPostedFileBase file = Request.Files[0]; DiscItemDocument discItemDoc = new DiscItemDocument(); if (file.ContentLength > 0) // checks if file was uploaded to the form { DateTime discItemDateTime = discItem.Meeting_DateTime; // sets the PKs of the disc Item Document discItemDoc.DiscItem_Meeting_Comm_CommOwn_ID = discItem.Meeting_Comm_CommOwn_ID; discItemDoc.DiscItem_Meeting_Comm_ID = discItem.Meeting_Comm_ID; discItemDoc.DiscItem_Meeting_DateTime = discItemDateTime; discItemDoc.DiscItem_Title = discItem.Title; // getting size of file int fileLen = file.ContentLength; // create write buffer byte[] byteFile = new byte[fileLen]; file.InputStream.Read(byteFile, 0, fileLen); // write file to discItemDoc discItemDoc.FileImage = byteFile; discItemDoc.Filename = file.FileName; discItemDoc.ContentType = file.ContentType; // gets tags of file discItemDoc.Tags = Tags; } if (discItemDoc != null && file.ContentLength > 0) { db.DiscItemDocument.Add(discItemDoc); } db.SaveChanges(); return(RedirectToAction("Details", "DiscItem", new { primaryKey1 = discItem.Meeting_Comm_CommOwn_ID, primaryKey2 = discItem.Meeting_Comm_ID, primaryKey3 = discItem.Meeting_DateTime.ToString("MM-dd-yyyy h.mm.ss t\\M"), primaryKey4 = discItem.Title })); } ViewData["voteTypes"] = new SelectList(db.VoteType, "Type", "Type"); ViewBag.MeetingTime = db.Meeting.Find(discItem.Meeting.Comm_CommOwn_ID, discItem.Meeting.Comm_ID, discItem.Meeting.DateTime).DateTime; return(View("Details", "DiscItem", new { primaryKey1 = discItem.Meeting_Comm_CommOwn_ID, primaryKey2 = discItem.Meeting_Comm_ID, primaryKey3 = discItem.Meeting_DateTime.ToString("MM-dd-yyyy h.mm.ss t\\M"), primaryKey4 = discItem.Title })); }
public ActionResult AddVote(string vote, int primaryKey1 = 0, int primaryKey2 = 0, string primaryKey3 = "", string primaryKey4 = "") { DateTime meetingPKDateTime; if (!DateTime.TryParse(primaryKey3, out meetingPKDateTime)) { return(HttpNotFound()); } DiscItem discItem = db.DiscItem.Find(primaryKey1, primaryKey2, meetingPKDateTime, primaryKey4); if (discItem == null) { return(HttpNotFound()); } // Check to see if this discussion item is votable if (discItem.IsVoted == "N") { return(RedirectToAction("Details", "DiscItem", new { primaryKey1 = discItem.Meeting_Comm_CommOwn_ID, primaryKey2 = discItem.Meeting_Comm_ID, primaryKey3 = discItem.Meeting_DateTime.ToString("MM-dd-yyyy h.mm.ss t\\M"), primaryKey4 = discItem.Title })); } if (ModelState.IsValid) { Discussion discussion = new Discussion(); discussion.DiscItem_Meeting_Comm_CommOwn_ID = primaryKey1; discussion.DiscItem_Meeting_Comm_ID = primaryKey2; discussion.DiscItem_Meeting_DateTime = meetingPKDateTime; discussion.DiscItem_Title = primaryKey4; discussion.SysUser_Email = User.Identity.Name; // Check if the user already voted on this discussion item if (db.Discussion.Any(di => di.DiscItem_Meeting_Comm_CommOwn_ID == discussion.DiscItem_Meeting_Comm_CommOwn_ID && di.DiscItem_Meeting_Comm_ID == discussion.DiscItem_Meeting_Comm_ID && di.DiscItem_Meeting_DateTime == discussion.DiscItem_Meeting_DateTime && di.DiscItem_Title == discussion.DiscItem_Title && di.SysUser_Email == discussion.SysUser_Email && di.HasVoted == "Y")) { TempData["voted"] = "Y"; return(RedirectToAction("Details", "DiscItem", new { primaryKey1 = discItem.Meeting_Comm_CommOwn_ID, primaryKey2 = discItem.Meeting_Comm_ID, primaryKey3 = discItem.Meeting_DateTime.ToString("MM-dd-yyyy h.mm.ss t\\M"), primaryKey4 = discItem.Title })); } // If voting for this discussion item is anonymous, add vote to AnonVoting table. if (discItem.IsAnonVoting == "Y") { AnonVoting anonVote = new AnonVoting(); anonVote.DiscItem_Title = discItem.Title; anonVote.DiscItem_Meeting_Comm_CommOwn_ID = discItem.Meeting_Comm_CommOwn_ID; anonVote.DiscItem_Meeting_DateTime = discItem.Meeting_DateTime; anonVote.DiscItem_Meeting_Comm_ID = discItem.Meeting_Comm_ID; anonVote.Vote = vote; db.AnonVoting.Add(anonVote); //db.SaveChanges(); vote = null; } else { discussion.Vote = vote; } discussion.ActionDateTime = DateTime.Now; discussion.HasVoted = "Y"; TempData["voted"] = "Y"; db.Discussion.Add(discussion); db.SaveChanges(); return(RedirectToAction("Details", "DiscItem", new { primaryKey1 = discItem.Meeting_Comm_CommOwn_ID, primaryKey2 = discItem.Meeting_Comm_ID, primaryKey3 = discItem.Meeting_DateTime.ToString("MM-dd-yyyy h.mm.ss t\\M"), primaryKey4 = discItem.Title })); } //ViewBag.DiscItem_Meeting_Comm_CommOwn_ID = new SelectList(db.DiscItem, "Meeting_Comm_CommOwn_ID", "Description", discussion.DiscItem_Meeting_Comm_CommOwn_ID); //ViewBag.SysUser_Email = new SelectList(db.SysUser, "Email", "FirstName", discussion.SysUser_Email); return(View("Details", "DiscItem", new { primaryKey1 = discItem.Meeting_Comm_CommOwn_ID, primaryKey2 = discItem.Meeting_Comm_ID, primaryKey3 = discItem.Meeting_DateTime.ToString("MM-dd-yyyy h.mm.ss t\\M"), primaryKey4 = discItem.Title })); }