Esempio n. 1
0
        //public int CreateSurvey(VmSurvey vmSurvey)
        //{
        //    var result = -1;
        //    try
        //    {
        //        var questionRepository = UnitOfWork.GetRepository<ViewSurveyRepository>();

        //        var newSurvey = new Survey
        //        {
        //            Id = vmSurvey.Id,
        //            Name = vmSurvey.Name,
        //            Description = vmSurvey.Description,
        //        };

        //        questionRepository.CreateSurvey(newSurvey);

        //        UnitOfWork.Commit();

        //        result = newSurvey.Id;
        //    }
        //    catch (Exception ex)
        //    {
        //        result = -1;
        //    }

        //    return result;
        //}

        //public bool UpdateSurvey(VmSurvey vmSurvey)
        //{
        //    try
        //    {
        //        var questionRepository = UnitOfWork.GetRepository<ViewSurveyRepository>();

        //        var updateableSurvey = new Survey
        //        {
        //            Id = vmSurvey.Id,
        //            Name = vmSurvey.Name,
        //            Description = vmSurvey.Description,
        //        };

        //        questionRepository.UpdateSurvey(updateableSurvey);

        //        return UnitOfWork.Commit();
        //    }
        //    catch
        //    {
        //        return false;
        //    }

        //}
        public bool UpdateSurvey(string userId, List <VmClientSurveyResult> clientSurveyResult)
        {
            try
            {
                var blPerson = new BLPerson();
                var person   = blPerson.GetPersonByUserId(userId);


                var blTeamMember = new BLTeamMember();

                VmTeamMember teamMember = null;

                var teamId = 0;

                if (person.RoleName.ToLower().Contains("judge") == false)
                {
                    teamMember = blTeamMember.GetTeamMemberByUserId(userId);
                    teamId     = teamMember.TeamId;
                }

                var surveyResultRepository = UnitOfWork.GetRepository <SurveyResultRepository>();

                surveyResultRepository.DeleteSurveyResult(userId, clientSurveyResult.Select(q => q.QuestionId).ToArray());

                var surveyResultDetails = new List <SurveyResultDetail>();

                var surveyResultList = from survey in clientSurveyResult
                                       group new
                {
                    survey.QuestionAnswerId,
                    survey.Value,
                    survey.Comment
                }
                by survey.QuestionId into g
                    select new SurveyResult
                {
                    QuestionId          = g.Key,
                    TeamId              = teamId,
                    UserId              = userId,
                    SurveyResultDetails = (from s in g.ToList()
                                           select new SurveyResultDetail
                    {
                        QuestionAnswerId = s.QuestionAnswerId,
                        Value = s.Value,
                        Comment = s.Comment,
                    }).ToList()
                };

                if (person.RoleName.ToLower().Contains("judge") == false)
                {
                    blTeamMember.UpdateTeamMemberSurvey(userId, true);
                }

                surveyResultRepository.CreateSurveyResult(surveyResultList);

                return(UnitOfWork.Commit());
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 2
0
        public IEnumerable <VmSurvey> GetSurveyList(string userId, QuestionType type)
        {
            var blPerson = new BLPerson();
            var person   = blPerson.GetPersonByUserId(userId);

            var blTeamMember = new BLTeamMember();

            VmTeamMember teamMember = null;

            var teamId = 0;

            if (person.RoleName.ToLower().Contains("judge") == false)
            {
                teamMember = blTeamMember.GetTeamMemberByUserId(userId);
                teamId     = teamMember.TeamId;
                blTeamMember.UpdateTeamMemberSurvey(userId, true);
            }

            var viewViewSurveyRepository = UnitOfWork.GetRepository <ViewSurveyRepository>();

            var questionList = viewViewSurveyRepository.GetViewSurveys(type);

            var vmSurveyList = (from q in questionList
                                group new
            {
                q.AnswerId,
                q.QuestionAnswerId,
                q.AnswerType,
                q.Weight,
                q.AnswerPriority,
                q.Answer,
                q.TitleVisible,
                q.Comment,
                q.ShowComment,
            }
                                by new
            {
                q.Id,
                q.Question,
                q.QuestionPriority,
                q.QuestionType,
                q.QuestionComment,
            }
                                into g
                                select new VmSurvey
            {
                Id = g.Key.Id,
                Question = g.Key.Question,
                QuestionPriority = g.Key.QuestionPriority,
                QuestionComment = g.Key.QuestionComment,
                QuestionType = g.Key.QuestionType,

                SurveyDetailList = (from gd in g.ToList()
                                    select new VmSurveyDetail
                {
                    AnswerId = gd.AnswerId,
                    QuestionAnswerId = gd.QuestionAnswerId,
                    AnswerType = gd.AnswerType,
                    Weight = gd.Weight,
                    AnswerPriority = gd.AnswerPriority,
                    Answer = gd.Answer,
                    TitleVisible = gd.TitleVisible,
                    Value = "",
                    Comment = gd.Comment,
                    ShowComment = gd.ShowComment,
                }).ToList()
            }).ToList();


            IEnumerable <ViewSurveyResult> surveyResultList = null;

            if (person.RoleName.ToLower().Contains("judge") == false)
            {
                surveyResultList = viewViewSurveyRepository.GetViewSurveyResults(userId, teamId);
            }
            else
            {
                surveyResultList = viewViewSurveyRepository.GetViewSurveyResults(userId);
            }
            if (surveyResultList.Count() > 0)
            {
                foreach (var question in vmSurveyList)
                {
                    foreach (var answer in question.SurveyDetailList)
                    {
                        answer.Value   = surveyResultList.Where(a => a.UserId == userId && a.QuestionAnswerId == answer.QuestionAnswerId && a.Id == question.Id).First().Value ?? "";
                        answer.Comment = surveyResultList.Where(a => a.UserId == userId && a.QuestionAnswerId == answer.QuestionAnswerId && a.Id == question.Id).First().Comment ?? "";
                    }
                }
            }
            return(vmSurveyList);
        }
Esempio n. 3
0
        public VmInvoice GetExtraMemberInvoiceFullInfoByUserId(string userId)
        {
            var viewInvoiceRepository = UnitOfWork.GetRepository <ViewInvoiceExtraMemberRepository>();

            var viewInvoice = viewInvoiceRepository.GetViewInvoiceExtraMemberByUserId(userId, true, true);

            if (viewInvoice.Count() == 0)
            {
                return(null);//At first, Please pay for the team by the peyment menu
            }

            var teamIds = viewInvoice.Select(t => t.TeamId).Distinct(); // Grouped Teams

            var invoiceDetailRepository = UnitOfWork.GetRepository <InvoiceDetailRepository>();

            var blparticipantRule = new BLParticipantRule();

            var blTeamMember = new BLTeamMember();

            var participantRule = blparticipantRule.GetParticipantRule();

            var extraMemberCount = 0;

            #region Temprorary Calculation


            foreach (var teamId in teamIds)
            {
                var teamExtraParticipantSum = viewInvoice.Where(i => i.TeamId == teamId).Sum(t => t.ExtraParticipantCount);

                var team = viewInvoice.Where(i => i.TeamId == teamId).First();

                var teamMemberCount = blTeamMember.GetTeamMembersCount(team.TeamId);

                extraMemberCount = 0;

                if (team.IsFirstTeam.Value)
                {
                    extraMemberCount = (teamMemberCount - participantRule.FirstTeamMaxMember - teamExtraParticipantSum).Value;
                }
                else
                {
                    extraMemberCount = (teamMemberCount - participantRule.EachExtraTeamMaxMember - teamExtraParticipantSum).Value;
                }

                if (extraMemberCount > 0)
                {
                    break;
                }
            }

            if (extraMemberCount <= 0)
            {
                return(null);// There is no balance to pay for extra members.
            }

            #endregion Temprorary Calculation

            #region Create/Edit Invoice

            VmInvoice vmInvoice = null;

            if (extraMemberCount > 0) // there is one payable extra member at least
            {
                var viewInvoiceUnFinished = viewInvoiceRepository.GetViewInvoiceExtraMemberByUserId(userId, true, false);

                if (viewInvoiceUnFinished == null || viewInvoiceUnFinished.Count() == 0)
                {
                    vmInvoice = new VmInvoice
                    {
                        UserId          = userId,
                        DateOfIssue     = DateTime.Now.Date,
                        InvoiceTotal    = 0,
                        Subtotal        = 0,
                        Tax             = 0,
                        Total           = 0,
                        AmountDue       = 0,
                        ConventionalFee = 2.5M,
                        Finished        = false,
                    };

                    vmInvoice.Id = CreateInvoice(vmInvoice);
                }
                else
                {
                    var blInvoice = new BLInvoice();
                    vmInvoice = blInvoice.GetInvoiceById(viewInvoiceUnFinished.First().InvoiceId.Value);

                    invoiceDetailRepository.DeleteInvoiceDetailsByInvoiceId(viewInvoiceUnFinished.First().InvoiceId.Value);
                    UnitOfWork.Commit();
                }

                vmInvoice.Subtotal = 0;
            }

            #endregion Create/Edit Invoice

            #region Calculation

            foreach (var teamId in teamIds)
            {
                var teamExtraParticipantSum = viewInvoice.Where(i => i.TeamId == teamId).Sum(t => t.ExtraParticipantCount);

                var team = viewInvoice.Where(i => i.TeamId == teamId).First();

                var teamMemberCount = blTeamMember.GetTeamMembersCount(team.TeamId);

                extraMemberCount = 0;

                if (team.IsFirstTeam.Value)
                {
                    extraMemberCount = (teamMemberCount - participantRule.FirstTeamMaxMember - teamExtraParticipantSum).Value;
                }
                else
                {
                    extraMemberCount = (teamMemberCount - participantRule.EachExtraTeamMaxMember - teamExtraParticipantSum).Value;
                }

                if (extraMemberCount > 0) // has payable extra member
                {
                    var invoiceDetail = new InvoiceDetail
                    {
                        TeamId            = team.TeamId,
                        InvoiceId         = vmInvoice.Id,
                        PaymentRuleId     = team.PaymentRuleId.Value,
                        IsFirstTeam       = team.IsFirstTeam.Value,
                        ConventionalFee   = vmInvoice.ConventionalFee,
                        ExtraTeamDiscount = 0
                    };

                    invoiceDetail.ExtraParticipantCount = extraMemberCount;

                    invoiceDetail.TeamUnitCost = 0;

                    invoiceDetail.ExtraParticipantUnitCost = participantRule.ExtraParticipantFee;

                    invoiceDetail.ExtraParticipantAmount = invoiceDetail.ExtraParticipantCount * invoiceDetail.ExtraParticipantUnitCost;

                    invoiceDetail.Amount = invoiceDetail.ExtraParticipantAmount;

                    invoiceDetailRepository.CreateInvoiceDetail(invoiceDetail);

                    vmInvoice.Subtotal += invoiceDetail.Amount;

                    vmInvoice.TotalConventionalFee += vmInvoice.ConventionalFee * invoiceDetail.Amount / 100;
                }
            }

            #endregion Calculation

            UnitOfWork.Commit();

            vmInvoice.Total        = vmInvoice.Subtotal + vmInvoice.TotalConventionalFee;
            vmInvoice.AmountDue    = vmInvoice.Total;
            vmInvoice.InvoiceTotal = vmInvoice.AmountDue * vmInvoice.ConventionalFee / 100;

            UpdateInvoice(vmInvoice);

            viewInvoice = viewInvoiceRepository.GetViewInvoiceExtraMemberByUserId(userId, true, false);

            var viewDataInvoice = viewInvoiceRepository.GetViewInvoiceExtraMemberById(vmInvoice.Id);

            var invoice = viewDataInvoice.OrderByDescending(i => i.Total).First();

            var allowCheckFisrtTeam = false;

            if (GetPayedTeamCount(userId) == 0)
            {
                allowCheckFisrtTeam = true;
            }

            vmInvoice.Id                  = invoice.InvoiceId ?? -1;
            vmInvoice.University          = invoice.University;
            vmInvoice.Address             = invoice.StreetLine1 + " " + invoice.StreetLine2 + " " + invoice.City + invoice.State + " " + invoice.ZipCode;
            vmInvoice.AccountOwner        = invoice.FirstName + " " + invoice.LastName;
            vmInvoice.DateOfIssue         = invoice.DateOfIssue ?? DateTime.Now.Date;
            vmInvoice.InvoiceNumber       = invoice.InvoiceNumber ?? 0;
            vmInvoice.InvoiceTotal        = invoice.InvoiceTotal ?? 0;
            vmInvoice.Title               = invoice.Title ?? "";
            vmInvoice.UserId              = invoice.UserId;
            vmInvoice.Subtotal            = invoice.Subtotal ?? 0;
            vmInvoice.Tax                 = invoice.Tax ?? 0;
            vmInvoice.Total               = invoice.Total ?? 0;
            vmInvoice.AmountDue           = invoice.AmountDue ?? 0;
            vmInvoice.AllowCheckFisrtTeam = allowCheckFisrtTeam;

            vmInvoice.InvoiceDetails =

                (from i in viewInvoice
                 select new VmInvoiceDetail
            {
                Amount = i.Amount ?? 0,
                ExtraParticipantAmount = i.ExtraParticipantAmount ?? 0,
                ExtraParticipantCount = i.ExtraParticipantCount ?? 0,
                ExtraParticipantUnitCost = i.ExtraParticipantUnitCost ?? 0,
                ExtraTeamDiscount = i.ExtraTeamDiscount ?? 0,
                Id = i.InvoiceId ?? -1,
                InvoiceId = invoice.InvoiceId ?? -1,
                IsFirstTeam = i.IsFirstTeam ?? false,
                FirstTeamOrExtraTeam =
                    (allowCheckFisrtTeam == true) ?
                    (i.IsFirstTeam == null || i.IsFirstTeam == false) ? "Extra" : "First"
                                               : "Extra",

                PaymentRuleId = i.PaymentRuleId ?? -1,
                PayStatus = i.PayStatus,
                TeamId = i.TeamId,
                TeamName = i.TeamName,
                TeamUnitCost = (i.IsFirstTeam == null || i.IsFirstTeam == false) ?
                               (i.TeamUnitCost - i.ExtraTeamDiscount) ?? 0 : i.TeamUnitCost ?? 0,
                TypeOfRegistration = i.TypeOfRegistration,
                DueDate = i.DueDate ?? DateTime.Now.Date,
                IsChecked = i.Amount > 0 ? true : false,
                ConventionalFee = i.Amount * i.ConventionalFee / 100,
                Task = i.Task,
            }).ToList();

            vmInvoice.TotalConventionalFee = vmInvoice.InvoiceDetails.Sum(i => i.ConventionalFee).Value;

            return(vmInvoice);
        }
Esempio n. 4
0
        public void ProcessInvoice(string currentUserId, int currentTeamId, List <VmTeamSelection> teamSelectionList)
        {
            var invoiceDetailRepository = UnitOfWork.GetRepository <InvoiceDetailRepository>();

            var blPaymentRule     = new BLPaymentRule();
            var blparticipantRule = new BLParticipantRule();
            var blTeamMember      = new BLTeamMember();

            var paymentRule = blPaymentRule.GetPaymentRuleBySuitableDueDate(DateTime.Now.Date);

            var participantRule = blparticipantRule.GetParticipantRule();

            if (paymentRule != null)
            {
                var vmInvoice = GetInvoiceByUserId(currentUserId, false);

                if (vmInvoice == null)
                {
                    vmInvoice = new VmInvoice
                    {
                        UserId          = currentUserId,
                        DateOfIssue     = DateTime.Now.Date,
                        InvoiceTotal    = 0,
                        Subtotal        = 0,
                        Tax             = 0,
                        Total           = 0,
                        AmountDue       = 0,
                        ConventionalFee = 2.5M,
                        Finished        = false,
                    };

                    vmInvoice.Id = CreateInvoice(vmInvoice);
                }

                vmInvoice.Subtotal = 0;

                invoiceDetailRepository.DeleteInvoiceDetailsByInvoiceId(vmInvoice.Id);

                var finishedInvoice = GetInvoiceByUserId(currentUserId, true);

                var allowCheckFisrtTeam = false;

                if (finishedInvoice == null)
                {
                    allowCheckFisrtTeam = true;
                }

                foreach (var item in teamSelectionList)
                {
                    var teamMemberCount = blTeamMember.GetTeamMembersCount(item.TeamId);

                    var invoiceDetail = new InvoiceDetail();

                    if (item.Checked == true)
                    {
                        invoiceDetail.TeamId          = item.TeamId;
                        invoiceDetail.InvoiceId       = vmInvoice.Id;
                        invoiceDetail.PaymentRuleId   = paymentRule.Id;
                        invoiceDetail.IsFirstTeam     = item.IsFirstTeam;
                        invoiceDetail.ConventionalFee = vmInvoice.ConventionalFee;

                        if (item.IsFirstTeam && allowCheckFisrtTeam == true)
                        {
                            invoiceDetail.ExtraTeamDiscount     = 0;
                            invoiceDetail.ExtraParticipantCount = (teamMemberCount - participantRule.FirstTeamMaxMember) < 0 ? 0 : teamMemberCount - participantRule.FirstTeamMaxMember;
                        }
                        else
                        {
                            invoiceDetail.ExtraTeamDiscount     = paymentRule.ExtraTeamDiscount;
                            invoiceDetail.ExtraParticipantCount = (teamMemberCount - participantRule.EachExtraTeamMaxMember) < 0 ? 0 : teamMemberCount - participantRule.EachExtraTeamMaxMember;
                            invoiceDetail.TeamUnitCost          = paymentRule.FirstTeamFee - paymentRule.ExtraTeamDiscount;//Team Unit Cost
                        }

                        invoiceDetail.TeamUnitCost             = paymentRule.FirstTeamFee;//Team Unit Cost
                        invoiceDetail.ExtraParticipantUnitCost = participantRule.ExtraParticipantFee;
                        invoiceDetail.ExtraParticipantAmount   = invoiceDetail.ExtraParticipantCount * invoiceDetail.ExtraParticipantUnitCost;
                        invoiceDetail.Amount = invoiceDetail.ExtraParticipantAmount + invoiceDetail.TeamUnitCost - invoiceDetail.ExtraTeamDiscount;

                        invoiceDetailRepository.CreateInvoiceDetail(invoiceDetail);

                        vmInvoice.Subtotal             += invoiceDetail.Amount;
                        vmInvoice.TotalConventionalFee += vmInvoice.ConventionalFee * invoiceDetail.Amount / 100;
                    }
                }

                UnitOfWork.Commit();

                vmInvoice.Total        = vmInvoice.Subtotal + vmInvoice.TotalConventionalFee;
                vmInvoice.AmountDue    = vmInvoice.Total;
                vmInvoice.InvoiceTotal = vmInvoice.AmountDue * vmInvoice.ConventionalFee / 100;

                UpdateInvoice(vmInvoice);
            }
        }
Esempio n. 5
0
        public List <VmTaskBaseGrade> GetStudentOtherTeamGradeReportList(string studentUserId, int teamId)
        {
            var viewTaskTeamRepository = UnitOfWork.GetRepository <ViewTaskTeamRepository>();

            IEnumerable <ViewTaskTeam> taskTeamRepositoryList;

            var blTeamMember = new BLTeamMember();
            var teamMember   = blTeamMember.GetTeamMemberByUserIdAndTeamId(studentUserId, teamId);
            var taskId       = teamMember.TaskId.Value;


            var blUserTask        = new BLUserTask();
            var judgeUserTaskList = blUserTask.GetUsersByTask(taskId);

            var bTeam      = new BLTeam();
            var teamIdList = bTeam.GetTeamIdsByTask(taskId);


            taskTeamRepositoryList = viewTaskTeamRepository.GetTaskTeamByJudgesAndteamIds(judgeUserTaskList.ToArray(), teamIdList.ToArray()).ToList();

            var viewTaskRepository = UnitOfWork.GetRepository <ViewTaskRepository>();

            var taskGradeList = viewTaskRepository.GetViewTaskByIds(new int[] { taskId }).ToList();

            var blTeamGradeDetail   = new BLTeamGradeDetail();
            var teamGradeDetailList = blTeamGradeDetail.GetAllTeamGradeDetailByTaskIds(taskTeamRepositoryList.Select(t => t.TaskId).Distinct().ToArray()).ToList();

            var taskBaseGradeList = (from task in taskTeamRepositoryList
                                     group task by new { task.TaskId, task.TaskName } into g
                                     select new VmTaskBaseGrade
            {
                TaskId = g.Key.TaskId,
                TaskName = g.Key.TaskName,

                GradeList = (from gt in taskGradeList
                             where gt.Id == g.Key.TaskId
                             select new VmGrade
                {
                    Id = gt.GradeId,
                    Name = gt.Grade
                }).ToList(),

                TeamGradeList = (from team in g.ToList()
                                 group team by new { team.TeamId, team.TeamName } into tg
                                 select new VmTeamGrade
                {
                    TeamId = tg.Key.TeamId,
                    TeamName = tg.Key.TeamName,
                }).ToList()
            }).ToList();


            foreach (var taskBaseGrade in taskBaseGradeList)
            {
                foreach (var team in taskBaseGrade.TeamGradeList)
                {
                    team.GradeReportList = new List <VmGradeReport>();

                    foreach (var grade in taskBaseGrade.GradeList)
                    {
                        team.GradeReportList.Add(new VmGradeReport
                        {
                            GradeId   = grade.Id,
                            GradeType = grade.Name,
                            Average   = GetAverageTotal(teamGradeDetailList, taskBaseGrade.TaskId, team.TeamId, grade.Id)
                        });
                    }
                }
            }

            return(taskBaseGradeList);
        }