public void LookUpSheet() { ProjectRequestEntities request = new ProjectRequestEntities(); string name = Convert.ToString(User.Identity.Name); name = name.Remove(0, 8).ToLower(); try { DateTime sheetDate = Convert.ToDateTime(Request.Form["sheetDate"]); var timeSheet = request.TimeSheets.FirstOrDefault(t => t.sheetDate == sheetDate && t.staffID == name); if (timeSheet != null) { Response.Redirect("~/TimeSheet/CreateTimeSheet?sheetID=" + timeSheet.sheetID.ToString()); } else { Response.Redirect("~/TimeSheet/Index?sheet=Fail"); } } catch { Response.Redirect("~/TimeSheet/Index?sheet=Fail"); } }
protected override bool AuthorizeCore(HttpContextBase httpContext) { var authorized = base.AuthorizeCore(httpContext); ProjectRequestEntities request = new ProjectRequestEntities(); var staffList = request.Staffs.Select(s => s.staffID).ToList(); string name = Convert.ToString(httpContext.User.Identity.Name); name = name.Remove(0, 8).ToLower(); if (!authorized) { // The user is not authenticated return(false); } if (staffList.Contains(name)) { return(true); } else { return(false); } }
public RequestInfoViewModel GetRequestInfo(int requestID) { ProjectRequestEntities request = new ProjectRequestEntities(); var answers = request.Answers.Where(a => a.requestID == requestID); IEnumerable <Models.Attachment> attachments = request.Attachments.Where(a => a.requestID == requestID); IEnumerable <Staff> staff = request.Staffs; IEnumerable <RequestAssignment> requestAssignment = request.RequestAssignments.Where(r => r.requestID == requestID); IEnumerable <TaskList> taskList = request.TaskLists.Where(r => r.requestID == requestID).OrderBy(t => t.orderNum); List <TaskAssignment> taskAssignment = new List <TaskAssignment>(); List <AnswerListViewModel> myAnswerList = new List <AnswerListViewModel>(); foreach (var task in taskList) { var currentTasks = request.TaskAssignments.Where(t => t.taskID == task.taskID); foreach (var item in currentTasks) { taskAssignment.Add(item); } } foreach (var answer in answers) { var question = request.Questions.FirstOrDefault(q => q.questionID == answer.QuestionID); if (question != null) { AnswerListViewModel list = new AnswerListViewModel { answer = answer, question = question.Question1 }; myAnswerList.Add(list); } } var currentRequst = request.Requests.FirstOrDefault(r => r.reuqestID == requestID); var poNum = request.PONums.Where(r => r.requestID == requestID); RequestInfoViewModel requestList = new RequestInfoViewModel { answerList = myAnswerList, attachment = attachments, request = currentRequst, staff = staff, assignments = requestAssignment, category = request.Categories.FirstOrDefault(c => c.categoryID == currentRequst.categoryID), cateogires = request.Categories, location = request.Locations, taskList = taskList, taskStatus = request.TaskStatus1, templateList = request.Templates, taskAssignments = taskAssignment, poNum = poNum }; return(requestList); }
public ActionResult NewSchoolEvent() { ProjectRequestEntities request = new ProjectRequestEntities(); IEnumerable <Location> location = request.Locations.OrderByDescending(i => i.name); return(View(location)); }
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 }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { ProjectRequestEntities request = new ProjectRequestEntities(); var staffList = request.Staffs.Select(s => s.staffID).ToList(); name = Convert.ToString(User.Identity.Name); name = name.Remove(0, 8).ToLower(); ViewState["name"] = name; lblHello.Text = "Hello " + name; if (staffList.Contains(name)) { var ccAgent = request.Staffs.FirstOrDefault(s => s.staffID == name); ddlDepartment.Items.Insert(1, new ListItem("Creative", "Creative")); ddlDepartment.Items[1].Selected = true; tbFName.Text = ccAgent.firstName; tbLName.Text = ccAgent.lastName; tbEmail.Text = name + "@Sullivan.edu"; ddlLocation.SelectedIndex = 2; ViewState["CCAgent"] = true; //pnlBlackOut.Visible = false; //mainPanel.Visible = true; } else { pnlBillboard.Visible = false; pnlTvCommercial.Visible = false; pnlWebBanner.Visible = false; //pnlBlackOut.Visible = true; //mainPanel.Visible = false; } if (name == "lajones") { pnlBlackOut.Visible = false; mainPanel.Visible = true; } btnSubmit.Visible = false; Session.Abandon(); } }
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 Index() { ProjectRequestEntities project = new ProjectRequestEntities(); string name = Convert.ToString(User.Identity.Name); name = name.Remove(0, 8).ToLower(); Staff staff = project.Staffs.FirstOrDefault(s => s.staffID == name); IEnumerable <Category> category = project.Categories.OrderBy(c => c.categoryName); if (staff != null) { ViewBag.Name = staff.lastName; return(View(category)); } else { RedirectToAction("ActionResult"); } return(View(staff)); }
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); }
protected void btnSubmit_Click(object sender, EventArgs e) { if (Page.IsValid) { List <FieldInfo> formInfo = new List <FieldInfo>(); FieldInfo fieldInfo = new FieldInfo(); string emailBody; List <string> To = new List <string>(); List <string> Bcc = new List <string>(); List <string> Cc = new List <string>(); List <string> attatchments = new List <string>(); string location = ddlLocation.SelectedItem.Text; int requestID; ProjectRequestEntities newCase = new ProjectRequestEntities(); 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(); //Send out email and insert into database //try //{ requestID = DataInsert(); formInfo = fieldInfo.CreateFormInfo(pnlIntro); if (animation.Checked) { formInfo = fieldInfo.CreateFormInfo(pnlAnimation); CreateSubRequest(requestID, "animation", pnlAnimation); } if (website.Checked) { formInfo = fieldInfo.CreateFormInfo(pnlWebChange); CreateSubRequest(requestID, "website", pnlWebChange); } if (billBoard.Checked) { formInfo = fieldInfo.CreateFormInfo(pnlBillboard); CreateSubRequest(requestID, "billBoard", pnlBillboard); } if (businessCard.Checked) { formInfo = fieldInfo.CreateFormInfo(pnlBusinessCards); CreateSubRequest(requestID, "businessCard", pnlBusinessCards); } if (postcards.Checked) { formInfo = fieldInfo.CreateFormInfo(pnlPostcards); CreateSubRequest(requestID, "postcards", pnlPostcards); } if (flyer.Checked) { formInfo = fieldInfo.CreateFormInfo(pnlFlyer); CreateSubRequest(requestID, "flyer", pnlFlyer); } if (landingPage.Checked) { formInfo = fieldInfo.CreateFormInfo(pnlLandingPage); CreateSubRequest(requestID, "landingPage", pnlLandingPage); } if (filmCrew.Checked) { formInfo = fieldInfo.CreateFormInfo(pnlFilmCrew); CreateSubRequest(requestID, "filmCrew", pnlFilmCrew); } if (poster.Checked) { formInfo = fieldInfo.CreateFormInfo(pnlPoster); CreateSubRequest(requestID, "poster", pnlPoster); } if (printAd.Checked) { formInfo = fieldInfo.CreateFormInfo(pnlPrintAd); CreateSubRequest(requestID, "printAd", pnlPrintAd); } if (radioSpot.Checked) { formInfo = fieldInfo.CreateFormInfo(pnlRadioSpot); CreateSubRequest(requestID, "radioSpot", pnlRadioSpot); } if (specialEvent.Checked) { formInfo = fieldInfo.CreateFormInfo(pnlSpecialEvent); CreateSubRequest(requestID, "specialEvent", pnlSpecialEvent); } if (story.Checked) { formInfo = fieldInfo.CreateFormInfo(pnlStory); CreateSubRequest(requestID, "story", pnlStory); } if (targetedAd.Checked) { formInfo = fieldInfo.CreateFormInfo(pnlTargetedAd); CreateSubRequest(requestID, "targetedAd", pnlTargetedAd); } if (tShirt.Checked) { formInfo = fieldInfo.CreateFormInfo(pnlTShirt); CreateSubRequest(requestID, "tShirt", pnlTShirt); } if (tvCommercial.Checked) { formInfo = fieldInfo.CreateFormInfo(pnlTvCommercial); CreateSubRequest(requestID, "tvCommercial", pnlTvCommercial); } if (webBanner.Checked) { formInfo = fieldInfo.CreateFormInfo(pnlWebBanner); CreateSubRequest(requestID, "webBanner", pnlWebBanner); } if (E_Blast.Checked) { formInfo = fieldInfo.CreateFormInfo(pnlEBlast); CreateSubRequest(requestID, "E_Blast", pnlEBlast); } if (socialMedia.Checked) { CreateSubRequest(requestID, "socialMedia", null); } foreach (var file in deleteAttachments) { File.Delete(file); } emailBody = fieldInfo.CreateEmailBody(formInfo); if (ViewState["allAttachments"] != null) { attatchments = (List <string>)ViewState["allAttachments"]; } //fieldInfo.SendEmail("Project Request", emailBody, To, Bcc, Cc, "*****@*****.**", attatchments); //} //catch (Exception ex) //{ // To.Clear(); // Cc.Clear(); // To.Add("*****@*****.**"); // fieldInfo.SendEmail("PR EMail Error", ex.ToString(), To, Bcc, Cc, "*****@*****.**", attatchments); //} Session.Abandon(); //Send confirmation email try { To.Clear(); To.Add(tbEmail.Text); Cc.Clear(); Bcc.Clear(); attatchments.Clear(); if (staffList.Contains((string)ViewState["name"])) { fieldInfo.SendEmail("Creative Communication Project Submitted", "<p>" + tbProjectName.Text + " has been put in the oven and is now baking.</p><p><img src='https://www.wiseguysbuffalo.com/wp-content/uploads/2016/12/pizzaGuyColor.png'></p>", To, Bcc, Cc, "*****@*****.**", attatchments); Response.Redirect("https://secure.sullivan.edu/ProjectRequest/ProjectRequest/Request/EditCase?requestID=" + (string)ViewState["RequestID"]); } else if (DOAs.Contains((string)ViewState["name"]) || approverList.Contains((string)ViewState["name"])) { fieldInfo.SendEmail("Creative Communication Project Submitted", "<p>" + tbProjectName.Text + " has been submitted.</p>", To, Bcc, Cc, "*****@*****.**", attatchments); Response.Redirect("https://secure.sullivan.edu/ProjectRequest/ProjectRequest/User/MyRequests"); } else { var approvers = newCase.Approvers.Where(d => d.department == ddlDepartment.SelectedItem.Text); string approverName = ""; To.Clear(); foreach (var name in approvers) { To.Add(name.email); approverName += name.name + ", "; } approverName = approverName.Trim(); approverName = approverName.TrimEnd(','); fieldInfo.SendEmail("Creative Communication Project Approval Needed", "<html><body> <p>Hello " + approverName + "</p>" + "<p><b>" + tbFName.Text + " " + tbLName.Text + "</b> has submitted a project request to Creative Communications. Please review <b>" + tbProjectName.Text + "</b> and determine if it should be approved or denied. Work on the project will not be started unless it has been approved.</p>" + "<p><a href='https://secure.sullivan.edu/ProjectRequest/ProjectRequest/Request/ViewCase?requestID=" + (string)ViewState["RequestID"] + "'>Project Info</a></p>" + "<p><a href='https://secure.sullivan.edu/ProjectRequest/ProjectRequest/Request?projectStatus=Pending&approvers=Yes'>All projects pending approval</a></p></body></html>", To, Bcc, Cc, "*****@*****.**", attatchments); To.Clear(); To.Add(tbEmail.Text); fieldInfo.SendEmail("Creative Communication Project Submitted", "<html><body><p>Thank You!</p>" + "<p>Your Creative Communications project request, " + tbProjectName.Text + ", has been submitted.</p>" + "<p>Your project is currently pending approval from " + approverName + ".</p>" + "<p>You’ll be notified once a decision has been made.</p>" + "<p><a href='https://secure.sullivan.edu/ProjectRequest/ProjectRequest/Request/ViewCase?requestID=" + (string)ViewState["RequestID"] + "'>Project Info</a></p>" + "<p><a href='https://secure.sullivan.edu/ProjectRequest/ProjectRequest/User/MyRequests'>All my projects</a></p>" + "<p>If you have any questions, please email me at <a href='mailTo:[email protected]'></a>[email protected].</p></body></html>", To, Bcc, Cc, "*****@*****.**", attatchments); Session["Approver"] = approverName; Response.Redirect("RequestFormConfirm.aspx"); } } catch { } }//Ensure Page is Valid }
public ViewResult MyRequests(string dateStart, string dateEnd, string location, string category, string search, string searchPO, string excludeCategory, string assignedTo, string projectStatus, string excludeStatus, int page = 1, string completed = "false") { ProjectRequestEntities request = new ProjectRequestEntities(); IEnumerable <Request> info = request.Requests.OrderByDescending(i => i.dateRequested).Where(r => r.categoryID != "timeSheet"); PagingInfo pageInfo = new PagingInfo(); IEnumerable <Models.Attachment> attachmnets = request.Attachments; Regex reg = new Regex(@"^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d$"); if (search != null && search.Count() > 0) { info = request.Requests.OrderByDescending(i => i.dateRequested).Where(r => r.projectName.ToLower().Contains(search.ToLower()) || r.email.ToLower().Contains(search.ToLower()) || r.doaName.ToLower().Contains(search.ToLower()) || r.name.ToLower().Contains(search.ToLower()) || r.customID.Contains(search)); if (reg.IsMatch(search)) { info = request.Requests.Where(r => r.dueDate == Convert.ToDateTime(search)); } info = info.Where(r => r.categoryID != "timeSheet"); } if (searchPO != null && searchPO.Count() > 0) { var poNum = request.PONums.Where(p => p.PONum1 == searchPO).Select(p => p.requestID).ToList(); info = info.Where(p => poNum.Contains(p.reuqestID)); } string name = Convert.ToString(User.Identity.Name); name = name.Remove(0, 8).ToLower(); info = info.Where(a => a.email != null); info = info.Where(a => a.email.Contains(name)); if (completed == "false") { info = info.Where(i => i.completed == false); } else if (completed == "true") { info = info.Where(i => i.completed == true); } if (location != "00" && location != null) { info = info.Where(i => i.location == location); } if (category != "00" && category != null) { info = info.Where(i => i.categoryID == category); } if (excludeCategory != "00" && excludeCategory != null) { info = info.Where(i => i.categoryID != excludeCategory); } if (projectStatus != "00" && projectStatus != null) { info = info.Where(i => i.status == projectStatus); } if (excludeStatus != "00" && excludeStatus != null) { info = info.Where(i => i.status != excludeStatus); } if (dateStart != null && dateEnd != null && reg.IsMatch(dateStart) && reg.IsMatch(dateEnd)) { try { info = info.Where(i => i.dateRequested >= Convert.ToDateTime(dateStart) && i.dateRequested < Convert.ToDateTime(dateEnd).AddDays(1)); } catch { } } //if (search != null && search.Count() > 0) //{ // info = info.Where(r => r.projectName.ToLower().Contains(search.ToLower()) || r.doaName.ToLower().Contains(search.ToLower()) // || r.name.ToLower().Contains(search.ToLower()) || r.customID.Contains(search)); // if (reg.IsMatch(search)) // { // info = info.Where(r => r.dueDate == Convert.ToDateTime(search)); // } //} List <RequestListViewModel> requestList = new List <RequestListViewModel>(); foreach (var item in info) { RequestListViewModel myList = new RequestListViewModel() { Request = item, Category = request.Categories.FirstOrDefault(c => c.categoryID == item.categoryID) }; requestList.Add(myList); } int pageTotal = requestList.Count(); int subCases = Convert.ToInt16(requestList.Sum(r => r.Request.subProjects)); ViewBag.CaseTotal = pageTotal; ViewBag.SubCases = subCases; RequestListCategory requestListCategory = new RequestListCategory { requestList = requestList.Skip((page - 1) * PageSize).Take(PageSize), cateogires = request.Categories.Where(c => c.version == "1"), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = pageTotal, dateStart = dateStart, dateEnd = dateEnd, category = category, excludeCategory = excludeCategory, completed = completed, location = location, completionStatus = pageInfo.PopulateStatus(), search = search, searchPO = searchPO, assignedTo = assignedTo, projectStatus = projectStatus, excludeStatus = excludeStatus }, location = request.Locations, attachments = attachmnets, staffList = request.Staffs, projectStatus = request.ProjectStatus1.OrderBy(s => s.status) }; ViewData["Categories"] = request.Categories; ViewBag.Method = "MyProjects"; return(View(requestListCategory)); }
protected void Page_Load(object sender, EventArgs e) { ProjectRequestEntities request = new ProjectRequestEntities(); IEnumerable <Request> info = request.Requests.OrderByDescending(i => i.dateRequested).Where(r => r.categoryID != "timeSheet"); IEnumerable <Models.Attachment> attachmnets = request.Attachments; DataTable projectTable = new DataTable(); DataColumn column; DataRow row; DataView view; int maxAttachments = Convert.ToInt16(attachmnets.GroupBy(r => r.requestID).OrderByDescending(gp => gp.Count()).Take(1).Select(r => r.Key)); column = new DataColumn(); column.DataType = System.Type.GetType("System.String"); column.ColumnName = "CT#"; projectTable.Columns.Add(column); column = new DataColumn(); column.DataType = System.Type.GetType("System.String"); column.ColumnName = "CCID"; projectTable.Columns.Add(column); column = new DataColumn(); column.DataType = System.Type.GetType("System.DateTime"); column.ColumnName = "DateSubmitted"; projectTable.Columns.Add(column); column = new DataColumn(); column.DataType = System.Type.GetType("System.String"); column.ColumnName = "Requester"; projectTable.Columns.Add(column); column = new DataColumn(); column.DataType = System.Type.GetType("System.DueDate"); column.ColumnName = "DueDate"; projectTable.Columns.Add(column); column = new DataColumn(); column.DataType = System.Type.GetType("System.String"); column.ColumnName = "ProjectName"; projectTable.Columns.Add(column); column = new DataColumn(); column.DataType = System.Type.GetType("System.String"); column.ColumnName = "Location"; projectTable.Columns.Add(column); column = new DataColumn(); column.DataType = System.Type.GetType("System.String"); column.ColumnName = "Category"; projectTable.Columns.Add(column); foreach (var record in info) { row = projectTable.NewRow(); row["CT#"] = record.currentTrackID; row["CCID"] = record.customID; row["DateSubmitted"] = record.dateRequested; row["Requester"] = record.name; row["DueDate"] = record.dueDate; row["ProjectName"] = record.projectName; row["Location"] = record.location; row["Category"] = record.categoryID; } }
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 CreateTimeSheet(string startDate, string endDate, string assignedProjects = "true", string completed = "false") { ProjectRequestEntities request = new ProjectRequestEntities(); int sheetID = Convert.ToInt32(Request.QueryString["sheetID"]); string name = Convert.ToString(User.Identity.Name); name = name.Remove(0, 8).ToLower(); IEnumerable <Chore> chores = request.Chores.Where(c => c.sheetID == sheetID); IEnumerable <Request> requests = request.Requests; IEnumerable <Location> locations = request.Locations.OrderBy(l => l.name); TimeSheet timeSheet = request.TimeSheets.FirstOrDefault(t => t.sheetID == sheetID); Regex reg = new Regex(@"^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d$"); if (startDate != null && reg.IsMatch(startDate)) { try { requests = requests.Where(i => i.dateRequested >= Convert.ToDateTime(startDate)); } catch { } } if (endDate != null && reg.IsMatch(endDate)) { try { requests = requests.Where(i => i.dateRequested < Convert.ToDateTime(endDate).AddDays(1)); } catch { } } if (completed == "false") { requests = requests.Where(i => i.completed == false); } if (assignedProjects == "true") { var assignments = request.RequestAssignments.Where(r => r.staffID == name).Select(r => r.requestID).ToList(); requests = requests.Where(r => assignments.Contains(r.reuqestID)); } TimeSheetInfo sheetInfo = new TimeSheetInfo { requests = requests, chores = chores, locations = locations, timeSheet = timeSheet, startDate = startDate, endDate = endDate, completedProjects = completed, assignedProjects = assignedProjects }; return(View(sheetInfo)); }
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)); }