public ActionResult NewEmployee(EmployeeViewModel model)
        {
            Employee newEmployee = new Employee();

            try
            {
                //Transfer the models info to our main Employee Model
                newEmployee.EmployeeID   = model.EmployeeID;
                newEmployee.FirstName    = model.FirstName;
                newEmployee.LastName     = model.LastName;
                newEmployee.MiddleName   = model.MiddleName;
                newEmployee.PhoneNumber  = model.PhoneNumber;
                newEmployee.EmailAddress = model.EmailAddress;
                newEmployee.Gender       = model.Gender;
                newEmployee.PositionID   = model.PositionID;
                newEmployee.DepartmentID = model.DepartmentID;

                if (model.Status_booleanVal)
                {
                    newEmployee.Status = 1;
                }
                else
                {
                    newEmployee.Status = 0;
                }

                if (model.CompanyName != null)
                {
                    newEmployee.IsCompany   = 1;
                    newEmployee.CompanyName = model.CompanyName;
                }

                EmployeeProcess employeeProcess = new EmployeeProcess();

                int result = employeeProcess.Add(newEmployee);

                if (result == FASTConstant.RETURN_VAL_SUCCESS)
                {
                    TempData[FASTConstant.TMPDATA_RESULT]       = FASTConstant.SUCCESSFUL;
                    TempData[FASTConstant.TMPDATA_SOURCE]       = "Add New Employee";
                    TempData[FASTConstant.TMPDATA_EXTRAMESSAGE] = "The new employee has been added to the database.";
                    TempData[FASTConstant.TMPDATA_ACTION]       = "Index";
                    TempData[FASTConstant.TMPDATA_CONTROLLER]   = "Employee";

                    return(View("~/Views/Shared/Result.cshtml"));
                }
                else
                {
                    throw new Exception("There was an error while adding the new employee.");
                }
            }
            catch (Exception ex)
            {
                TempData[FASTConstant.TMPDATA_RESULT]       = FASTConstant.FAILURE;
                TempData[FASTConstant.TMPDATA_SOURCE]       = "Add New Employee";
                TempData[FASTConstant.TMPDATA_EXTRAMESSAGE] = ex.Message;
                return(View("~/Views/Shared/Result.cshtml"));
            }
        }
