Пример #1
0
        public IHttpActionResult Put(ScorecardItem scorecardRequest)
        {
            if (!User.IsInRole(NDMSSecurityConstants.AdminRole))
            {
                var canEditScorecard = userManager.IsUserKPIOwnerOfParentScorecard(Username, scorecardRequest.Id.Value);
                if (!canEditScorecard)
                {
                    return(Unauthorized());
                }
            }

            CheckModelState();
            if (!scorecardAdminMgr.UpdateScorecard(scorecardRequest, Username))
            {
                return(NotFound());
            }
            return(Ok());
        }
Пример #2
0
        /// <summary>
        /// Update an existing scorecard
        /// </summary>
        /// <param name="scorecardRequest">scorecard details object</param>
        /// <param name="updatedKPIOwnerIds">Updated KPI Owner Id's</param>
        /// <param name="updatedTeamIds">Updated Team Member Id's</param>
        /// <param name="userName">logged in user name</param>
        /// <returns>flag which says whether update is successful or not</returns>
        public bool UpdateScorecard(ScorecardItem scorecardRequest, List <int> updatedKPIOwnerIds,
                                    List <int> updatedTeamIds, string userName)
        {
            int loggedInUserId = Context.Users.FirstOrDefault(
                x => x.AccountName == userName).Id;
            var existingScorecard = Context.Scorecards
                                    .Include(x => x.KPIOwners)
                                    .Include(x => x.Teams)
                                    .Include(x => x.KPIs)
                                    .Include(x => x.ScorecardWorkdayPatterns)
                                    .Single(c => c.Id == scorecardRequest.Id);

            if (existingScorecard == null)
            {
                return(false);
            }

            existingScorecard.Name     = scorecardRequest.Name;
            existingScorecard.IsActive = scorecardRequest.IsActive;
            existingScorecard.IsBowlingChartApplicable = scorecardRequest.IsBowlingChartApplicable;
            existingScorecard.DrilldownLevel           = scorecardRequest.DrilldownLevel;
            // existingScorecard.ProductLineId = scorecardRequest.ProductLine.Id.Value;
            // existingScorecard.DepartmentId = scorecardRequest.Department.Id.Value;
            //existingScorecard.ProcessId = scorecardRequest.Process.Id.Value;
            existingScorecard.LastModifiedBy = loggedInUserId;
            existingScorecard.LastModifiedOn = TimeZoneUtility.GetCurrentTimestamp();

            // Fetching existing scorecard teams and Kpi Owners from Context directly
            // This is to update deactivated on and IsActive flag
            var existingKPIOwners = existingScorecard.KPIOwners
                                    .Where(owner => owner.ScorecardId == scorecardRequest.Id && owner.IsActive);
            var existingTeams = existingScorecard.Teams
                                .Where(team => team.ScorecardId == scorecardRequest.Id && team.IsActive);

            foreach (var owner in existingKPIOwners)
            {
                // Deactivating the kpi owners which are not present in update list
                if (!updatedKPIOwnerIds.Any(id => id == owner.UserId))
                {
                    owner.DeactivatedOn = TimeZoneUtility.GetCurrentTimestamp();
                    owner.IsActive      = false;
                }
            }
            foreach (var team in existingTeams)
            {
                // Deactivating the teams which are not present in update list
                if (!updatedTeamIds.Any(id => id == team.UserId))
                {
                    team.DeactivatedOn = TimeZoneUtility.GetCurrentTimestamp();
                    team.IsActive      = false;
                }
            }

            // Find the  newly added KPI owners for this score card
            var newKPIOwnerIDs = updatedKPIOwnerIds.Except(existingKPIOwners.
                                                           Select(x => x.UserId)).ToList();

            foreach (var kpiOwnerID in newKPIOwnerIDs)
            {
                // If the new KPI owner were part of this scorecard long back, we just need to update entries
                var kpiOwner = existingScorecard.KPIOwners.Where(x => x.ScorecardId == scorecardRequest.Id &&
                                                                 x.UserId == kpiOwnerID).FirstOrDefault();
                if (kpiOwner != null)
                {
                    kpiOwner.IsActive      = true;
                    kpiOwner.DeactivatedOn = null;
                    kpiOwner.AssignedOn    = TimeZoneUtility.GetCurrentTimestamp();
                }
                else
                {
                    if (existingScorecard.KPIOwners == null)
                    {
                        existingScorecard.KPIOwners = new List <ScorecardKPIOwner>();
                    }
                    // Adding an entirely new KPI owner
                    existingScorecard.KPIOwners.Add(new ScorecardKPIOwner
                    {
                        UserId      = kpiOwnerID,
                        AssignedOn  = TimeZoneUtility.GetCurrentTimestamp(),
                        Scorecard   = existingScorecard,
                        ScorecardId = existingScorecard.Id,
                        IsActive    = true
                    });
                }
            }

            // Find the  newly added teams for this score card
            var newScorecardTeamIDs = updatedTeamIds.Except(existingTeams.Select(x => x.UserId)).ToList();

            foreach (var teamID in newScorecardTeamIDs)
            {
                var teamUser = existingScorecard.Teams.Where(x => x.ScorecardId == scorecardRequest.Id &&
                                                             x.UserId == teamID).FirstOrDefault();
                if (teamUser != null)
                {
                    teamUser.IsActive      = true;
                    teamUser.DeactivatedOn = null;
                    teamUser.AssignedOn    = TimeZoneUtility.GetCurrentTimestamp();
                }
                else
                {
                    if (existingScorecard.Teams == null)
                    {
                        existingScorecard.Teams = new List <ScorecardTeam>();
                    }
                    existingScorecard.Teams.Add(new ScorecardTeam
                    {
                        UserId      = teamID,
                        AssignedOn  = TimeZoneUtility.GetCurrentTimestamp(),
                        Scorecard   = existingScorecard,
                        ScorecardId = existingScorecard.Id,
                        IsActive    = true
                    });
                }
            }

            // Update KPI's of score card
            List <KPI> updatedKpiEntityList = new List <KPI>();

            foreach (var kpi in scorecardRequest.KPIs)
            {
                updatedKpiEntityList.Add(Context.KPIs.Find(kpi.Id));
            }
            // First clear the existing ones
            if (existingScorecard.KPIs != null)
            {
                existingScorecard.KPIs.Clear();
            }
            else
            {
                existingScorecard.KPIs = new List <KPI>();
            }
            foreach (KPI kpi in updatedKpiEntityList)
            {
                // Add kpi in existing scorecard's kpi collection
                existingScorecard.KPIs.Add(kpi);
            }

            // Update business segments of scorecard
            List <BusinessSegment> updatedBusinessSegmentEntityList = new List <BusinessSegment>();

            if (scorecardRequest.BusinessSegments.Any(x => x.Id == 0))
            {
                updatedBusinessSegmentEntityList.Add(Context.BusinessSegments.Find(0));
            }
            else
            {
                foreach (var businessSegment in scorecardRequest.BusinessSegments)
                {
                    updatedBusinessSegmentEntityList.Add(Context.BusinessSegments.Find(businessSegment.Id));
                }
            }
            // First clear the existing ones
            if (existingScorecard.BusinessSegments != null)
            {
                existingScorecard.BusinessSegments.Clear();
            }
            else
            {
                existingScorecard.BusinessSegments = new List <BusinessSegment>();
            }
            foreach (BusinessSegment businessSegment in updatedBusinessSegmentEntityList)
            {
                // Add business segment in existing scorecard's business segment collection
                existingScorecard.BusinessSegments.Add(businessSegment);
            }

            // Update Divisions of scorecard
            List <Division> updatedDivisionEntityList = new List <Division>();

            if (scorecardRequest.Divisions.Any(x => x.Id == 0))
            {
                updatedDivisionEntityList.Add(Context.Divisions.Find(0));
            }
            else
            {
                foreach (var division in scorecardRequest.Divisions)
                {
                    updatedDivisionEntityList.Add(Context.Divisions.Find(division.Id));
                }
            }
            // First clear the existing ones
            if (existingScorecard.Divisions != null)
            {
                existingScorecard.Divisions.Clear();
            }
            else
            {
                existingScorecard.Divisions = new List <Division>();
            }
            foreach (Division division in updatedDivisionEntityList)
            {
                // Add divisions in existing scorecard's division collection
                existingScorecard.Divisions.Add(division);
            }

            // Update Facilities of scorecard
            List <Facility> updatedFacilityEntityList = new List <Facility>();

            if (scorecardRequest.Facilities.Any(x => x.Id == 0))
            {
                updatedFacilityEntityList.Add(Context.Facilities.Find(0));
            }
            else
            {
                foreach (var facility in scorecardRequest.Facilities)
                {
                    updatedFacilityEntityList.Add(Context.Facilities.Find(facility.Id));
                }
            }
            // First clear the existing ones
            if (existingScorecard.Facilities != null)
            {
                existingScorecard.Facilities.Clear();
            }
            else
            {
                existingScorecard.Facilities = new List <Facility>();
            }
            foreach (Facility facility in updatedFacilityEntityList)
            {
                // Add Facility in existing scorecard's facility collection
                existingScorecard.Facilities.Add(facility);
            }

            // Update Product Lines of scorecard
            List <ProductLine> updatedProductLineEntityList = new List <ProductLine>();

            if (scorecardRequest.ProductLines.Any(x => x.Id == 0))
            {
                updatedProductLineEntityList.Add(Context.ProductLines.Find(0));
            }
            else
            {
                foreach (var productLine in scorecardRequest.ProductLines)
                {
                    updatedProductLineEntityList.Add(Context.ProductLines.Find(productLine.Id));
                }
            }
            // First clear the existing ones
            if (existingScorecard.ProductLines != null)
            {
                existingScorecard.ProductLines.Clear();
            }
            else
            {
                existingScorecard.ProductLines = new List <ProductLine>();
            }
            foreach (ProductLine productline in updatedProductLineEntityList)
            {
                // Add Product Lines in existing scorecard's Product Line collection
                existingScorecard.ProductLines.Add(productline);
            }
            // Update Departments of scorecard
            List <Department> updatedDepartmentEntityList = new List <Department>();

            if (scorecardRequest.Departments.Any(x => x.Id == 0))
            {
                updatedDepartmentEntityList.Add(Context.Departments.Find(0));
            }
            else
            {
                foreach (var department in scorecardRequest.Departments)
                {
                    updatedDepartmentEntityList.Add(Context.Departments.Find(department.Id));
                }
            }
            // First clear the existing ones
            if (existingScorecard.Departments != null)
            {
                existingScorecard.Departments.Clear();
            }
            else
            {
                existingScorecard.Departments = new List <Department>();
            }
            foreach (Department department in updatedDepartmentEntityList)
            {
                // Add departments in existing scorecard's department collection
                existingScorecard.Departments.Add(department);
            }

            // Update Processes of scorecard
            List <Process> updatedProcessEntityList = new List <Process>();

            if (scorecardRequest.Processes.Any(x => x.Id == 0))
            {
                updatedProcessEntityList.Add(Context.Processes.Find(0));
            }
            else
            {
                foreach (var process in scorecardRequest.Processes)
                {
                    updatedProcessEntityList.Add(Context.Processes.Find(process.Id));
                }
            }
            // First clear the existing ones
            if (existingScorecard.Processes != null)
            {
                existingScorecard.Processes.Clear();
            }
            else
            {
                existingScorecard.Processes = new List <Process>();
            }
            foreach (Process process in updatedProcessEntityList)
            {
                // Add processes in existing scorecard's process collection
                existingScorecard.Processes.Add(process);
            }

            DateTime currentDate = TimeZoneUtility.GetCurrentTimestamp().Date;
            DateTime EndDate     = new DateTime(currentDate.Year, currentDate.Month, DateTime.DaysInMonth(currentDate.Year, currentDate.Month));

            //Scorecard Workday Pattern
            if (scorecardRequest.ScorecardWorkdayPattern != null)
            {
                if (scorecardRequest.ActiveScorecardWorkdayPattern != null && scorecardRequest.ScorecardWorkdayPattern != null)
                {
                    if (scorecardRequest.ActiveScorecardWorkdayPattern.EffectiveStartDate.Date == scorecardRequest.ScorecardWorkdayPattern.EffectiveStartDate.Date)
                    {
                        ScorecardWorkdayPattern scorecardWorkdayPatternExisting = existingScorecard.ScorecardWorkdayPatterns.Where(x => x.Id == scorecardRequest.ScorecardWorkdayPattern.Id).FirstOrDefault();
                        scorecardWorkdayPatternExisting.LastModifiedBy   = loggedInUserId;
                        scorecardWorkdayPatternExisting.LastModifiedOn   = TimeZoneUtility.GetCurrentTimestamp();
                        scorecardWorkdayPatternExisting.EffectiveEndDate = EndDate.Date;
                        existingScorecard.ScorecardWorkdayPatterns.Add(scorecardWorkdayPatternExisting);

                        ScorecardWorkdayPattern scorecardWorkdayPatternNew = new ScorecardWorkdayPattern();

                        scorecardWorkdayPatternNew.ScorecardId    = scorecardRequest.ScorecardWorkdayPattern.ScorecardId;
                        scorecardWorkdayPatternNew.IsSunday       = scorecardRequest.ScorecardWorkdayPattern.IsSunday;
                        scorecardWorkdayPatternNew.IsMonday       = scorecardRequest.ScorecardWorkdayPattern.IsMonday;
                        scorecardWorkdayPatternNew.IsTuesday      = scorecardRequest.ScorecardWorkdayPattern.IsTuesday;
                        scorecardWorkdayPatternNew.IsWednesday    = scorecardRequest.ScorecardWorkdayPattern.IsWednesday;
                        scorecardWorkdayPatternNew.IsThursday     = scorecardRequest.ScorecardWorkdayPattern.IsThursday;
                        scorecardWorkdayPatternNew.IsFriday       = scorecardRequest.ScorecardWorkdayPattern.IsFriday;
                        scorecardWorkdayPatternNew.IsSaturday     = scorecardRequest.ScorecardWorkdayPattern.IsSaturday;
                        scorecardWorkdayPatternNew.CreatedOn      = TimeZoneUtility.GetCurrentTimestamp();
                        scorecardWorkdayPatternNew.CreatedBy      = loggedInUserId;
                        scorecardWorkdayPatternNew.LastModifiedOn = TimeZoneUtility.GetCurrentTimestamp();
                        scorecardWorkdayPatternNew.LastModifiedBy = loggedInUserId;

                        scorecardWorkdayPatternNew.EffectiveStartDate = EndDate.AddDays(1).Date;
                        existingScorecard.ScorecardWorkdayPatterns.Add(scorecardWorkdayPatternNew);
                    }
                    else
                    {
                        ScorecardWorkdayPattern scorecardWorkdayPatternExisting = existingScorecard.ScorecardWorkdayPatterns.Where(x => x.Id == scorecardRequest.ScorecardWorkdayPattern.Id).FirstOrDefault();
                        scorecardWorkdayPatternExisting.LastModifiedBy = loggedInUserId;
                        scorecardWorkdayPatternExisting.LastModifiedOn = TimeZoneUtility.GetCurrentTimestamp();
                        scorecardWorkdayPatternExisting.IsSunday       = scorecardRequest.ScorecardWorkdayPattern.IsSunday;
                        scorecardWorkdayPatternExisting.IsMonday       = scorecardRequest.ScorecardWorkdayPattern.IsMonday;
                        scorecardWorkdayPatternExisting.IsTuesday      = scorecardRequest.ScorecardWorkdayPattern.IsTuesday;
                        scorecardWorkdayPatternExisting.IsWednesday    = scorecardRequest.ScorecardWorkdayPattern.IsWednesday;
                        scorecardWorkdayPatternExisting.IsThursday     = scorecardRequest.ScorecardWorkdayPattern.IsThursday;
                        scorecardWorkdayPatternExisting.IsFriday       = scorecardRequest.ScorecardWorkdayPattern.IsFriday;
                        scorecardWorkdayPatternExisting.IsSaturday     = scorecardRequest.ScorecardWorkdayPattern.IsSaturday;
                        existingScorecard.ScorecardWorkdayPatterns.Add(scorecardWorkdayPatternExisting);
                    }
                }
                else
                {
                    var EffectiveStartDate = new DateTime(currentDate.Year, currentDate.Month, 1);
                    ScorecardWorkdayPattern scorecardWorkdayPatternNew = new ScorecardWorkdayPattern();

                    scorecardWorkdayPatternNew.ScorecardId        = existingScorecard.Id;
                    scorecardWorkdayPatternNew.IsSunday           = scorecardRequest.ScorecardWorkdayPattern.IsSunday;
                    scorecardWorkdayPatternNew.IsMonday           = scorecardRequest.ScorecardWorkdayPattern.IsMonday;
                    scorecardWorkdayPatternNew.IsTuesday          = scorecardRequest.ScorecardWorkdayPattern.IsTuesday;
                    scorecardWorkdayPatternNew.IsWednesday        = scorecardRequest.ScorecardWorkdayPattern.IsWednesday;
                    scorecardWorkdayPatternNew.IsThursday         = scorecardRequest.ScorecardWorkdayPattern.IsThursday;
                    scorecardWorkdayPatternNew.IsFriday           = scorecardRequest.ScorecardWorkdayPattern.IsFriday;
                    scorecardWorkdayPatternNew.IsSaturday         = scorecardRequest.ScorecardWorkdayPattern.IsSaturday;
                    scorecardWorkdayPatternNew.CreatedOn          = TimeZoneUtility.GetCurrentTimestamp();
                    scorecardWorkdayPatternNew.CreatedBy          = loggedInUserId;
                    scorecardWorkdayPatternNew.LastModifiedOn     = TimeZoneUtility.GetCurrentTimestamp();
                    scorecardWorkdayPatternNew.LastModifiedBy     = loggedInUserId;
                    scorecardWorkdayPatternNew.EffectiveStartDate = EffectiveStartDate.Date;
                    existingScorecard.ScorecardWorkdayPatterns.Add(scorecardWorkdayPatternNew);
                }
            }
            //Scorecard Holiday Pattern
            if (scorecardRequest.ScorecardHolidayPattern != null)
            {
                if (scorecardRequest.ActiveScorecardHolidayPattern.EffectiveStartDate.Date == scorecardRequest.ScorecardHolidayPattern.EffectiveStartDate.Date)
                {
                    ScorecardHolidayPattern scorecardHolidayPatternExisting = existingScorecard.ScorecardHolidayPatterns.Where(x => x.Id == scorecardRequest.ScorecardHolidayPattern.Id).FirstOrDefault();
                    scorecardHolidayPatternExisting.LastModifiedBy   = loggedInUserId;
                    scorecardHolidayPatternExisting.LastModifiedOn   = TimeZoneUtility.GetCurrentTimestamp();
                    scorecardHolidayPatternExisting.EffectiveEndDate = EndDate.Date;
                    existingScorecard.ScorecardHolidayPatterns.Add(scorecardHolidayPatternExisting);

                    ScorecardHolidayPattern scorecardHolidayPatternNew = new ScorecardHolidayPattern();

                    scorecardHolidayPatternNew.ScorecardId      = scorecardRequest.ScorecardHolidayPattern.ScorecardId;
                    scorecardHolidayPatternNew.HolidayPatternId = scorecardRequest.ScorecardHolidayPattern.HolidayPatternId;
                    scorecardHolidayPatternNew.CreatedOn        = TimeZoneUtility.GetCurrentTimestamp();
                    scorecardHolidayPatternNew.CreatedBy        = loggedInUserId;
                    scorecardHolidayPatternNew.LastModifiedOn   = TimeZoneUtility.GetCurrentTimestamp();
                    scorecardHolidayPatternNew.LastModifiedBy   = loggedInUserId;

                    scorecardHolidayPatternNew.EffectiveStartDate = EndDate.AddDays(1).Date;
                    existingScorecard.ScorecardHolidayPatterns.Add(scorecardHolidayPatternNew);
                }
                else
                {
                    ScorecardHolidayPattern sorecardHolidayPatternExisting = existingScorecard.ScorecardHolidayPatterns.Where(x => x.Id == scorecardRequest.ScorecardHolidayPattern.Id).FirstOrDefault();
                    sorecardHolidayPatternExisting.LastModifiedBy   = loggedInUserId;
                    sorecardHolidayPatternExisting.LastModifiedOn   = TimeZoneUtility.GetCurrentTimestamp();
                    sorecardHolidayPatternExisting.HolidayPatternId = scorecardRequest.ScorecardHolidayPattern.HolidayPatternId;
                    existingScorecard.ScorecardHolidayPatterns.Add(sorecardHolidayPatternExisting);
                }
            }
            // Call save
            Save();
            return(true);
        }
