Example #1
0
        //[ValidateAntiForgeryToken]
        ///<summary>
        /// Retrieves form for the given absence selected
        /// </summary>
        public ActionResult UpdateAbsenceEntry(IAbsenceDO iAbsence, int pointBankID)
        {
            ActionResult oResponse = null;
            var          userPO    = (IUserPO)Session["UserModel"];

            if (userPO.Email != null && userPO.RoleID_FK >= (int)RoleEnum.Administrator && userPO.RoleID_FK <= (int)RoleEnum.Team_Lead)
            {
                var absenceVM = new AbsenceViewModel();

                // Retrieve selected absence
                var absenceDO = PointsDataAccess.GetAbsenceByID(pointBankID);
                ViewBag.Name = "Modify Employee Absence";

                // Maps absence DO to PO
                absenceVM.Absence = AbsenceMapper.MapAbsenceDOtoPO(absenceDO);

                oResponse = View(absenceVM);
            }
            else
            {
                // User doesn't have priveleges redirect home
                oResponse = RedirectToAction("Index", "Home");
            }

            return(oResponse);
        }
Example #2
0
        public IAbsenceDO UpdateAbsenceType(IAbsenceDO iAbsence, int ModifiedByUserID)
        {
            try
            {
                using (SqlConnection conn = new SqlConnection(_ConnectionString))
                {
                    using (SqlCommand updateComm = new SqlCommand("sp_UpdateAttendanceTypeById", conn))
                    {
                        try
                        {
                            updateComm.Parameters.AddWithValue("@AttendanceTypeId", SqlDbType.Int).Value = iAbsence.AbsenceTypeID;
                            updateComm.Parameters.AddWithValue("@ModifiedByUserId", SqlDbType.Int).Value = ModifiedByUserID;
                            updateComm.Parameters.AddWithValue("@Name", SqlDbType.VarChar).Value         = iAbsence.Name;
                            updateComm.Parameters.AddWithValue("@Point", SqlDbType.Decimal).Value        = iAbsence.Point;

                            return(iAbsence);
                        }
                        catch (Exception ex)
                        {
                            ErrorLogger.LogError(ex, "UpdateAbsenceType", "nothing");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LogError(ex, "UpdateAbsenceType", "nothing");
            }
            return(iAbsence);
        }
Example #3
0
        ///<summary>
        /// Sends the form to the database to be modified for an absence
        /// </summary>
        public ActionResult UpdateAbsenceEntry(AbsenceViewModel iViewModel, int userID)
        {
            ActionResult oResponse = null;
            var          userPO    = (IUserPO)Session["UserModel"];

            // Ensure user has priveleges
            if (userPO.Email != null && userPO.RoleID_FK >= (int)RoleEnum.Administrator && userPO.RoleID_FK <= (int)RoleEnum.Team_Lead)
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        // Map absence from PO to DO
                        IAbsenceDO lAbsenceForm = AbsenceMapper.MapAbsencePOtoDO(iViewModel.Absence);

                        // Passes form to data access to update the database
                        PointsDataAccess.UpdateAbsenceInformation(lAbsenceForm, userPO.UserID);

                        // Determine redirect based off role
                        switch (userPO.RoleID_FK)
                        {
                        case 1:
                            oResponse = RedirectToAction("ViewAllAbsenceEntries", "Maint");
                            break;

                        case 2:
                            oResponse = RedirectToAction("ViewAllAbsencesForSMTeam", "Maint");
                            break;

                        case 3:
                            oResponse = RedirectToAction("ViewAbsencesByTeamID", "Maint");
                            break;

                        default:
                            oResponse = RedirectToAction("Index", "Home");
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        ErrorLogger.LogError(ex, "UpdateAbsenceEntry", "Maint");
                        iViewModel.ErrorMessage = "Something went wrong updating the absence entry. Please try again.";
                        oResponse = View(iViewModel);
                    }
                }
                else
                {
                    oResponse = View(iViewModel);
                }
            }
            else
            {
                oResponse = RedirectToAction("Index", "Home");
            }

            return(oResponse);
        }
Example #4
0
        public string CreateAbsenceType(IAbsenceDO absence, int userID)
        {
            string result;

            try
            {
                using (SqlConnection connection = new SqlConnection(_ConnectionString))
                {
                    using (SqlCommand command = new SqlCommand("sp_TeamAddNew", connection))
                    {
                        try
                        {
                            command.CommandType    = CommandType.StoredProcedure;
                            command.CommandTimeout = 35;

                            command.Parameters.AddWithValue("@AbsenceTypeID", SqlDbType.Int).Value     = absence.AbsenceTypeID;
                            command.Parameters.AddWithValue("@AbsenceName", SqlDbType.VarChar).Value   = absence.Name;
                            command.Parameters.AddWithValue("@Point", SqlDbType.Decimal).Value         = absence.Point;
                            command.Parameters.AddWithValue("@Active", SqlDbType.Int).Value            = absence.Active;
                            command.Parameters.AddWithValue("@TeamID_FK", SqlDbType.Int).Value         = absence.TeamID_FK;
                            command.Parameters.AddWithValue("@CreateDate", SqlDbType.DateTime).Value   = absence.AbsenceDate;
                            command.Parameters.AddWithValue("@CreateUser_FK", SqlDbType.Int).Value     = userID;
                            command.Parameters.AddWithValue("@ModifiedDate", SqlDbType.DateTime).Value = DateTime.Now;
                            command.Parameters.AddWithValue("@ModifiedUser_FK", SqlDbType.Int).Value   = userID;
                            command.ExecuteNonQuery();

                            result = "Success";
                        }
                        catch (Exception ex)
                        {
                            ErrorLogger.LogError(ex, "CreateAbsenceType", "nothing");
                            result = "fail";
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ErrorLogger.LogError(e, "CreateAbsenceType", "nothing");
                result = "fail";
            }

            return(result);
        }
        public static void AddAbsence(IAbsenceDO iAbsence, int createdBy)
        {
            try
            {
                using (SqlConnection conn = new SqlConnection(_ConnectionString))
                {
                    using (SqlCommand command = new SqlCommand("sp_PointsAddNew", conn))
                    {
                        try
                        {
                            command.CommandType    = CommandType.StoredProcedure;
                            command.CommandTimeout = 15;

                            command.Parameters.AddWithValue("@AbsenceTypeID", iAbsence.AbsenceTypeID);
                            command.Parameters.AddWithValue("@TeamID", iAbsence.TeamID_FK);
                            command.Parameters.AddWithValue("@AbsentUserID", iAbsence.AbsentUserID);
                            command.Parameters.AddWithValue("@Comments", iAbsence.Comments);
                            command.Parameters.AddWithValue("@CreateUserID", createdBy);
                            command.Parameters.AddWithValue("@AbsenceDate", iAbsence.AbsenceDate);

                            conn.Open();
                            command.ExecuteNonQuery();
                        }
                        catch (Exception ex)
                        {
                            ErrorLogger.LogError(ex, "AddAbsence", "nothing");
                        }
                        finally
                        {
                            conn.Close();
                            conn.Dispose();
                            command.Dispose();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LogError(ex, "AddAbsence", "");
            }
        }
        public static void UpdateAbsenceInformation(IAbsenceDO iAbsence, int updatedBy)
        {
            try
            {
                using (SqlConnection conn = new SqlConnection(_ConnectionString))
                {
                    using (SqlCommand updateComm = new SqlCommand("sp_PointsUpdate", conn))
                    {
                        try
                        {
                            updateComm.CommandType    = CommandType.StoredProcedure;
                            updateComm.CommandTimeout = 35;

                            updateComm.Parameters.AddWithValue("@AbsenceTypeID", iAbsence.AbsenceTypeID);
                            updateComm.Parameters.AddWithValue("@@TeamMgtID", iAbsence.TeamMgtID);
                            updateComm.Parameters.AddWithValue("@AbsentUserID", iAbsence.AbsentUserID);
                            updateComm.Parameters.AddWithValue("@AbsenceDate", iAbsence.AbsenceDate);
                            updateComm.Parameters.AddWithValue("@UpdatedUserID", updatedBy);
                            updateComm.Parameters.AddWithValue("@Active", iAbsence.Active);

                            conn.Open();
                            updateComm.ExecuteNonQuery();
                        }
                        catch (Exception ex)
                        {
                            ErrorLogger.LogError(ex, "UdpateAbsenceInformation", "nothing");
                        }
                        finally
                        {
                            conn.Close();
                            conn.Dispose();
                            updateComm.Dispose();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LogError(ex, "UdpateAbsenceInformation", "");
            }
        }
Example #7
0
        ///<summary>
        /// Sends the absence form to the database to be added
        /// </summary>
        /// <returns></returns>
        public ActionResult AddAbsenceEntry(AbsenceViewModel iViewModel)
        {
            ActionResult oResponse = null;
            var          userPO    = (IUserPO)Session["UserModel"];

            // User is authenticated(Admin, Service Manager or Team Lead)
            if (userPO.Email != null && userPO.RoleID_FK < (int)RoleEnum.Service_Desk_Employee && userPO.RoleID_FK >= (int)RoleEnum.Administrator)
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        var absenceTypes   = _AbsenceDataAccess.GetAllAbsenceTypes();
                        var absenceTypePOs = AbsenceMapper.MapListOfDOsToListOfPOs(absenceTypes);

                        // Maps absence PO to DO during creation
                        IAbsenceDO lAbsenceForm = AbsenceMapper.MapAbsencePOtoDO(iViewModel.Absence);
                        var        absenceType  = absenceTypePOs.Where(at => at.AbsenceTypeID == iViewModel.Absence.AbsenceTypeID);
                        // Passes form to data access to add event to db
                        PointsDataAccess.AddAbsence(lAbsenceForm, userPO.UserID);
                        oResponse = RedirectToAction("ViewAllAbsence", "Maint");
                    }
                    catch (Exception ex)
                    {
                        ErrorLogger.LogError(ex, "AddAbsenceEntry", "Maint");
                        iViewModel.ErrorMessage = "Something went wrong when creating the absence to the system. Please try again.";
                    }
                }
                else
                {
                    oResponse = View(iViewModel);
                }
            }
            else
            {
                // User doesn't have privileges to create an absense entry, redirect to home.
                oResponse = RedirectToAction("Index", "Home");
            }

            return(oResponse);
        }
        public static AbsencePO MapAbsenceDOtoPO(IAbsenceDO absenceDO)
        {
            var oAbsence = new AbsencePO();

            oAbsence.AbsenceTypeID = absenceDO.AbsenceTypeID;
            oAbsence.Name          = absenceDO.Name;
            oAbsence.TeamName      = absenceDO.TeamName;
            oAbsence.Point         = absenceDO.Point;
            oAbsence.Active        = absenceDO.Active;
            oAbsence.TeamID_FK     = absenceDO.TeamID_FK;
            oAbsence.AbsenceDate   = absenceDO.AbsenceDate;
            oAbsence.AbsentUserID  = absenceDO.AbsentUserID;
            oAbsence.Comments      = absenceDO.Comments;
            oAbsence.RunningTotal  = absenceDO.RunningTotal;
            oAbsence.TeamMgtID     = absenceDO.TeamMgtID;
            oAbsence.EmployeeName  = absenceDO.EmployeeName;
            oAbsence.PointBankID   = absenceDO.PointBankID;
            oAbsence.AbsenceType   = absenceDO.AbsenceType;

            return(oAbsence);
        }