private void AssignTemplate(TaskList task, int templateID, string assignmentList) { var staffList = request.Staffs; string assign = assignmentList; assign = assign.Replace(" ", ""); string[] assignments = assign.Split(','); Dictionary <string, bool> staffAssignments = new Dictionary <string, bool>(); foreach (var staff in staffList) { if (assignments.Contains(staff.staffID.ToString())) { staffAssignments.Add(staff.staffID.ToString(), true); } else { staffAssignments.Add(staff.staffID.ToString(), false); } } using (ProjectRequestEntities project = new ProjectRequestEntities()) { foreach (var assignment in staffAssignments) { var editTaskAssignment = project.TaskAssignments.FirstOrDefault(a => a.taskID == task.taskID && a.staffID == assignment.Key); if (assignment.Value == true) { if (editTaskAssignment == null) { TaskAssignment myTask = new TaskAssignment(); myTask.templateID = templateID; myTask.taskID = task.taskID; myTask.staffID = assignment.Key; project.AddToTaskAssignments(myTask); project.SaveChanges(); } } else if (assignment.Value == false) { if (editTaskAssignment != null) { project.TaskAssignments.DeleteObject(editTaskAssignment); project.SaveChanges(); } } } //end assignment foreach } //end using statement }
public void LoadAttachments(int requestID) { ProjectRequestEntities projectRequest = new ProjectRequestEntities(); List <Control> dynamicControls = new List <Control>(); List <string> allAttachments = new List <string>(); List <string> To = new List <string>(); List <string> Bcc = new List <string>(); List <string> Cc = new List <string>(); FieldInfo fieldInfo = new FieldInfo(); List <string> attatchments = new List <string>(); int listNum; if (ViewState["Attatchment"] != null) { string fileName; CreateDirectory(requestID); List <string> Attachment = new List <string>(); Attachment = (List <string>)ViewState["Attatchment"]; foreach (var file in Attachment) { fileName = file; Attachment attachment = new Attachment(); attachment.filePath = requestID.ToString() + "/" + fileName; attachment.requestID = requestID; projectRequest.AddToAttachments(attachment); projectRequest.SaveChanges(); System.IO.File.Copy(filePath + fileName, filePath + requestID.ToString() + @"\" + fileName); allAttachments.Add(filePath + requestID.ToString() + @"\" + fileName); deleteAttachments.Add(filePath + fileName); } } ViewState["allAttachments"] = allAttachments; projectRequest.Dispose(); }
public void CreateSubRequest(int requestID, string category, Panel selectedPanel) { Models.SubRequest subrequest = new Models.SubRequest(); int subRequestID; using (ProjectRequestEntities projectRequest = new ProjectRequestEntities()) { subrequest.requestID = requestID; subrequest.categoryID = category; subRequestID = subrequest.subRequestID; projectRequest.AddToSubRequests(subrequest); projectRequest.SaveChanges(); subRequestID = subrequest.subRequestID; if (category != "socialMedia") { InsertData(selectedPanel, subRequestID); } } }
public ActionResult SavePetPic(HttpPostedFileBase file) { string name = Convert.ToString(User.Identity.Name); name = name.Remove(0, 8).ToLower(); if (file != null && file.ContentLength > 1) { string fileName = "Pet_" + System.IO.Path.GetFileName(file.FileName); file.SaveAs(@"C:\websites\secure.sullivan.edu\ProjectRequest\ProjectRequest\Attachments\" + fileName); Attachment attachment = new Attachment(); attachment.filePath = fileName; attachment.staffID = name; request.AddToAttachments(attachment); request.SaveChanges(); } return(RedirectToAction("Pets")); }
public ActionResult AddEvent() { string title = Request.Form["title"].ToString(); bool delete; //string startDate = Request.Form["startDate"].ToString(); DateTime StartDate = Convert.ToDateTime(Request.Form["startDate"].ToString()); int startTime1 = Convert.ToInt16(Request.Form["startTime1"]); int startTime2 = Convert.ToInt16(Request.Form["startTime2"]); string startAmPm = Request.Form["startAmPm"].ToString(); string startTime; //string endDate = Request.Form["endDate"].ToString(); DateTime EndDate = Convert.ToDateTime(Request.Form["endDate"].ToString()); int endTime1 = Convert.ToInt16(Request.Form["endTime1"]); int endTime2 = Convert.ToInt16(Request.Form["endTime2"]); string endAmPm = Request.Form["endAmPm"].ToString(); string endTime; //bool video = Convert.ToBoolean(Request.Form["video"]); //string[] startDates = startDate.Split('/'); //string[] endDates = endDate.Split('/'); //if (startAmPm == "PM" && endTime1 < 12) //{ // endTime1 = endTime1 + 12; //} //DateTime StartDate = new DateTime(Convert.ToInt16(startDates[2]), Convert.ToInt16(startDates[0]), Convert.ToInt16(startDates[1]), startTime1, startTime2, 000); //if (endAmPm == "PM" && endTime1 < 12) //{ // endTime1 = endTime1 + 12; //} //DateTime EndDate = new DateTime(Convert.ToInt16(endDates[2]), Convert.ToInt16(endDates[0]), Convert.ToInt16(endDates[1]), endTime1, endTime2, 000); //if (EndDate > StartDate) //{ // EndDate = EndDate.AddDays(1); //} if (Request.Form["id"].ToString() == "0") { Calender calender = new Calender(); calender.end = EndDate.AddHours(23).AddMinutes(59); calender.start = StartDate; calender.title = Request.Form["title"].ToString(); calender.allDay = false; calender.location = "Creative Communications"; //calender.allDay = Convert.ToBoolean(Request.Form["allDay"]); //if (video) // calender.className = "videoEvent"; request.AddToCalenders(calender); request.SaveChanges(); } else { int eventID = Convert.ToInt16(Request.Form["id"]); var calender = request.Calenders.FirstOrDefault(c => c.id == eventID); if (Request.Form["delete"] != null) { delete = true; } else { delete = false; } if (delete) { request.Calenders.DeleteObject(calender); } else { calender.end = EndDate.AddHours(23).AddMinutes(59); calender.start = StartDate; calender.title = Request.Form["title"].ToString(); calender.allDay = false; calender.location = "Creative Communications"; //calender.allDay = Convert.ToBoolean(Request.Form["allDay"]); } request.SaveChanges(); } return(RedirectToAction("Index")); }
public void InsertData(Panel panel, int subRequestID) { if (panel.ID != "pnlStoryPic") { //the page is warpped in a pnael, cycle through it to get all the labels on the page foreach (Control control in panel.Controls) { ProjectRequestEntities projectRequest = new ProjectRequestEntities(); Answer answer = new Answer(); answer.subrequestID = subRequestID; //if the current selected control is a panel you need to cycle through this panel to get all the controls in side of it if (control is Panel) { InsertData((Panel)control, subRequestID); } else if (control is TextBox || control is DropDownList || control is RadioButtonList || control is CheckBox) { //check to see what type of control is selected so you can get the appropiate text value if (control is TextBox) { answer.AnswerText = ((TextBox)control).Text; answer.QuestionID = control.ID; } else if (control is DropDownList) { if (((DropDownList)control).SelectedIndex > 0) { answer.AnswerText = ((DropDownList)control).SelectedItem.Text; answer.AnswerValue = ((DropDownList)control).SelectedValue; } else { answer.AnswerText = "No Answer"; } answer.QuestionID = control.ID; } else if (control is RadioButtonList) { if (((RadioButtonList)control).SelectedIndex > -1) { answer.AnswerText = ((RadioButtonList)control).SelectedItem.Text; answer.AnswerValue = ((RadioButtonList)control).SelectedValue; } else { answer.AnswerText = "No Answer"; } answer.QuestionID = control.ID; } else if (control is CheckBox) { if (((CheckBox)control).Checked) { answer.AnswerText = "Yes"; } else { answer.AnswerText = "No"; } answer.QuestionID = control.ID; } else { answer.AnswerText = "No Answer"; answer.QuestionID = control.ID; } projectRequest.AddToAnswers(answer); projectRequest.SaveChanges(); projectRequest.Dispose(); } } } }
public int DataInsert() { int requestID; string emailBody; List <string> To = new List <string>(); List <string> Bcc = new List <string>(); List <string> Cc = new List <string>(); FieldInfo fieldInfo = new FieldInfo(); List <string> attatchments = new List <string>(); using (ProjectRequestEntities projectRequest = new ProjectRequestEntities()) { ProjectRequestEntities newCase = new ProjectRequestEntities(); Models.Request request = new Models.Request(); var DOAs = newCase.DOAs.Select(d => d.doaID).ToList(); var staffList = newCase.Staffs.Select(s => s.staffID).ToList(); var approverList = newCase.Approvers.Select(a => a.sullivanID).ToList(); request.name = tbFName.Text + " " + tbLName.Text; request.location = ddlLocation.SelectedItem.Text; request.contactInfo = tbContact.Text; request.dateRequested = DateTime.Now; request.completed = false; request.subProjects = 1; request.projectName = tbProjectName.Text; request.categoryID = "multi"; request.department = ddlDepartment.SelectedItem.Text; request.email = tbEmail.Text; request.additionalInfo = tbAdditionalInfo.Text; if (DOAs.Contains((string)ViewState["name"]) || staffList.Contains((string)ViewState["name"]) || approverList.Contains((string)ViewState["name"])) { request.status = "Approved"; } else { request.status = "Pending"; var approvers = newCase.Approvers.Where(d => d.department == ddlDepartment.SelectedItem.Text); string approverName = ""; foreach (var name in approvers) { approverName += name.name + ", "; } approverName = approverName.Trim(); approverName = approverName.TrimEnd(','); request.doaName = approverName; } projectRequest.AddToRequests(request); projectRequest.SaveChanges(); requestID = request.reuqestID; ViewState["RequestID"] = requestID.ToString(); projectRequest.Dispose(); LoadAttachments(requestID); //} //catch (Exception ex) //{ // To.Clear(); // Cc.Clear(); // To.Add("*****@*****.**"); // fieldInfo.SendEmail("PR Database Error for " + category, ex.ToString(), To, Bcc, Cc, "*****@*****.**", attatchments); //} } return(requestID); }
public ActionResult EditTemplate() { int templateID = 0; if (Request.Form["templateID"].ToString().Length > 0) { templateID = Convert.ToInt16(Request.Form["templateID"]); } var tasks = request.TaskLists.Where(r => r.TemplateID == templateID); if (templateID != 0) { var template = request.Templates.FirstOrDefault(t => t.templateID == templateID); template.templateName = Request.Form["templateName"].ToString(); foreach (var task in tasks) { bool delete; var currentTask = request.TaskLists.FirstOrDefault(a => a.taskID == task.taskID); if (Request.Form["Delete_" + task.taskID] != null) { delete = true; } else { delete = false; } if (delete == false) { try { currentTask.orderNum = Convert.ToInt16(Request.Form["Order_" + task.taskID]); } catch { //Response.Redirect(task.taskID.ToString()); } currentTask.Task = Request.Form["Task_" + task.taskID].ToString(); currentTask.Comments = Request.Form["Comments_" + task.taskID].ToString(); try { currentTask.DueDate = Convert.ToDateTime(Request.Form["DueDate_" + task.taskID]); } catch { } if (Request.Form["Status_" + task.taskID].ToString() != "00") { currentTask.Status = Request.Form["Status_" + task.taskID].ToString(); } AssignTemplate(task, templateID, Request.Form["Assignment_" + task.taskID].ToString().Replace(" ", "")); } else if (delete == true) { var taskAsignment = request.TaskAssignments.Where(t => t.templateID == templateID && t.taskID == task.taskID); foreach (var assignment in taskAsignment) { request.TaskAssignments.DeleteObject(assignment); } request.TaskLists.DeleteObject(currentTask); } }// end task foreach request.SaveChanges(); } else { Template newTemplate = new Template(); newTemplate.templateID = templateID; newTemplate.templateName = Request.Form["templateName"].ToString(); request.AddToTemplates(newTemplate); request.SaveChanges(); templateID = newTemplate.templateID; } if (Request.Form["Task"] != null && Request.Form["Task"].ToString().Length > 0 && templateID != 0) { TaskList newTask = new TaskList(); newTask.TemplateID = templateID; try { newTask.orderNum = Convert.ToInt16(Request.Form["Order"]); } catch { } newTask.Task = Request.Form["Task"].ToString(); newTask.Comments = Request.Form["Comments"].ToString(); try { newTask.DueDate = Convert.ToDateTime(Request.Form["DueDate"]); } catch { } if (Request.Form["Status"].ToString() != "00") { newTask.Status = Request.Form["Status"].ToString(); } request.AddToTaskLists(newTask); request.SaveChanges(); AssignTemplate(newTask, templateID, Request.Form["Assignment"].ToString().Replace(" ", "")); } return(RedirectToAction("DisplayTemplate", new { template = templateID })); }
public string AddTime(string id, string description, string time) { ProjectRequestEntities request = new ProjectRequestEntities(); try { if (description.Count() > 0 && time.Count() > 0) { string name = Convert.ToString(User.Identity.Name); name = name.Remove(0, 8).ToLower(); int requestID = Convert.ToInt16(id); var date = DateTime.Now.Date; var sheetName = request.TimeSheets.FirstOrDefault(d => d.sheetDate == date && d.staffID == name); if (sheetName == null) { int sheetsNeeded; DateTime sheetDate; IEnumerable <TimeSheet> timeSheet = request.TimeSheets.Where(t => t.staffID == name && t.completed == false).OrderByDescending(t => t.sheetDate); TimeSheet currentSheet; var allSheets = request.TimeSheets.Where(t => t.staffID == name).OrderByDescending(t => t.sheetDate); if (allSheets == null || allSheets.Count() < 1) { TimeSheet mySheet = new TimeSheet(); mySheet.sheetDate = DateTime.Today; mySheet.staffID = name; mySheet.completed = false; request.AddToTimeSheets(mySheet); request.SaveChanges(); } currentSheet = allSheets.FirstOrDefault(); sheetDate = currentSheet.sheetDate.GetValueOrDefault(); sheetDate = sheetDate.AddDays(1); sheetsNeeded = (int)DateTime.Today.Subtract(sheetDate).TotalDays; for (var startDate = 1; startDate <= sheetsNeeded + 1; startDate++) { if (sheetDate.DayOfWeek != DayOfWeek.Saturday && sheetDate.DayOfWeek != DayOfWeek.Sunday) { var sheet = request.TimeSheets.FirstOrDefault(t => t.sheetDate == sheetDate && t.staffID == name); if (sheet == null) { TimeSheet mySheet = new TimeSheet(); mySheet.sheetDate = sheetDate; mySheet.staffID = name; mySheet.completed = false; request.AddToTimeSheets(mySheet); request.SaveChanges(); sheetDate = sheetDate.AddDays(1); } else { sheetDate = sheetDate.AddDays(1); } } else { sheetDate = sheetDate.AddDays(1); } } sheetName = request.TimeSheets.FirstOrDefault(d => d.sheetDate == date && d.staffID == name); } var currentRequest = request.Requests.FirstOrDefault(r => r.reuqestID == requestID); Chore chore = new Chore(); chore.chore1 = description; chore.requestID = requestID; chore.sheetID = sheetName.sheetID; chore.timeSpent = Convert.ToDecimal(time); chore.name = currentRequest.projectName; request.AddToChores(chore); request.SaveChanges(); return("Your report has been successfully filed."); }// end validation if else { return("Please fill out description and time fields"); } }// end try catch (Exception ex) { return(ex.ToString()); } }
public ActionResult EditTimeSheet(int sheetID, string startDate, string endDate, string assignedProjects = "true", string completed = "false") { ProjectRequestEntities request = new ProjectRequestEntities(); //sheetID = Convert.ToInt32(Request.QueryString["sheetID"]); var chores = request.Chores.Where(c => c.sheetID == sheetID); var timeSheet = request.TimeSheets.FirstOrDefault(t => t.sheetID == sheetID); bool delete; bool complete; if (Request.Form["complete"] != null) { complete = true; } else { complete = false; } timeSheet.completed = complete; foreach (var chore in chores) { var currentRequest = request.Requests.FirstOrDefault(r => r.reuqestID == chore.requestID); if (Request.Form["Delete_" + chore.choreID] != null) { delete = true; } else { delete = false; } if (delete == false) { chore.requestID = Convert.ToInt16(Request.Form["Request_" + chore.choreID]); chore.chore1 = Request.Form["Chore_" + chore.choreID].ToString(); chore.timeSpent = Convert.ToDecimal(Request.Form["TimeSpent_" + chore.choreID]); chore.name = currentRequest.projectName; } else { request.DeleteObject(chore); } } request.SaveChanges(); if (Request.Form["Request"] != null && Request.Form["Request"].ToString().Count() > 0) { int requestID = Convert.ToInt16(Request.Form["Request"]); var currentRequest = request.Requests.FirstOrDefault(r => r.reuqestID == requestID); Chore chore = new Chore(); chore.sheetID = sheetID; chore.requestID = Convert.ToInt16(Request.Form["Request"]); chore.chore1 = Request.Form["Chore"].ToString(); chore.timeSpent = Convert.ToDecimal(Request.Form["TimeSpent"]); chore.name = currentRequest.projectName; request.AddToChores(chore); request.SaveChanges(); } return(RedirectToAction("CreateTimeSheet", new { sheetID = sheetID, startDate = startDate, endDate = endDate, assignedProjects = assignedProjects, completed = completed })); }
// // GET: /TimeSheet/ public ActionResult Index() { ProjectRequestEntities request = new ProjectRequestEntities(); string name = Convert.ToString(User.Identity.Name); name = name.Remove(0, 8).ToLower(); int sheetsNeeded; DateTime sheetDate; IEnumerable <TimeSheet> timeSheet = request.TimeSheets.Where(t => t.staffID == name && t.completed == false).OrderByDescending(t => t.sheetDate); TimeSheet currentSheet; var allSheets = request.TimeSheets.Where(t => t.staffID == name).OrderByDescending(t => t.sheetDate); if (allSheets == null || allSheets.Count() < 1) { TimeSheet mySheet = new TimeSheet(); mySheet.sheetDate = DateTime.Today; mySheet.staffID = name; mySheet.completed = false; request.AddToTimeSheets(mySheet); request.SaveChanges(); } currentSheet = allSheets.FirstOrDefault(); //if (timeSheet == null || timeSheet.Count() < 1) //{ // var sheetsCompleted = request.TimeSheets.Where(t => t.staffID == name && t.completed == true).OrderByDescending(t => t.sheetDate); // if (sheetsCompleted == null || sheetsCompleted.Count() < 1) // { // var todaySheet = request.TimeSheets.FirstOrDefault(t => t.sheetDate == DateTime.Today && t.completed == true); // if (todaySheet == null) // { // TimeSheet mySheet = new TimeSheet(); // mySheet.sheetDate = DateTime.Today; // mySheet.staffID = name; // mySheet.completed = false; // request.AddToTimeSheets(mySheet); // request.SaveChanges(); // currentSheet = mySheet; // } // else // currentSheet = todaySheet; // } // else // { // var lastSheetCompleted = sheetsCompleted.FirstOrDefault(); // currentSheet = lastSheetCompleted; // } //} //else //{ // currentSheet = timeSheet.FirstOrDefault(t => t.staffID == name); //} sheetDate = currentSheet.sheetDate.GetValueOrDefault(); sheetDate = sheetDate.AddDays(1); sheetsNeeded = (int)DateTime.Today.Subtract(sheetDate).TotalDays; for (var startDate = 1; startDate <= sheetsNeeded + 1; startDate++) { if (sheetDate.DayOfWeek != DayOfWeek.Saturday && sheetDate.DayOfWeek != DayOfWeek.Sunday) { var sheet = request.TimeSheets.FirstOrDefault(t => t.sheetDate == sheetDate && t.staffID == name); if (sheet == null) { TimeSheet mySheet = new TimeSheet(); mySheet.sheetDate = sheetDate; mySheet.staffID = name; mySheet.completed = false; request.AddToTimeSheets(mySheet); request.SaveChanges(); sheetDate = sheetDate.AddDays(1); } else { sheetDate = sheetDate.AddDays(1); } } else { sheetDate = sheetDate.AddDays(1); } } IEnumerable <TimeSheet> lateSheets = request.TimeSheets.Where(t => t.staffID == name && t.completed == false).OrderByDescending(t => t.sheetDate); return(View(lateSheets)); }
public void EditRequesterInfo(FormCollection form) { IEnumerable <Staff> staff = request.Staffs; string emailBody; MailMessage mail = new MailMessage(); SmtpClient mailer = new SmtpClient("owa13.Sullivan.edu"); //mail.Bcc.Add(new MailAddress("*****@*****.**")); //mail.Bcc.Add(new MailAddress("*****@*****.**")); mail.IsBodyHtml = true; mailer.EnableSsl = false; mail.From = new MailAddress("*****@*****.**"); int requestID = Convert.ToInt16(Request.QueryString["requestID"]); string currentTrackID = Request.Form["CT#"].ToString(); string completed = Request.Form["completed"].ToString(); Dictionary <string, bool> staffing = new Dictionary <string, bool>(); var editRequest = request.Requests.FirstOrDefault(r => r.reuqestID == requestID); if (editRequest.currentTrackID == null && currentTrackID != null && currentTrackID.Length > 3) { //mail.To.Add("*****@*****.**"); emailBody = "<p>Current Track ID assigned for " + editRequest.projectName + ". <a href='https://secure.sullivan.edu/ProjectRequest/ProjectRequest/Request/RequestInfo?requestID=" + requestID.ToString() + "'>Click Here</a> to view the project</p>"; mail.Body = emailBody; mail.Subject = "Creative Communications Current Track ID Assigned"; mailer.Send(mail); mail.To.Clear(); try { mail.To.Add(editRequest.email); mail.Subject = "Creative Communications Projeject Request Received"; mail.Body = "Your request of '" + editRequest.projectName + "' has been received by Creative Communications. Project number " + currentTrackID + "."; mailer.Send(mail); } catch { } } editRequest.currentTrackID = currentTrackID; if (completed == "Yes" && editRequest.completed == false) { editRequest.completed = true; mail.To.Clear(); try { mail.To.Add(editRequest.email); mail.To.Add("*****@*****.**"); mail.Subject = "Creative Communications Project Request Completed"; mail.Body = "Your request of '" + editRequest.projectName + "' has been been completed. Project number " + currentTrackID + "."; mailer.Send(mail); } catch { } } else if (completed == "No") { editRequest.completed = false; } editRequest.contactInfo = Request.Form["contactInfo"].ToString(); editRequest.dateRequested = Convert.ToDateTime(Request.Form["date"]); editRequest.location = Request.Form["location"].ToString(); editRequest.name = Request.Form["name"].ToString(); editRequest.categoryID = Request.Form["category"].ToString(); editRequest.doaName = Request.Form["doaName"].ToString(); editRequest.projectName = Request.Form["projectName"].ToString(); editRequest.email = Request.Form["email"].ToString(); editRequest.additionalInfo = Request.Form["additionalInfo"].ToString(); editRequest.comment = Request.Form["comments"].ToString(); request.SaveChanges(); }