Пример #3
0
        public ActionResult ScorecardResult(int ResultID)
        {
            ScorecardModel          model            = new ScorecardModel();
            dsScorecard             ScorecardDataset = new dsScorecard();
            ResultTableAdapter      ResultTA         = new ResultTableAdapter();
            ResultGroupTableAdapter ResultGroupTA    = new ResultGroupTableAdapter();
            ResultItemTableAdapter  ResultItemTA     = new ResultItemTableAdapter();

            ScorecardTableAdapter          ScorecardTA      = new ScorecardTableAdapter();
            ScorecardItemGroupTableAdapter ScorecardGroupTA = new ScorecardItemGroupTableAdapter();
            ScorecardItemTableAdapter      ScorecardItemTA  = new ScorecardItemTableAdapter();



            ResultTA.Fill(ScorecardDataset.Result, null, ResultID);
            ResultGroupTA.Fill(ScorecardDataset.ResultGroup, ResultID);
            ResultItemTA.Fill(ScorecardDataset.ResultItem, ResultID);
            dsScorecard.ResultRow ResultRow = ((dsScorecard.ResultRow)ScorecardDataset.Result.Rows[0]);

            UserTableAdapter UserTA = new UserTableAdapter();

            UserTA.Fill(ScorecardDataset.User);

            dsScorecard.UserRow AgentScoredRow = ScorecardDataset.User.FindByUserID(ResultRow.AgentID);
            dsScorecard.UserRow ScoredByRow    = ScorecardDataset.User.FindByUserID(ResultRow.ScorerID);

            ScorecardTA.Fill(ScorecardDataset.Scorecard, ResultRow.ScorecardID);
            ScorecardGroupTA.Fill(ScorecardDataset.ScorecardItemGroup, ResultRow.ScorecardID);

            dsScorecard.ScorecardRow ScorecardRow = ((dsScorecard.ScorecardRow)ScorecardDataset.Scorecard.Rows[0]);

            model.scorecardname        = ScorecardRow.ScorecardName;
            model.scorecarddescription = ScorecardRow.ScorecardDescription;
            model.scorecardgroups      = new List <ScorecardGroup>();
            model.agentscored          = new User {
                emailaddress = AgentScoredRow.EmailAddress,
                firstname    = AgentScoredRow.FirstName,
                surname      = AgentScoredRow.Surname
            };
            model.scoredby = new User
            {
                emailaddress = ScoredByRow.EmailAddress,
                firstname    = ScoredByRow.FirstName,
                surname      = ScoredByRow.Surname
            };
            model.comment       = ResultRow.Comment;
            model.datescored    = ResultRow.DateScored;
            model.callreference = ResultRow.CallReference;
            model.score         = ResultRow.Score;

            foreach (dsScorecard.ScorecardItemGroupRow GroupRow in ScorecardDataset.ScorecardItemGroup)
            {
                DataRow[]      ResultGroupRows = ScorecardDataset.ResultGroup.Select("ScorecardItemGroupID=" + GroupRow.ScorecardItemGroupID.ToString());
                ScorecardGroup GroupItem       = new ScorecardGroup
                {
                    groupname        = GroupRow.GroupName,
                    pasmark          = GroupRow.PassScore,
                    groupdescription = GroupRow.Description,
                    comment          = ((dsScorecard.ResultGroupRow)ResultGroupRows[0]).Comment,
                    score            = ((dsScorecard.ResultGroupRow)ResultGroupRows[0]).Score
                };

                GroupItem.scorecarditems = new List <ScorecardItem>();
                ScorecardDataset.ScorecardItem.Clear();
                ScorecardItemTA.Fill(ScorecardDataset.ScorecardItem, ResultRow.ScorecardID, GroupRow.ScorecardItemGroupID);
                foreach (dsScorecard.ScorecardItemRow ItemRow in ScorecardDataset.ScorecardItem)
                {
                    DataRow[]     ResultItemRows = ScorecardDataset.ResultItem.Select("QuestionID=" + ItemRow.ScorecardItemID.ToString());
                    ScorecardItem Item           = new ScorecardItem
                    {
                        question      = ItemRow.Question,
                        autofail      = ItemRow.AutoFail.ToString(),
                        questiontype  = ItemRow.QuestionType,
                        scoremodifier = ItemRow.ScoreModifier,
                        answer        = ((dsScorecard.ResultItemRow)ResultItemRows[0]).Answer,
                        comment       = ((dsScorecard.ResultItemRow)ResultItemRows[0]).Comment,
                        score         = ((dsScorecard.ResultItemRow)ResultItemRows[0]).Score
                    };
                    GroupItem.scorecarditems.Add(Item);
                }


                model.scorecardgroups.Add(GroupItem);
            }

            return(View(model));
        }