示例#2
0
        public ActionResult MyAssets()
        {
            AssignmentProcess assignProcess   = new AssignmentProcess();
            EmployeeProcess   employeeProcess = new EmployeeProcess();

            ViewBag.Assignments = assignProcess.GetCurrentAssignmentsByEmployeeID(User.Identity.Name.ToInteger());
            ViewBag.Acceptances = assignProcess.GetAssignmentsForAcceptanceByEmployeeID(User.Identity.Name.ToInteger());
            ViewBag.History     = assignProcess.GetAllAssignmentsByEmployeeID(User.Identity.Name.ToInteger());

            return(View(employeeProcess.GetEmployeeProfileByID(User.Identity.Name.ToInteger())));
        }
        public ActionResult MyAssetHistoryReport()
        {
            AssignmentProcess assignProcess   = new AssignmentProcess();
            EmployeeProcess   employeeProcess = new EmployeeProcess();

            int employeeID = User.Identity.Name.ToInteger();

            ViewBag.Employee = employeeProcess.GetEmployeeProfileByID(employeeID);
            ViewBag.Assets   = assignProcess.GetAllAssignmentsByEmployeeID(employeeID);

            return(View());
        }
        private string GetEmployee(int employeeID)
        {
            if (employeeID > 0)
            {
                EmployeeProcess process = new EmployeeProcess();

                Common.Employee employee = process.GetByID(employeeID);

                return(String.Format("{0} , {1} {2}", employee.LastName, employee.FirstName, employee.MiddleName));
            }

            return(String.Empty);
        }
        public ActionResult Index()
        {
            EmployeeProcess             employeeProcess = new EmployeeProcess();
            IQueryable <vwEmployeeList> list            = employeeProcess.GetEmployeeProfiles();

            int departmentID = 0;

            if (Session["Department"] != null)
            {
                if (Int32.TryParse(Session["Department"].ToString(), out departmentID))
                {
                    list = employeeProcess.GetEmployeeProfiles().Where(i => i.DepartmentID == departmentID);
                }
            }

            TempData["Employees"] = list.ToList();

            return(View(list.ToList()));
        }
        public ActionResult EditEmployee(int mod)
        {
            GenericProcess <Department> deptProcess     = new GenericProcess <Department>();
            GenericProcess <Position>   positionProcess = new GenericProcess <Position>();
            EmployeeProcess             employeeProcess = new EmployeeProcess();

            ViewBag.Departments = deptProcess.GetAll().ToList();
            ViewBag.Positions   = positionProcess.GetAll().ToList();

            int employeeID = mod;

            FASTWeb.Models.EmployeeViewModel employeeEditView =
                new EmployeeViewModel();

            Employee employeeToEdit = employeeProcess.GetEmployeeByID(employeeID);

            //move data to editview
            employeeEditView.EmployeeID   = employeeToEdit.EmployeeID;
            employeeEditView.FirstName    = employeeToEdit.FirstName;
            employeeEditView.MiddleName   = employeeToEdit.MiddleName;
            employeeEditView.LastName     = employeeToEdit.LastName;
            employeeEditView.EmailAddress = employeeToEdit.EmailAddress;
            employeeEditView.PhoneNumber  = employeeToEdit.PhoneNumber;
            employeeEditView.Gender       = employeeToEdit.Gender;
            employeeEditView.PositionID   = employeeToEdit.PositionID;
            employeeEditView.DepartmentID = employeeToEdit.DepartmentID;
            employeeEditView.IsCompany    = employeeToEdit.IsCompany;
            employeeEditView.CompanyName  = employeeToEdit.CompanyName;
            employeeEditView.Status       = employeeToEdit.Status;

            if (employeeToEdit.Status == 1)
            {
                employeeEditView.Status_booleanVal = true;
            }
            else
            {
                employeeEditView.Status_booleanVal = false;
            }

            return(View(employeeEditView));
        }
        public ActionResult SearchEmployeeRights(int employeeID)
        {
            EmployeeProcess empProcess = new EmployeeProcess();
            vwEmployeeList  employee   = empProcess.GetEmployeeProfileByID(employeeID);

            GenericProcess <vwAccessRight> accessProcess = new GenericProcess <vwAccessRight>();
            List <vwAccessRight>           rights        = accessProcess.GetAll().Where(i => i.EmployeeID == employeeID).ToList();

            GenericProcess <AccessLevel>      levels      = new GenericProcess <AccessLevel>();
            GenericProcess <vwDepartmentList> departments = new GenericProcess <vwDepartmentList>();

            ViewBag.EmployeeID  = employeeID;
            ViewBag.AccessLevel = levels.GetAll().ToList();
            ViewBag.Department  = departments.GetAll().ToList();



            ViewBag.Rights = rights;

            return(View("NewAccessRight", employee));
        }
        public ActionResult ShowDepartmentEmployee(int departmentID)
        {
            EmployeeProcess employeeProcess = new EmployeeProcess();
            GenericProcess <Common.vwDepartmentList> deptProcess =
                new GenericProcess <Common.vwDepartmentList>();

            List <vwEmployeeList> listOfEmployees = new List <vwEmployeeList>();
            vwDepartmentList      department      = new vwDepartmentList();

            try
            {
                listOfEmployees = employeeProcess.GetEmployeesByDepartmentID(departmentID);

                department = deptProcess.GetAll().Where(i => i.DepartmentID == departmentID).First();
            }
            catch { }

            ViewBag.Department = department.GroupName;

            return(View("Index", listOfEmployees));
        }
