public static Guid?CreateImage(HttpPostedFileBase uploadPicture) { try { Guid avatarGuid = System.Guid.NewGuid(); var avatar = new Models.File { FileNumber = System.IO.Path.GetFileName(uploadPicture.FileName), FileID = avatarGuid, FileDescription = uploadPicture.ContentType }; avatar.FileNumber = avatar.FileNumber.Substring(0, Math.Min(avatar.FileNumber.Length, 45)); using (var reader = new System.IO.BinaryReader(uploadPicture.InputStream)) { avatar.ItemImage = reader.ReadBytes(uploadPicture.ContentLength); } db.Files.Add(avatar); db.SaveChanges(); return(avatarGuid); } catch (Exception ex) { //log } return(null); }
public HttpResponseMessage EditTask([Bind(Include = "TaskID,TaskDescription,Estimation,Difficulty")] Task task) { string jsonResponseText = ""; try { if (ModelState.IsValid) { Task existingTask = db.Tasks.Where(x => x.TaskID == task.TaskID).FirstOrDefault(); if (existingTask != null) { string accessLevel = Common.CheckTaskAuthentication(User, existingTask.SprintID); if (accessLevel != Const.PermissionLevels.Administrator && accessLevel != Const.PermissionLevels.Manager) { jsonResponseText = "{\"status\":0,\"message\":\"Permissions missing\"}"; } else { existingTask.Estimation = task.Estimation; existingTask.TaskDescription = task.TaskDescription; existingTask.Difficulty = task.Difficulty; db.Entry(existingTask).Property(X => X.TaskDescription).IsModified = true; db.Entry(existingTask).Property(X => X.Estimation).IsModified = true; db.Entry(existingTask).Property(X => X.Difficulty).IsModified = true; db.SaveChanges(); jsonResponseText = "{\"status\":1,\"message\":\"The update was successfull\"}"; } } else { jsonResponseText = "{\"status\":0,\"message\":\"Task not found\"}"; } } jsonResponseText = JsonConvert.SerializeObject(task); var response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent(jsonResponseText, Encoding.UTF8, "application/json"); return(response); } catch (Exception ex) { jsonResponseText = "{\"status\":0,\"error\":\"Error trying to edit the task\",\"message\":\"" + ex.Message + "\"}"; var response = Request.CreateResponse(HttpStatusCode.InternalServerError); response.Content = new StringContent(jsonResponseText, Encoding.UTF8, "application/json"); return(response); } }
public ActionResult ChangePassword([Bind(Include = "OldPassword,Password,ConfirmPassword")] ResetPassword passmodel) { if (ModelState.IsValid && Session[Const.CLAIM.USER_ID].ToString() != null) { int employeeID = Convert.ToInt32(Session[Const.CLAIM.USER_ID]); Employee employee = db.Employees.Where(x => x.EmployeeID == employeeID).FirstOrDefault(); //checking if we have the permission necessary to change the password for this user if (employee == null || !User.Identity.IsAuthenticated) { return(RedirectToAction("NotFound", "Home")); } if (passmodel.OldPassword != employee.Password) { ModelState.AddModelError("", "Old Password not correct"); ViewBag.error = "Either the 2 passwords do not match or the old password is not valid"; return(View(passmodel)); } if (passmodel.Password != passmodel.ConfirmPassword) { ModelState.AddModelError("PasswordsDoNotMatch", "Passwords Do Not Match"); ViewBag.error = "Either the 2 passwords do not match or the old password is not valid"; return(View(passmodel)); } employee.Password = passmodel.Password; db.Entry(employee).Property(X => X.Password).IsModified = true; db.SaveChanges(); return(RedirectToAction("Index", "Home")); } return(View()); }
public ActionResult Create([Bind(Include = "ProjectID,Title,StartDate,EndDate,Duration,ContractNumber,PJDescription,Budget,DepartmentID,ContactID")] Project project) { if (ModelState.IsValid) { string accessLevel = Common.CheckProjectAuthentication(Session, User, project); if (accessLevel != Const.PermissionLevels.Administrator && accessLevel != Const.PermissionLevels.Manager) { //a manager should only create a project only for his department return(RedirectToAction("NotFound", "Home")); } db.Projects.Add(project); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ContactID = new SelectList(db.Contacts, "ContactID", "ContactName", project.ContactID1); ViewBag.DepartmentID = new SelectList(db.Departments, "DepartmentID", "Title", project.DepartmentID); return(View(project)); }
public ActionResult Create([Bind(Include = "EducationID,Title,StartDate,EndDate,Degree,EmployeeID,Duration")] Education education) { if (ModelState.IsValid) { Employee emp = db.Employees.Where(x => x.EmployeeID == education.EmployeeID).FirstOrDefault(); if (emp == null || !(User.Identity.IsAuthenticated && Session[Const.CLAIM.USER_ACCESS_LEVEL] != null && ( (Session[Const.CLAIM.USER_ACCESS_LEVEL] != null && Session[Const.CLAIM.USER_ACCESS_LEVEL].ToString() == Const.PermissionLevels.Administrator) || (Session[Const.CLAIM.USER_ID] != null && (Session[Const.CLAIM.USER_ID].ToString() == emp.EmployeeID.ToString() || Session[Const.CLAIM.USER_ID].ToString() == emp.ManagerID.ToString())) ))) { //only the manager of the employee/ the employee or an admin can perform this action return(RedirectToAction("NotFound", "Home")); } db.Educations.Add(education); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.EmployeeID = new SelectList(db.Employees, "EmployeeID", "Account", education.EmployeeID); return(View(education)); //return "Freak out"; }
public ActionResult Create([Bind(Include = "EmployeeID,RoleID,Account,Password,ManagerID,DepartmentID,FirstName,MiddleInitial,LastName,Title,CNP,Email,PhoneNumber,Salary,PriorSalary,LastRaise,HireDate,TerminationDate,Administrator")] Employee employee, HttpPostedFileBase uploadProfilePicture) { //checking if we have the permission necessary to add a new user if (!(User.Identity.IsAuthenticated && Session[Const.CLAIM.USER_ACCESS_LEVEL] != null && Session[Const.CLAIM.USER_ACCESS_LEVEL] != null && Session[Const.CLAIM.USER_ACCESS_LEVEL].ToString() == Const.PermissionLevels.Administrator)) { return(RedirectToAction("NotFound", "Home")); } if (ModelState.IsValid) { //saving the profile picture if (uploadProfilePicture != null && uploadProfilePicture.ContentLength > 0) { Guid?avatarGuid = Common.CreateImage(uploadProfilePicture); //if file was stored successfully employee.ProfileImageID = avatarGuid; } else { employee.ProfileImageID = null; } db.Employees.Add(employee); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.DepartmentID = new SelectList(db.Departments, "DepartmentID", "Title", employee.DepartmentID); ViewBag.ManagerID = new SelectList(db.Employees, "EmployeeID", "Account", employee.ManagerID); ViewBag.RoleID = new SelectList(db.Roles, "RoleID", "Name", employee.RoleID); return(View(employee)); }
public ActionResult Create( [Bind(Include = "DepartmentID,Title,MaxSize,DeptDescription,StartDate,MonthlyExpenses")] Department department, HttpPostedFileBase uploadPicture, HttpPostedFileBase uploadBanner) { //checking if we have the permission necessary to add a new user if (!(User.Identity.IsAuthenticated && Session[Const.CLAIM.USER_ACCESS_LEVEL] != null && Session[Const.CLAIM.USER_ACCESS_LEVEL] != null && Session[Const.CLAIM.USER_ACCESS_LEVEL].ToString() == Const.PermissionLevels.Administrator)) { return(RedirectToAction("NotFound", "Home")); } if (ModelState.IsValid) { if (uploadPicture != null && uploadPicture.ContentLength > 0) { Guid?avatarGuid = CreateImage(uploadPicture); //if file was stored successfully department.MainImageID = avatarGuid; } if (uploadBanner != null && uploadBanner.ContentLength > 0) { Guid?avatarGuid = CreateImage(uploadBanner); //if file was stored successfully department.BannerImageID = avatarGuid; } db.Departments.Add(department); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.BannerImageID = new SelectList(db.Files, "FileID", "FileNumber", department.BannerImageID); ViewBag.MainImageID = new SelectList(db.Files, "FileID", "FileNumber", department.MainImageID); return(View(department)); }
/// <summary> /// //we'll get the email addresses and notify the attendants the attendants /// </summary> public void SendMeetingRequest(RATV3Entities db, Event ev, List <Employee> attendantEmployees, Employee creator, ControllerContext ControllerContext, int update = 0) { try { //getting the reviewed employee Attendant at = ev.Attendants.FirstOrDefault(); Employee reviewed = db.Employees.Where(x => x.EmployeeID == at.EmployeeID).FirstOrDefault(); reviewed.SkillLevelsList = reviewed.SkillLevels.ToList(); //getting message content EventTypeInfo currentEventType = Const.EventTypesinfo.Where(x => x.EventType == ev.EventType).FirstOrDefault(); string embededHtml = "<html><head></head><body>" + "<p>Test</p>" + "<br/><br/>" + "<p>Test Embeded</p>" + "<br/>" + "<p>Test Ending</p>" + "<br/></body></html>"; if (currentEventType != null && currentEventType.EventType == "Performance Review") { string generatednotificationHTML = ViewRenderer.RenderView("~/Views/Notifications/PerformanceReview.cshtml", reviewed, ControllerContext); if (!String.IsNullOrEmpty(generatednotificationHTML)) { embededHtml = generatednotificationHTML; } } //preping the email message MailMessage email = new MailMessage(); email.From = new MailAddress(creator.Email, creator.FirstName + ' ' + creator.LastName); //adding recipients foreach (Employee attendant in attendantEmployees) { email.To.Add(new MailAddress(attendant.Email, attendant.FirstName + ' ' + attendant.LastName)); } email.IsBodyHtml = true; email.Subject = ev.EventType; //preparing email content //"text/html" - this view will have all the content System.Net.Mime.ContentType htmlMimeContent = new System.Net.Mime.ContentType("text/html"); AlternateView htmlView = AlternateView.CreateAlternateViewFromString(embededHtml, htmlMimeContent); htmlView.ContentType.CharSet = Encoding.UTF8.WebName; if (ev.EventType == "Performance Review" && ev.Attendants != null && ev.Attendants.Count > 0 && reviewed != null) { //we'll attach the pdf to the email Stream pdfDocument = GenerateUserCV(reviewed, ControllerContext); if (pdfDocument != null) { LinkedResource resource = new LinkedResource(pdfDocument); resource.ContentType.Name = reviewed.FirstName + " " + reviewed.LastName + " " + "Report.pdf"; htmlView.LinkedResources.Add(resource); } } else if (ev.EventType == "Department Monthly Meeting" && reviewed.DepartmentID.HasValue) { //we'll attach the excel report to the email byte[] array = ExcelReportGenerator.GenerateExcelReportForDepartment(reviewed.DepartmentID.Value, ev.StartTime.Month, ev.StartTime.Year, db); Stream excelDocument = new MemoryStream(array); if (excelDocument != null) { LinkedResource resource = new LinkedResource(excelDocument); resource.ContentType.Name = "Department Report.xlsx"; htmlView.LinkedResources.Add(resource); } } //preparing calendar meeting view DateTime endTime; if (ev.EndTime.HasValue) { endTime = ev.EndTime.Value; } else { endTime = ev.StartTime; } //this is the guid of the meeting request Guid requestGUID; if (ev.IcsGuid.HasValue) { requestGUID = ev.IcsGuid.Value; } else { requestGUID = Guid.NewGuid(); } AlternateView avCal = CreateICSView(email, ev.StartTime, endTime, ev, requestGUID, update); //email.Headers.Add("Content-class", "urn:content-classes:calendarmessage"); email.AlternateViews.Add(htmlView); email.AlternateViews.Add(avCal); //finally we send the mail client.Send(email); if (!ev.IcsGuid.HasValue) { ev.IcsGuid = requestGUID; db.Entry(ev).State = EntityState.Modified; } if (update > 0) { //we want to be able to store the update number too //ev.UpdateNo = update; db.Entry(ev).State = EntityState.Modified; } db.SaveChanges(); } catch (Exception ex) { //handle Exception } }
public ActionResult Create([Bind(Include = "EventID,StartTime,EndTime,EventType,Location,CreatorID,Title")] Event @event, string AttendantsIDs) { //initialize baseUrl string baseUrl = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/') + "/"; ViewBag.baseUrl = baseUrl; //checking if we have the permission necessary to add a new event int currentUserID; if (!User.Identity.IsAuthenticated || String.IsNullOrEmpty(Session[Const.CLAIM.USER_ID].ToString()) || !int.TryParse(Session[Const.CLAIM.USER_ID].ToString(), out currentUserID)) { return(RedirectToAction("NotFound", "Home")); } if (ModelState.IsValid) { @event.CreatorID = currentUserID; //finding employees List <Employee> attendantEmployees = new List <Employee>(); if (!String.IsNullOrEmpty(AttendantsIDs)) { string[] ids = AttendantsIDs.Split(';'); List <int> parsedIDs = new List <int>(); foreach (string id in ids) { int resultID; if (int.TryParse(id, out resultID)) { parsedIDs.Add(resultID); } } //get attendants attendantEmployees = db.Employees.Where(x => parsedIDs.Contains(x.EmployeeID)).ToList(); } db.Events.Add(@event); db.SaveChanges(); //if we found any attendants, add them to the database if (attendantEmployees != null && attendantEmployees.Count() > 0) { try { foreach (Employee att in attendantEmployees) { Attendant newAtt = new Attendant(); newAtt.EmployeeID = att.EmployeeID; newAtt.EventID = @event.EventID; db.Attendants.Add(newAtt); } db.SaveChanges(); } catch (Exception ex) { //handle exception } } //after the save actions are completed, we'll send the notifications to the attendants //adding the necessary data to the viewbag if (@event.EventType == "Performance Review" && @event.Attendants != null && @event.Attendants.Count > 0) { Attendant at = @event.Attendants.FirstOrDefault(); Employee employee = db.Employees.Find(at.EmployeeID); if (employee != null) { Common.GeneratePDFViewBag(@event.EventID, ViewBag); } } if (!String.IsNullOrEmpty(@event.EventType)) { //we only send a request if the meeting type is selected Mailer mailer = new Mailer(); Employee creator = db.Employees.Find(currentUserID); mailer.SendMeetingRequest(db, @event, attendantEmployees, creator, ControllerContext); } return(RedirectToAction("Index")); } ViewBag.CreatorID = new SelectList(db.Employees, "EmployeeID", "Account", @event.CreatorID); return(View(@event)); }