Пример #4
0
        public ActionResult Score(ScorecardModel model, string submit)
        {
            dsScorecard ScorecardDataset = new dsScorecard();

            ScorecardTableAdapter ScorecardTA = new ScorecardTableAdapter();

            ScorecardTA.Fill(ScorecardDataset.Scorecard, model.scorecardid);

            dsScorecard.ScorecardRow ScoreCardRow = ScorecardDataset.Scorecard.FindByScorecardID(model.scorecardid);
            model.scorecardname = ScoreCardRow.ScorecardName;


            if (submit == "Load")
            {
                RecordingSelectCommandTableAdapter RecordingTA = new RecordingSelectCommandTableAdapter();
                RecordingTA.Fill(ScorecardDataset.RecordingSelectCommand, model.callreference.ToString());
                model.Callrecordinglist = new List <SelectListItem>();
                foreach (dsScorecard.RecordingSelectCommandRow row in ScorecardDataset.RecordingSelectCommand.Rows)
                {
                    SelectListItem item = new SelectListItem();
                    item.Text  = row.Description;
                    item.Value = row.CallDate.ToString("ddMMyyyy") + "\\" + row.FileName;
                    model.Callrecordinglist.Add(item);
                }
            }

            if (submit == "Load Call")
            {
                string recordingpath = ScorecardApplication.Properties.Settings.Default.CallRecordingPath + model.recording;
                model.recordingfilename = recordingpath.Replace(".vox", ".mp3");

                ScorecardItemGroupTableAdapter SCGroupTA = new ScorecardItemGroupTableAdapter();
                SCGroupTA.Fill(ScorecardDataset.ScorecardItemGroup, model.scorecardid);

                ScorecardItemTableAdapter SCItemTA = new ScorecardItemTableAdapter();

                if (ScorecardDataset.ScorecardItemGroup.Rows.Count > 0)
                {
                    model.scorecardgroups = new List <ScorecardGroup>();
                }
                foreach (dsScorecard.ScorecardItemGroupRow GroupRow in ScorecardDataset.ScorecardItemGroup.Rows)
                {
                    ScorecardGroup NewGroup = new ScorecardGroup()
                    {
                        groupid          = GroupRow.ScorecardItemGroupID,
                        groupdescription = GroupRow.Description,
                        groupname        = GroupRow.GroupName,
                        pasmark          = GroupRow.PassScore
                    };
                    SCItemTA.Fill(ScorecardDataset.ScorecardItem, model.scorecardid, GroupRow.ScorecardItemGroupID);

                    if (ScorecardDataset.ScorecardItem.Rows.Count > 0)
                    {
                        NewGroup.scorecarditems = new List <ScorecardItem>();
                    }
                    foreach (dsScorecard.ScorecardItemRow ItemRow in ScorecardDataset.ScorecardItem.Rows)
                    {
                        ScorecardItem NewItem = new ScorecardItem();
                        NewItem.autofail = ItemRow.AutoFail.ToString();
                        String[] PossibleAnswerArray = ItemRow.PossibleAnswers.Split("|".ToCharArray());
                        NewItem.possibleanswerslist = new List <SelectListItem>();
                        foreach (String possibleanswer in PossibleAnswerArray)
                        {
                            SelectListItem SelectItem = new SelectListItem
                            {
                                Text  = possibleanswer,
                                Value = possibleanswer
                            };
                            NewItem.possibleanswerslist.Add(SelectItem);
                        }
                        ;
                        NewItem.question     = ItemRow.Question;
                        NewItem.questiontype = ItemRow.QuestionType;
                        NewItem.itemid       = ItemRow.ScorecardItemID;
                        NewGroup.scorecarditems.Add(NewItem);
                    }

                    model.scorecardgroups.Add(NewGroup);
                }
            }

            if (submit == "Save Scorecard")
            {
                ResultTableAdapter      ResultTA      = new ResultTableAdapter();
                ResultItemTableAdapter  ResultItemTA  = new ResultItemTableAdapter();
                ResultGroupTableAdapter ResultGroupTA = new ResultGroupTableAdapter();
                UserTableAdapter        UserTA        = new UserTableAdapter();
                UserTA.Fill(ScorecardDataset.User);
                int ScorerID = 0;
                foreach (dsScorecard.UserRow row in ScorecardDataset.User)
                {
                    if (row.Username.ToLower() == User.Identity.Name.ToLower())
                    {
                        ScorerID = row.UserID;
                    }
                }

                ScorecardItemGroupTableAdapter SCGroupTA = new ScorecardItemGroupTableAdapter();
                SCGroupTA.Fill(ScorecardDataset.ScorecardItemGroup, model.scorecardid);

                ScorecardItemTableAdapter SCItemTA = new ScorecardItemTableAdapter();
                SCItemTA.Fill(ScorecardDataset.ScorecardItem, model.scorecardid, null);

                model.score = 0;
                bool AutoFail = false;
                foreach (ScorecardGroup Group in model.scorecardgroups)
                {
                    Group.score = 0;
                    foreach (ScorecardItem Item in Group.scorecarditems)
                    {
                        dsScorecard.ScorecardItemRow ItemRow = ScorecardDataset.ScorecardItem.FindByScorecardItemID(Item.itemid);
                        if (Item.answer.ToLower() == ItemRow.Answer.ToLower())
                        {
                            Item.score   = ItemRow.ScoreModifier;
                            Group.score += ItemRow.ScoreModifier;
                            model.score += ItemRow.ScoreModifier;
                        }
                        else
                        {
                            Item.score = 0;
                            if (Item.autofail.ToLower() == "true")
                            {
                                AutoFail = true;
                            }
                        }
                    }
                }
                if (AutoFail)
                {
                    model.score = 0;
                }


                // Save Results
                int ResultID = Convert.ToInt32(ResultTA.ResultInsertCommand(model.agentscored.userid, ScorerID, model.scorecardid, DateTime.Now, model.callreference, model.score, model.comment));

                foreach (ScorecardGroup Group in model.scorecardgroups)
                {
                    int GroupID = 0;
                    GroupID = Convert.ToInt32(ResultGroupTA.ResultGroupInsertCommand(ResultID, Group.groupid, Group.comment, Group.score));

                    foreach (ScorecardItem Item in Group.scorecarditems)
                    {
                        ResultItemTA.ResultItemInsertCommand(ResultID, Item.itemid, Item.answer, Item.score, Item.comment, GroupID);
                    }
                }

                return(Redirect("/home/index"));
            }

            return(View(model));
        }