示例#9
0
        public ActionResult UploadFile()
        {
            ExcelHelper excelHelp = new ExcelHelper();
            List <FixAssetExcelUploadModel> assets = new List <FixAssetExcelUploadModel>();
            BulkUpload           currentUpload     = new Common.BulkUpload();
            BulkUploadProcess    bulkProcess       = new BulkUploadProcess();
            AssetProcess         assetProcess      = new AssetProcess();
            EmployeeProcess      employeeProcess   = new EmployeeProcess();
            Employee             sender            = new Employee();
            ConfigurationProcess configProcess     = new ConfigurationProcess();

            FastEmailConfiguration emailConfig = configProcess.GetEmailConfiguration();

            StringBuilder uploadLog = new StringBuilder();

            string filename         = string.Empty;
            string completeFileName = string.Empty;

            //This is for the logging
            bulkProcess.UserID     = User.Identity.Name.ToInteger();
            configProcess.UserID   = User.Identity.Name.ToInteger();
            employeeProcess.UserID = User.Identity.Name.ToInteger();
            assetProcess.UserID    = User.Identity.Name.ToInteger();


            try
            {
                #region Get Request Files
                foreach (string upload in Request.Files)
                {
                    if (!(Request.Files[upload] != null && Request.Files[upload].ContentLength > 0))
                    {
                        continue;
                    }
                    string path = HttpContext.Server.MapPath("\\App_Data\\BulkUploads");
                    filename = Path.GetFileName(Request.Files[upload].FileName);

                    //check the filename and ensure its an xlsx file
                    if (String.Compare(filename.Substring(filename.Length - 4), "xlsx", true) != 0)
                    {
                        throw new Exception("Invalid file extension.");
                    }

                    //add the current time as unique indicator
                    filename = DateTime.Now.ToFileTime().ToString() + "_" + filename;

                    // If Upload folder is not yet existing, this code will create that directory.
                    if (!System.IO.Directory.Exists(path))
                    {
                        System.IO.Directory.CreateDirectory(path);
                    }
                    completeFileName = Path.Combine(path, filename);
                    Request.Files[upload].SaveAs(completeFileName);
                }
                #endregion

                BulkUpload newFile = new BulkUpload()
                {
                    EmployeeID   = User.Identity.Name.ToInteger(),
                    FilePath     = filename,
                    TotalRecords = 0,
                    TotalInserts = 0,
                    RequestDate  = DateTime.Now,
                    Type         = FASTConstant.BULKIPLOAD_TYPE_ASSET
                };

                if (bulkProcess.Add(newFile) == FASTConstant.RETURN_VAL_SUCCESS)
                {
                    //get the current upload
                    currentUpload = bulkProcess.GetCurrentUpload(newFile.FilePath, newFile.EmployeeID);
                }

                if (currentUpload != null)
                {
                    #region Process the excel file
                    //Success! Lets process the file.
                    System.Data.DataTable fixAssetTable = new DataTable();

                    fixAssetTable = excelHelp.GetExcelDataTable(completeFileName, "SELECT * FROM [FixAsset$]");
                    fixAssetTable = excelHelp.ConvertToFixAssetTable(fixAssetTable);

                    if (fixAssetTable == null)
                    {
                        throw new Exception("The upload file contains null data.");
                    }

                    assets = fixAssetTable.ToList <Models.FixAssetExcelUploadModel>();
                    sender = employeeProcess.GetEmployeeByID(currentUpload.EmployeeID);

                    if (assets.Count > 0)
                    {
                        int totalInserts = 0;
                        currentUpload.TotalRecords = assets.Count;

                        bulkProcess.UpdateProcessingStep(currentUpload, FASTConstant.BULKUPLOAD_STATUS_INPROGRESS);

                        foreach (FixAssetExcelUploadModel asset in assets)
                        {
                            FixAsset tempAsset = new FixAsset()
                            {
                                AssetTag        = asset.AssetTag,
                                SerialNumber    = asset.SerialNumber,
                                Model           = asset.Model,
                                Brand           = asset.Brand,
                                AssetClassID    = asset.AssetClassID,
                                AssetTypeID     = asset.AssetTypeID,
                                AssetStatusID   = asset.AssetStatusID,
                                AcquisitionDate = asset.AcquisitionDate
                            };


                            if (assetProcess.Add(tempAsset) == FASTConstant.RETURN_VAL_SUCCESS)
                            {
                                totalInserts++;
                                uploadLog.AppendLine(String.Format("<p>{0} : {1} inserted.</p>", FASTConstant.SUCCESSFUL, asset.AssetTag));
                            }
                            else
                            {
                                uploadLog.AppendLine(String.Format("<p>{0} : {1} not inserted.</p>", FASTConstant.FAILURE, asset.AssetTag));
                            }
                        }

                        currentUpload.TotalInserts = totalInserts;
                        bulkProcess.UpdateProcessingStep(currentUpload, FASTConstant.BULKUPLOAD_STATUS_DONE);


                        //Send email to the requestor
                        FastEmail email = new FastEmail();
                        email.Receipients = new List <string>()
                        {
                            sender.EmailAddress
                        };
                        email.Subject  = FASTConstant.EMAIL_SIMPLE_SUBJECT.Replace("[XXX]", "Fix Asset Bulk Upload Result");
                        email.HTMLBody = FASTProcess.Helper.EmailHelper.GenerateHTMLBody(FASTProcess.Helper.EmailHelper.EmailType.BULK_UPLOAD);

                        email.HTMLBody = email.HTMLBody.Replace(FASTConstant.EMAIL_RECEIPIENT_NAME, sender.FirstName + " " + sender.LastName);
                        email.HTMLBody = email.HTMLBody.Replace(FASTConstant.EMAIL_BULKUPLOAD_INFO, bulkProcess.GenerateUploadinformationHTML(currentUpload));
                        email.HTMLBody = email.HTMLBody.Replace(FASTConstant.EMAIL_BULKUPLOAD_LOG, uploadLog.ToString());
                        email.HTMLBody = email.HTMLBody.Replace(FASTConstant.EMAIL_BULKUPLOAD_SUMMARY, bulkProcess.GenerateSummaryinformationHTML(currentUpload));

                        SMTPEmail emailSender = new SMTPEmail(emailConfig, email);
                        emailSender.SendEmail();
                    }
                    else
                    {
                        bulkProcess.UpdateProcessingStep(currentUpload, FASTConstant.BULKUPLOAD_STATUS_DONE);
                    }
                    #endregion
                }

                TempData["Result"]       = "SUCCESSFUL";
                TempData["Source"]       = "File Upload";
                TempData["ExtraMessage"] = "An email will be sent to you containing the results of the upload process.";
                TempData["Action"]       = "Index";
                TempData["Controller"]   = "FixAsset";

                return(View("~/Views/Shared/Result.cshtml"));
            }
            catch (Exception ex)
            {
                TempData["Result"]       = "FAILURE";
                TempData["Source"]       = "Fix Asset Bulk Upload";
                TempData["ExtraMessage"] = ex.Message;
                return(View("~/Views/Shared/Result.cshtml"));
            }
        }