Пример #5
0
        public ActionResult NewScorecard(Models.ScorecardModel model, string submit)
        {
            System.Collections.Specialized.NameObjectCollectionBase.KeysCollection keys = Request.Form.Keys;
            foreach (string item in keys)
            {
                if (item.Contains("delete"))
                {
                    int           groupid    = Convert.ToInt32(item.Substring(18, item.IndexOf("]") - 18));
                    int           questionid = Convert.ToInt32(item.Replace(item.Substring(0, item.IndexOf("]") + 1), "").Replace(".scorecarditems[", "").Replace("].delete", ""));
                    ScorecardItem SCItem     = model.scorecardgroups[groupid].scorecarditems[questionid];
                    model.scorecardgroups[groupid].scorecarditems.Remove(SCItem);
                    //return View(model);
                }
                if (item.Contains("addpf"))
                {
                    int groupid = Convert.ToInt32(item.Substring(18, item.IndexOf("]") - 18));
                    List <SelectListItem> PossibleAnswersList = new List <SelectListItem>();
                    PossibleAnswersList.Add(new SelectListItem {
                        Text = "Pass", Value = "Pass"
                    });
                    PossibleAnswersList.Add(new SelectListItem {
                        Text = "Fail", Value = "Fail"
                    });
                    if (model.scorecardgroups[groupid].scorecarditems == null)
                    {
                        model.scorecardgroups[groupid].scorecarditems = new List <ScorecardItem>();
                    }
                    ScorecardItem SCitem = new ScorecardItem()
                    {
                        questiontype        = "Pass/Fail",
                        possibleanswers     = "Pass|Fail",
                        possibleanswerslist = PossibleAnswersList
                    };
                    model.scorecardgroups[groupid].scorecarditems.Add(SCitem);
                    ViewData[$"m.scorecardgroups[{groupid}].scorecarditems[{(model.scorecardgroups[groupid].scorecarditems.Count-1).ToString()}].possibleanswers"] = "Pass|Fail";
                    //return View(model);
                }
                if (item.Contains("addmc"))
                {
                    int groupid = Convert.ToInt32(item.Substring(18, item.IndexOf("]") - 18));
                    if (model.scorecardgroups[groupid].scorecarditems == null)
                    {
                        model.scorecardgroups[groupid].scorecarditems = new List <ScorecardItem>();
                    }
                    model.scorecardgroups[groupid].scorecarditems.Add(new ScorecardItem()
                    {
                        questiontype = "Multiple Choice"
                    });
                    //return View(model);
                }
                if (item.Contains("newitem"))
                {
                    string   key        = item.Replace("newitem", "itemvalue");
                    string[] value      = Request.Form.GetValues(key);
                    int      groupid    = Convert.ToInt32(item.Substring(18, item.IndexOf("]") - 18));
                    int      questionid = Convert.ToInt32(item.Replace(item.Substring(0, item.IndexOf("]") + 1), "").Replace(".scorecarditems[", "").Replace("].newitem", ""));

                    string[] existinganswers = new String[] { };
                    string   existinganswer  = Request.Form.GetValues($"m.scorecardgroups[{groupid}].scorecarditems[{questionid}].possibleanswers")[0];
                    if (existinganswer != "")
                    {
                        existinganswers = existinganswer.Split(Convert.ToChar("|"));
                    }


                    if (model.scorecardgroups[groupid].scorecarditems[questionid].possibleanswerslist == null)
                    {
                        model.scorecardgroups[groupid].scorecarditems[questionid].possibleanswerslist = new List <SelectListItem>();
                        if (existinganswers != null)
                        {
                            foreach (string answer in existinganswers)
                            {
                                model.scorecardgroups[groupid].scorecarditems[questionid].possibleanswerslist.Add(new SelectListItem {
                                    Text = answer, Value = answer
                                });
                            }
                        }
                    }
                    model.scorecardgroups[groupid].scorecarditems[questionid].possibleanswerslist.Add(new SelectListItem {
                        Text = value[0], Value = value[0]
                    });

                    String possibleanswers = "";
                    foreach (SelectListItem answer in model.scorecardgroups[groupid].scorecarditems[questionid].possibleanswerslist)
                    {
                        if (possibleanswers != "")
                        {
                            possibleanswers = possibleanswers + "|";
                        }
                        possibleanswers = possibleanswers + answer.Text;
                    }
                    model.scorecardgroups[groupid].scorecarditems[questionid].possibleanswers = possibleanswers;
                    ViewData[$"m.scorecardgroups[{groupid}].scorecarditems[{questionid}].possibleanswers"] = possibleanswers;

                    // return View(model);
                }
            }


            if (submit == "Add Group")
            {
                if (model.scorecardgroups == null)
                {
                    model.scorecardgroups = new List <ScorecardGroup>();
                }
                model.scorecardgroups.Add(new ScorecardGroup {
                    groupname = "New Group"
                });
                model.scorecardgroups[model.scorecardgroups.Count - 1].scorecarditems = new List <ScorecardItem>();


                // return View(model);
            }



            for (int j = 0; j < model.scorecardgroups.Count; j++)
            {
                ScorecardGroup Group = model.scorecardgroups[j];

                for (int i = 0; i < model.scorecardgroups[j].scorecarditems.Count; i++)
                {
                    ScorecardItem Item            = model.scorecardgroups[j].scorecarditems[i];
                    String        PreviousAnswers = "";

                    PreviousAnswers = Item.possibleanswers;
                    if (PreviousAnswers == null || PreviousAnswers == "")
                    {
                        try
                        {
                            PreviousAnswers = Request.Form.GetValues($"m.scorecardgroups[{j}].scorecarditems[{i}].possibleanswers")[0];
                        }
                        catch (Exception e)
                        {
                            PreviousAnswers = Item.possibleanswers;
                        }
                    }


                    if (PreviousAnswers != null)
                    {
                        String[] PossibleAnswers = PreviousAnswers.Split(Convert.ToChar("|"));

                        ViewData[$"m.scorecardgroups[{j}].scorecarditems[{i}].possibleanswers"] = PreviousAnswers;
                        Item.possibleanswerslist = new List <SelectListItem>();
                        foreach (String Answer in PossibleAnswers)
                        {
                            Item.possibleanswerslist.Add(new SelectListItem {
                                Text = Answer, Value = Answer
                            });
                        }
                    }
                }
            }


            if (submit == "Save")
            {
                dsScorecard ScorecardDataset = new dsScorecard();

                ScorecardTableAdapter          ScorecardTA      = new ScorecardTableAdapter();
                ScorecardItemGroupTableAdapter ScorecardGroupTA = new ScorecardItemGroupTableAdapter();
                ScorecardItemTableAdapter      ScorecardItemTA  = new ScorecardItemTableAdapter();

                int ScorecardID = Convert.ToInt32(ScorecardTA.ScorecardInsertCommand(model.scorecardname, model.scorecarddescription, model.passmark));

                for (int j = 0; j < model.scorecardgroups.Count; j++)
                {
                    ScorecardGroup group   = model.scorecardgroups[j];
                    int            GroupID = Convert.ToInt32(ScorecardGroupTA.ScorecardItemGroupInsertCommand(ScorecardID, group.groupname, group.groupdescription, group.pasmark));

                    for (int i = 0; i < model.scorecardgroups[j].scorecarditems.Count; i++)
                    {
                        ScorecardItem item = model.scorecardgroups[j].scorecarditems[i];
                        bool          autofail;
                        if (item.autofail == "Yes")
                        {
                            autofail = true;
                        }
                        else
                        {
                            autofail = false;
                        }

                        string existinganswer = Request.Form.GetValues($"m.scorecardgroups[{j}].scorecarditems[{i}].possibleanswers")[0];

                        ScorecardItemTA.Insert(ScorecardID, item.question, item.questiontype, existinganswer, item.scoremodifier, autofail, GroupID, item.answer);
                    }
                }
                return(Redirect("/home/index"));
            }

            return(View(model));
        }