Ejemplo n.º 1
0
        public IHttpActionResult GetPanelties()
        {
            try
            {
                IEnumerable <DeMerit> deMerits = new List <DeMerit>();
                deMerits = _deMerit.GetAllDeMerits();
                DeMeritMemberTypeViewModel deMeritMemType = new DeMeritMemberTypeViewModel();
                deMeritMemType.driver          = new DeMeritTypeSetViewModel();
                deMeritMemType.driver.adPannel = new List <DeMeritTypeViewModel>();
                deMeritMemType.driver.finePay  = new List <DeMeritTypeViewModel>();
                deMeritMemType.driver.punish   = new List <DeMeritTypeViewModel>();
                deMeritMemType.driver.cancel   = new List <DeMeritTypeViewModel>();


                deMeritMemType.conductor          = new DeMeritTypeSetViewModel();
                deMeritMemType.conductor.adPannel = new List <DeMeritTypeViewModel>();
                deMeritMemType.conductor.finePay  = new List <DeMeritTypeViewModel>();
                deMeritMemType.conductor.punish   = new List <DeMeritTypeViewModel>();
                deMeritMemType.conductor.cancel   = new List <DeMeritTypeViewModel>();


                foreach (DeMerit demerit in deMerits.Where(z => z.CreatedDate.Date >= DateTime.Now.Date.AddMonths(-1) && z.CreatedDate.Date <= DateTime.Now.Date))
                {
                    foreach (MemberDeMerit mem in demerit.MemberDeMerits)
                    {
                        switch (demerit.Member.MemberType.Code)
                        {
                        case "Driver":
                            switch (mem.Merit.ColorCodeId)
                            {
                            case 1:
                                var a = deMeritMemType.driver.cancel.Find(x => x.id == demerit.Member.ID && x.meritId == mem.MeritId);
                                if (a == null && mem.Point > 0)
                                {
                                    DeMeritTypeViewModel ad = new DeMeritTypeViewModel();
                                    ad.id      = demerit.Member.ID;
                                    ad.name    = demerit.Member.FullName;
                                    ad.ntcNo   = demerit.Member.NTCNo;
                                    ad.point   = mem.Point;
                                    ad.meritId = mem.MeritId;
                                    deMeritMemType.driver.cancel.Add(ad);
                                }
                                else if (a != null && mem.Point > 0)
                                {
                                    a.point += mem.Point;
                                }
                                break;

                            case 2:
                                var b = deMeritMemType.driver.adPannel.Find(x => x.id == demerit.Member.ID && x.meritId == mem.MeritId);
                                if (b == null && mem.Point > 0)
                                {
                                    DeMeritTypeViewModel ad = new DeMeritTypeViewModel();
                                    ad.id      = demerit.Member.ID;
                                    ad.name    = demerit.Member.FullName;
                                    ad.ntcNo   = demerit.Member.NTCNo;
                                    ad.point   = mem.Point;
                                    ad.meritId = mem.MeritId;
                                    deMeritMemType.driver.adPannel.Add(ad);
                                }
                                else if (b != null && mem.Point > 0)
                                {
                                    b.point += mem.Point;
                                }
                                break;

                            case 3:
                                var c = deMeritMemType.driver.punish.Find(x => x.id == demerit.Member.ID && x.meritId == mem.MeritId);
                                if (c == null && mem.Point > 0)
                                {
                                    DeMeritTypeViewModel ad = new DeMeritTypeViewModel();
                                    ad.id      = demerit.Member.ID;
                                    ad.name    = demerit.Member.FullName;
                                    ad.ntcNo   = demerit.Member.NTCNo;
                                    ad.point   = mem.Point;
                                    ad.meritId = mem.MeritId;
                                    deMeritMemType.driver.punish.Add(ad);
                                }
                                else if (c != null && mem.Point > 0)
                                {
                                    c.point += mem.Point;
                                }
                                break;

                            case 4:
                                var d = deMeritMemType.driver.finePay.Find(x => x.id == demerit.Member.ID && x.meritId == mem.MeritId);
                                if (d == null && mem.Point > 0)
                                {
                                    DeMeritTypeViewModel ad = new DeMeritTypeViewModel();
                                    ad.id      = demerit.Member.ID;
                                    ad.name    = demerit.Member.FullName;
                                    ad.ntcNo   = demerit.Member.NTCNo;
                                    ad.point   = mem.Point;
                                    ad.meritId = mem.MeritId;
                                    deMeritMemType.driver.finePay.Add(ad);
                                }
                                else if (d != null && mem.Point > 0)
                                {
                                    d.point += mem.Point;
                                }
                                break;

                            default:
                                break;
                            }
                            break;

                        case "Conductor":
                            switch (mem.Merit.ColorCodeId)
                            {
                            case 1:
                                var a = deMeritMemType.conductor.cancel.Find(x => x.id == demerit.Member.ID && x.meritId == mem.MeritId);
                                if (a == null && mem.Point > 0)
                                {
                                    DeMeritTypeViewModel ad = new DeMeritTypeViewModel();
                                    ad.id      = demerit.Member.ID;
                                    ad.name    = demerit.Member.FullName;
                                    ad.ntcNo   = demerit.Member.NTCNo;
                                    ad.point   = mem.Point;
                                    ad.meritId = mem.MeritId;
                                    deMeritMemType.conductor.cancel.Add(ad);
                                }
                                else if (a != null && mem.Point > 0)
                                {
                                    a.point += mem.Point;
                                }
                                break;

                            case 2:
                                var b = deMeritMemType.conductor.adPannel.Find(x => x.id == demerit.Member.ID && x.meritId == mem.MeritId);
                                if (b == null && mem.Point > 0)
                                {
                                    DeMeritTypeViewModel ad = new DeMeritTypeViewModel();
                                    ad.id      = demerit.Member.ID;
                                    ad.name    = demerit.Member.FullName;
                                    ad.ntcNo   = demerit.Member.NTCNo;
                                    ad.point   = mem.Point;
                                    ad.meritId = mem.MeritId;
                                    deMeritMemType.conductor.adPannel.Add(ad);
                                }
                                else if (b != null && mem.Point > 0)
                                {
                                    b.point += mem.Point;
                                }
                                break;

                            case 3:
                                var c = deMeritMemType.conductor.punish.Find(x => x.id == demerit.Member.ID && x.meritId == mem.MeritId);
                                if (c == null && mem.Point > 0)
                                {
                                    DeMeritTypeViewModel ad = new DeMeritTypeViewModel();
                                    ad.id      = demerit.Member.ID;
                                    ad.name    = demerit.Member.FullName;
                                    ad.ntcNo   = demerit.Member.NTCNo;
                                    ad.point   = mem.Point;
                                    ad.meritId = mem.MeritId;
                                    deMeritMemType.conductor.punish.Add(ad);
                                }
                                else if (c != null && mem.Point > 0)
                                {
                                    c.point += mem.Point;
                                }
                                break;

                            case 4:
                                var d = deMeritMemType.conductor.finePay.Find(x => x.id == demerit.Member.ID && x.meritId == mem.MeritId);
                                if (d == null && mem.Point > 0)
                                {
                                    DeMeritTypeViewModel ad = new DeMeritTypeViewModel();
                                    ad.id      = demerit.Member.ID;
                                    ad.name    = demerit.Member.FullName;
                                    ad.ntcNo   = demerit.Member.NTCNo;
                                    ad.point   = mem.Point;
                                    ad.meritId = mem.MeritId;
                                    deMeritMemType.conductor.finePay.Add(ad);
                                }
                                else if (d != null && mem.Point > 0)
                                {
                                    d.point += mem.Point;
                                }
                                break;

                            default:
                                break;
                            }
                            break;

                        default: break;
                        }
                    }
                }
                List <int> admem = new List <int>();
                deMeritMemType.driver.adPannel = deMeritMemType.driver.adPannel.Where(x => x.point > 2).ToList();
                admem = deMeritMemType.driver.adPannel.Select(x => x.id).Distinct().ToList();
                deMeritMemType.driver.adPannel.Clear();
                foreach (int i in admem)
                {
                    Member mem = _member.GetAll(x => x.ID == i).FirstOrDefault();
                    DeMeritTypeViewModel ad = new DeMeritTypeViewModel();
                    ad.id    = mem.ID;
                    ad.name  = mem.FullName;
                    ad.ntcNo = mem.NTCNo;
                    deMeritMemType.driver.adPannel.Add(ad);
                }
                admem.Clear();
                deMeritMemType.driver.finePay = deMeritMemType.driver.finePay.Where(x => x.point > 2).ToList();
                admem = deMeritMemType.driver.finePay.Select(x => x.id).Distinct().ToList();
                deMeritMemType.driver.finePay.Clear();
                foreach (int i in admem)
                {
                    Member mem = _member.GetAll(x => x.ID == i).FirstOrDefault();
                    DeMeritTypeViewModel ad = new DeMeritTypeViewModel();
                    ad.id    = mem.ID;
                    ad.name  = mem.FullName;
                    ad.ntcNo = mem.NTCNo;
                    deMeritMemType.driver.finePay.Add(ad);
                }
                admem.Clear();
                deMeritMemType.driver.punish = deMeritMemType.driver.punish.Where(x => x.point > 2).ToList();
                admem = deMeritMemType.driver.punish.Select(x => x.id).Distinct().ToList();
                deMeritMemType.driver.punish.Clear();
                foreach (int i in admem)
                {
                    Member mem = _member.GetAll(x => x.ID == i).FirstOrDefault();
                    DeMeritTypeViewModel ad = new DeMeritTypeViewModel();
                    ad.id    = mem.ID;
                    ad.name  = mem.FullName;
                    ad.ntcNo = mem.NTCNo;
                    deMeritMemType.driver.punish.Add(ad);
                }
                admem.Clear();
                deMeritMemType.driver.cancel = deMeritMemType.driver.cancel.Where(x => x.point > 2).ToList();
                admem = deMeritMemType.driver.cancel.Select(x => x.id).Distinct().ToList();
                deMeritMemType.driver.cancel.Clear();
                foreach (int i in admem)
                {
                    Member mem = _member.GetAll(x => x.ID == i).FirstOrDefault();
                    DeMeritTypeViewModel ad = new DeMeritTypeViewModel();
                    ad.id    = mem.ID;
                    ad.name  = mem.FullName;
                    ad.ntcNo = mem.NTCNo;
                    deMeritMemType.driver.cancel.Add(ad);
                }

                deMeritMemType.conductor.adPannel = deMeritMemType.conductor.adPannel.Where(x => x.point > 2).ToList();
                admem.Clear();
                admem = deMeritMemType.conductor.adPannel.Select(x => x.id).Distinct().ToList();
                deMeritMemType.conductor.adPannel.Clear();
                foreach (int i in admem)
                {
                    Member mem = _member.GetAll(x => x.ID == i).FirstOrDefault();
                    DeMeritTypeViewModel ad = new DeMeritTypeViewModel();
                    ad.id    = mem.ID;
                    ad.name  = mem.FullName;
                    ad.ntcNo = mem.NTCNo;
                    deMeritMemType.conductor.adPannel.Add(ad);
                }

                deMeritMemType.conductor.finePay = deMeritMemType.conductor.finePay.Where(x => x.point > 2).ToList();
                admem.Clear();
                admem = deMeritMemType.conductor.finePay.Select(x => x.id).Distinct().ToList();
                deMeritMemType.conductor.finePay.Clear();
                foreach (int i in admem)
                {
                    Member mem = _member.GetAll(x => x.ID == i).FirstOrDefault();
                    DeMeritTypeViewModel ad = new DeMeritTypeViewModel();
                    ad.id    = mem.ID;
                    ad.name  = mem.FullName;
                    ad.ntcNo = mem.NTCNo;
                    deMeritMemType.conductor.finePay.Add(ad);
                }
                deMeritMemType.conductor.punish = deMeritMemType.conductor.punish.Where(x => x.point > 2).ToList();
                admem.Clear();
                admem = deMeritMemType.conductor.punish.Select(x => x.id).Distinct().ToList();
                deMeritMemType.conductor.punish.Clear();
                foreach (int i in admem)
                {
                    Member mem = _member.GetAll(x => x.ID == i).FirstOrDefault();
                    DeMeritTypeViewModel ad = new DeMeritTypeViewModel();
                    ad.id    = mem.ID;
                    ad.name  = mem.FullName;
                    ad.ntcNo = mem.NTCNo;
                    deMeritMemType.conductor.punish.Add(ad);
                }
                deMeritMemType.conductor.cancel = deMeritMemType.conductor.cancel.Where(x => x.point > 2).ToList();
                admem.Clear();
                admem = deMeritMemType.conductor.cancel.Select(x => x.id).Distinct().ToList();
                deMeritMemType.conductor.cancel.Clear();
                foreach (int i in admem)
                {
                    Member mem = _member.GetAll(x => x.ID == i).FirstOrDefault();
                    DeMeritTypeViewModel ad = new DeMeritTypeViewModel();
                    ad.id    = mem.ID;
                    ad.name  = mem.FullName;
                    ad.ntcNo = mem.NTCNo;
                    deMeritMemType.conductor.cancel.Add(ad);
                }

                var messageData  = new { code = Constant.SuccessMessageCode, message = Constant.MessageSuccess };
                var returnObject = new { merits = deMeritMemType, messageCode = messageData };
                return(Ok(returnObject));
            }
            catch (Exception ex)
            {
                string errorLogId   = _eventLog.WriteLogs(User.Identity.Name, ex, MethodBase.GetCurrentMethod().Name);
                var    messageData  = new { code = Constant.ErrorMessageCode, message = String.Format(Constant.MessageTaskmateError, errorLogId) };
                var    returnObject = new { messageCode = messageData };
                return(Ok(returnObject));
            }
        }
Ejemplo n.º 2
0
        public IHttpActionResult ChartData()
        {
            try
            {
                ChartDeMeritCountViewModel chart = new ChartDeMeritCountViewModel();
                //chart.adPannel = new ChartDeMeritViewModel();
                //chart.cancel = new ChartDeMeritViewModel();
                //chart.punish = new ChartDeMeritViewModel();
                //chart.finePay = new ChartDeMeritViewModel();
                chart.adPannel = new List <int>();
                chart.cancel   = new List <int>();
                chart.punish   = new List <int>();
                chart.finePay  = new List <int>();

                IEnumerable <MemberDeMerit> deMerits = new List <MemberDeMerit>();
                deMerits = _deMerit.GetDeMerits();
                //deMerits = deMerits.Where(x => x.DeMerit.CreatedDate.Year == DateTime.Now.Year && x.DeMerit.CreatedDate.Month == 1).Select(x => x.DeMerit.MemberId).Count();//.ToList();

                for (int i = 1; i <= 12; i++)
                {
                    DeMeritMemberTypeViewModel deMeritMemType = new DeMeritMemberTypeViewModel();
                    deMeritMemType.driver          = new DeMeritTypeSetViewModel();
                    deMeritMemType.driver.adPannel = new List <DeMeritTypeViewModel>();
                    deMeritMemType.driver.finePay  = new List <DeMeritTypeViewModel>();
                    deMeritMemType.driver.punish   = new List <DeMeritTypeViewModel>();
                    deMeritMemType.driver.cancel   = new List <DeMeritTypeViewModel>();

                    foreach (MemberDeMerit mem in deMerits.Where(x => x.DeMerit.CreatedDate.Year == DateTime.Now.Year && x.DeMerit.CreatedDate.Month == i))
                    {
                        switch (mem.Merit.ColorCodeId)
                        {
                        case 1:
                            var a = deMeritMemType.driver.cancel.Find(x => x.id == mem.DeMerit.Member.ID && x.meritId == mem.MeritId);
                            if (a == null && mem.Point > 0)
                            {
                                DeMeritTypeViewModel ad = new DeMeritTypeViewModel();
                                ad.id      = mem.DeMerit.Member.ID;
                                ad.name    = mem.DeMerit.Member.FullName;
                                ad.ntcNo   = mem.DeMerit.Member.NTCNo;
                                ad.point   = mem.Point;
                                ad.meritId = mem.MeritId;
                                deMeritMemType.driver.cancel.Add(ad);
                            }
                            else if (a != null)
                            {
                                a.point += mem.Point;
                            }
                            break;

                        case 2:
                            var b = deMeritMemType.driver.adPannel.Find(x => x.id == mem.DeMerit.Member.ID && x.meritId == mem.MeritId);
                            if (b == null && mem.Point > 0)
                            {
                                DeMeritTypeViewModel ad = new DeMeritTypeViewModel();
                                ad.id      = mem.DeMerit.Member.ID;
                                ad.name    = mem.DeMerit.Member.FullName;
                                ad.ntcNo   = mem.DeMerit.Member.NTCNo;
                                ad.point   = mem.Point;
                                ad.meritId = mem.MeritId;
                                deMeritMemType.driver.adPannel.Add(ad);
                            }
                            else if (b != null)
                            {
                                b.point += mem.Point;
                            }
                            break;

                        case 3:
                            var c = deMeritMemType.driver.punish.Find(x => x.id == mem.DeMerit.Member.ID && x.meritId == mem.MeritId);
                            if (c == null && mem.Point > 0)
                            {
                                DeMeritTypeViewModel ad = new DeMeritTypeViewModel();
                                ad.id      = mem.DeMerit.Member.ID;
                                ad.name    = mem.DeMerit.Member.FullName;
                                ad.ntcNo   = mem.DeMerit.Member.NTCNo;
                                ad.point   = mem.Point;
                                ad.meritId = mem.MeritId;
                                deMeritMemType.driver.punish.Add(ad);
                            }
                            else if (c != null)
                            {
                                c.point += mem.Point;
                            }
                            break;

                        case 4:
                            var d = deMeritMemType.driver.finePay.Find(x => x.id == mem.DeMerit.Member.ID && x.meritId == mem.MeritId);
                            if (d == null && mem.Point > 0)
                            {
                                DeMeritTypeViewModel ad = new DeMeritTypeViewModel();
                                ad.id      = mem.DeMerit.Member.ID;
                                ad.name    = mem.DeMerit.Member.FullName;
                                ad.ntcNo   = mem.DeMerit.Member.NTCNo;
                                ad.point   = mem.Point;
                                ad.meritId = mem.MeritId;
                                deMeritMemType.driver.finePay.Add(ad);
                            }
                            else if (d != null)
                            {
                                d.point += mem.Point;
                            }
                            break;

                        default:
                            break;
                        }
                    }
                    //deMeritMemType.driver.adPannel = deMeritMemType.driver.adPannel.Where(x => x.point > 2).ToList();
                    //deMeritMemType.driver.finePay = deMeritMemType.driver.finePay.Where(x => x.point > 2).ToList();
                    //deMeritMemType.driver.punish = deMeritMemType.driver.punish.Where(x => x.point > 2).ToList();
                    //deMeritMemType.driver.cancel = deMeritMemType.driver.cancel.Where(x => x.point > 2).ToList();

                    List <int> admem = new List <int>();
                    deMeritMemType.driver.adPannel = deMeritMemType.driver.adPannel.Where(x => x.point > 2).ToList();
                    admem = deMeritMemType.driver.adPannel.Select(x => x.id).Distinct().ToList();
                    deMeritMemType.driver.adPannel.Clear();
                    foreach (int j in admem)
                    {
                        Member mem = _member.GetAll(x => x.ID == j).FirstOrDefault();
                        DeMeritTypeViewModel ad = new DeMeritTypeViewModel();
                        ad.id    = mem.ID;
                        ad.name  = mem.FullName;
                        ad.ntcNo = mem.NTCNo;
                        deMeritMemType.driver.adPannel.Add(ad);
                    }
                    admem.Clear();
                    deMeritMemType.driver.finePay = deMeritMemType.driver.finePay.Where(x => x.point > 2).ToList();
                    admem = deMeritMemType.driver.finePay.Select(x => x.id).Distinct().ToList();
                    deMeritMemType.driver.finePay.Clear();
                    foreach (int j in admem)
                    {
                        Member mem = _member.GetAll(x => x.ID == j).FirstOrDefault();
                        DeMeritTypeViewModel ad = new DeMeritTypeViewModel();
                        ad.id    = mem.ID;
                        ad.name  = mem.FullName;
                        ad.ntcNo = mem.NTCNo;
                        deMeritMemType.driver.finePay.Add(ad);
                    }
                    admem.Clear();
                    deMeritMemType.driver.punish = deMeritMemType.driver.punish.Where(x => x.point > 2).ToList();
                    admem = deMeritMemType.driver.punish.Select(x => x.id).Distinct().ToList();
                    deMeritMemType.driver.punish.Clear();
                    foreach (int j in admem)
                    {
                        Member mem = _member.GetAll(x => x.ID == j).FirstOrDefault();
                        DeMeritTypeViewModel ad = new DeMeritTypeViewModel();
                        ad.id    = mem.ID;
                        ad.name  = mem.FullName;
                        ad.ntcNo = mem.NTCNo;
                        deMeritMemType.driver.punish.Add(ad);
                    }
                    admem.Clear();
                    deMeritMemType.driver.cancel = deMeritMemType.driver.cancel.Where(x => x.point > 2).ToList();
                    admem = deMeritMemType.driver.cancel.Select(x => x.id).Distinct().ToList();
                    deMeritMemType.driver.cancel.Clear();
                    foreach (int j in admem)
                    {
                        Member mem = _member.GetAll(x => x.ID == j).FirstOrDefault();
                        DeMeritTypeViewModel ad = new DeMeritTypeViewModel();
                        ad.id    = mem.ID;
                        ad.name  = mem.FullName;
                        ad.ntcNo = mem.NTCNo;
                        deMeritMemType.driver.cancel.Add(ad);
                    }

                    chart.adPannel.Add(deMeritMemType.driver.adPannel.Count());
                    chart.finePay.Add(deMeritMemType.driver.finePay.Count());
                    chart.punish.Add(deMeritMemType.driver.punish.Count());
                    chart.cancel.Add(deMeritMemType.driver.cancel.Count());
                }
                chart.adPannel[0] = 4;
                chart.adPannel[1] = 2;
                chart.adPannel[2] = 1;
                chart.adPannel[3] = 2;

                chart.finePay[0] = 1;
                chart.finePay[1] = 2;
                chart.finePay[2] = 2;
                chart.finePay[3] = 4;

                chart.punish[0] = 2;
                chart.punish[1] = 2;
                chart.punish[2] = 1;
                chart.punish[3] = 2;

                chart.cancel[0] = 3;
                chart.cancel[1] = 4;
                chart.cancel[2] = 3;
                chart.cancel[3] = 4;

                var messageData  = new { code = Constant.SuccessMessageCode, message = Constant.MessageSuccess };
                var returnObject = new { chart = chart, messageCode = messageData };
                return(Ok(returnObject));
            }
            catch (Exception ex)
            {
                string errorLogId   = _eventLog.WriteLogs(User.Identity.Name, ex, MethodBase.GetCurrentMethod().Name);
                var    messageData  = new { code = Constant.ErrorMessageCode, message = String.Format(Constant.MessageTaskmateError, errorLogId) };
                var    returnObject = new { messageCode = messageData };
                return(Ok(returnObject));
            }
        }
Ejemplo n.º 3
0
        public IHttpActionResult GetMember(int Id)
        {
            try
            {
                bool            rednotice  = false;
                bool            adpanel    = false;
                bool            finepay    = false;
                bool            punish     = false;
                bool            bestmember = true;
                MemberViewModel memberView = new MemberViewModel();
                Member          member     = new Member();
                member = _member.GetMember(Id);
                IEnumerable <DeMerit>      demerit        = new List <DeMerit>();
                DeMeritMemberTypeViewModel deMeritMemType = new DeMeritMemberTypeViewModel();
                deMeritMemType.driver          = new DeMeritTypeSetViewModel();
                deMeritMemType.driver.adPannel = new List <DeMeritTypeViewModel>();
                deMeritMemType.driver.finePay  = new List <DeMeritTypeViewModel>();
                deMeritMemType.driver.punish   = new List <DeMeritTypeViewModel>();
                deMeritMemType.driver.cancel   = new List <DeMeritTypeViewModel>();

                demerit = _demerit.GetAll(x => x.MemberId == Id).ToList();
                if (demerit != null)
                {
                    demerit = demerit.Where(y => y.CreatedDate.Date >= DateTime.Now.Date.AddMonths(-1) && y.CreatedDate <= DateTime.Now.Date.AddDays(1)).ToList();

                    foreach (DeMerit de in demerit)
                    {
                        IEnumerable <MemberDeMerit> memDe = de.MemberDeMerits.Where(x => x.DeMeritId == de.ID).ToList();
                        foreach (MemberDeMerit mem in memDe)
                        {
                            switch (mem.Merit.ColorCodeId)
                            {
                            case 1:
                                var a = deMeritMemType.driver.cancel.Find(x => x.meritId == mem.MeritId);
                                if (a == null && mem.Point > 0)
                                {
                                    DeMeritTypeViewModel ad = new DeMeritTypeViewModel();
                                    ad.id      = de.Member.ID;
                                    ad.name    = de.Member.FullName;
                                    ad.ntcNo   = de.Member.NTCNo;
                                    ad.point   = mem.Point;
                                    ad.meritId = mem.MeritId;
                                    deMeritMemType.driver.cancel.Add(ad);
                                }
                                else if (a != null && mem.Point > 0)
                                {
                                    a.point += mem.Point;
                                }
                                break;

                            case 2:
                                var b = deMeritMemType.driver.adPannel.Find(x => x.meritId == mem.MeritId);
                                if (b == null && mem.Point > 0)
                                {
                                    DeMeritTypeViewModel ad = new DeMeritTypeViewModel();
                                    ad.id      = de.Member.ID;
                                    ad.name    = de.Member.FullName;
                                    ad.ntcNo   = de.Member.NTCNo;
                                    ad.point   = mem.Point;
                                    ad.meritId = mem.MeritId;
                                    deMeritMemType.driver.adPannel.Add(ad);
                                }
                                else if (b != null && mem.Point > 0)
                                {
                                    b.point += mem.Point;
                                }
                                break;

                            case 3:
                                var c = deMeritMemType.driver.punish.Find(x => x.meritId == mem.MeritId);
                                if (c == null && mem.Point > 0)
                                {
                                    DeMeritTypeViewModel ad = new DeMeritTypeViewModel();
                                    ad.id      = de.Member.ID;
                                    ad.name    = de.Member.FullName;
                                    ad.ntcNo   = de.Member.NTCNo;
                                    ad.point   = mem.Point;
                                    ad.meritId = mem.MeritId;
                                    deMeritMemType.driver.punish.Add(ad);
                                }
                                else if (c != null && mem.Point > 0)
                                {
                                    c.point += mem.Point;
                                }
                                break;

                            case 4:
                                var d = deMeritMemType.driver.finePay.Find(x => x.meritId == mem.MeritId);
                                if (d == null && mem.Point > 0)
                                {
                                    DeMeritTypeViewModel ad = new DeMeritTypeViewModel();
                                    ad.id      = de.Member.ID;
                                    ad.name    = de.Member.FullName;
                                    ad.ntcNo   = de.Member.NTCNo;
                                    ad.point   = mem.Point;
                                    ad.meritId = mem.MeritId;
                                    deMeritMemType.driver.finePay.Add(ad);
                                }
                                else if (d != null && mem.Point > 0)
                                {
                                    d.point += mem.Point;
                                }
                                break;

                            default:
                                break;
                            }
                        }
                    }
                    List <int> admem = new List <int>();
                    deMeritMemType.driver.adPannel = deMeritMemType.driver.adPannel.Where(x => x.point > 2).ToList();
                    admem = deMeritMemType.driver.adPannel.Select(x => x.id).Distinct().ToList();
                    deMeritMemType.driver.adPannel.Clear();
                    foreach (int i in admem)
                    {
                        Member mem = _member.GetAll(x => x.ID == i).FirstOrDefault();
                        DeMeritTypeViewModel ad = new DeMeritTypeViewModel();
                        ad.id    = mem.ID;
                        ad.name  = mem.FullName;
                        ad.ntcNo = mem.NTCNo;
                        deMeritMemType.driver.adPannel.Add(ad);
                    }
                    admem.Clear();
                    deMeritMemType.driver.finePay = deMeritMemType.driver.finePay.Where(x => x.point > 2).ToList();
                    admem = deMeritMemType.driver.finePay.Select(x => x.id).Distinct().ToList();
                    deMeritMemType.driver.finePay.Clear();
                    foreach (int i in admem)
                    {
                        Member mem = _member.GetAll(x => x.ID == i).FirstOrDefault();
                        DeMeritTypeViewModel ad = new DeMeritTypeViewModel();
                        ad.id    = mem.ID;
                        ad.name  = mem.FullName;
                        ad.ntcNo = mem.NTCNo;
                        deMeritMemType.driver.finePay.Add(ad);
                    }
                    admem.Clear();
                    deMeritMemType.driver.punish = deMeritMemType.driver.punish.Where(x => x.point > 2).ToList();
                    admem = deMeritMemType.driver.punish.Select(x => x.id).Distinct().ToList();
                    deMeritMemType.driver.punish.Clear();
                    foreach (int i in admem)
                    {
                        Member mem = _member.GetAll(x => x.ID == i).FirstOrDefault();
                        DeMeritTypeViewModel ad = new DeMeritTypeViewModel();
                        ad.id    = mem.ID;
                        ad.name  = mem.FullName;
                        ad.ntcNo = mem.NTCNo;
                        deMeritMemType.driver.punish.Add(ad);
                    }
                    admem.Clear();
                    deMeritMemType.driver.cancel = deMeritMemType.driver.cancel.Where(x => x.point > 2).ToList();
                    admem = deMeritMemType.driver.cancel.Select(x => x.id).Distinct().ToList();
                    deMeritMemType.driver.cancel.Clear();
                    foreach (int i in admem)
                    {
                        Member mem = _member.GetAll(x => x.ID == i).FirstOrDefault();
                        DeMeritTypeViewModel ad = new DeMeritTypeViewModel();
                        ad.id    = mem.ID;
                        ad.name  = mem.FullName;
                        ad.ntcNo = mem.NTCNo;
                        deMeritMemType.driver.cancel.Add(ad);
                    }

                    rednotice = deMeritMemType.driver.cancel.Count() > 0 ? true : false;
                    adpanel   = deMeritMemType.driver.adPannel.Count() > 0 ? true : false;
                    finepay   = deMeritMemType.driver.finePay.Count() > 0 ? true : false;
                    punish    = deMeritMemType.driver.punish.Count() > 0 ? true : false;

                    if (demerit.Count() >= 2)
                    {
                        bestmember = false;
                    }
                    if (_complain.GetAll(x => x.ConductorId == Id || x.DriverId == Id).Count() > 2)
                    {
                        bestmember = false;
                    }
                }

                IEnumerable <Complain> complains = new List <Complain>();
                complains = _complain.GetAll(x => x.ComplainStatus == "Unresolved" && (x.DriverId == Id || x.ConductorId == Id)).ToList();

                if (member != null)
                {
                    memberView.id              = member.ID;
                    memberView.userID          = member.UserID == null ? 0 : member.UserID.Value;
                    memberView.fullName        = String.IsNullOrEmpty(member.FullName) ? String.Empty : member.FullName;
                    memberView.nameWithInitial = String.IsNullOrEmpty(member.ShortName) ? String.Empty : member.ShortName;
                    memberView.currentAddress  = String.IsNullOrEmpty(member.CurrentAddress) ? String.Empty : member.CurrentAddress;
                    memberView.permanetAddress = String.IsNullOrEmpty(member.PermanetAddress) ? String.Empty : member.PermanetAddress;
                    memberView.nic             = String.IsNullOrEmpty(member.NIC) ? String.Empty : member.NIC;
                    memberView.dob             = member.DOB.ToString("yyyy-MM-dd");
                    memberView.cetificateNo    = String.IsNullOrEmpty(member.TrainingCertificateNo) ? String.Empty : member.TrainingCertificateNo;
                    memberView.trainingCenter  = String.IsNullOrEmpty(member.TrainingCenter) ? String.Empty : member.TrainingCenter;
                    memberView.licenceNo       = String.IsNullOrEmpty(member.LicenceNo) ? String.Empty : member.LicenceNo;
                    memberView.dateIssued      = member.IssuedDate.ToString("yyyy-MM-dd");
                    memberView.dateValidity    = member.ExpireDate.ToString("yyyy-MM-dd");
                    memberView.dateJoin        = member.JoinDate.ToString("yyyy-MM-dd");
                    memberView.educationQuali  = String.IsNullOrEmpty(member.HighestEducation) ? String.Empty : member.HighestEducation;
                    memberView.type            = member.MemberType.Code;
                    memberView.imagePath       = member.ImagePath;
                    memberView.isNotification1 = rednotice;
                    memberView.notification1   = rednotice ? "Red Noticed" : String.Empty;
                    memberView.isNotification2 = bestmember && memberView.isNotification1 == false ? true : false;
                    memberView.notification2   = bestmember && memberView.isNotification1 == false ? "Best " + member.MemberType.Code : String.Empty;
                    memberView.isNotification3 = complains.Count() > 0 && complains != null ? true : false;
                    memberView.notification3   = complains.Count() > 0 && complains != null?complains.Count() + " Unresolved Complains" : String.Empty;

                    memberView.isNotification4 = adpanel;
                    memberView.notification4   = adpanel ? "Advising Panel ": String.Empty;
                    memberView.isNotification5 = finepay;
                    memberView.notification5   = finepay ? "Fine Payments" : String.Empty;
                    memberView.isNotification6 = punish;
                    memberView.notification6   = punish ? "Punishment Training" : String.Empty;
                }


                var messageData  = new { code = Constant.SuccessMessageCode, message = Constant.MessageSuccess };
                var returnObject = new { member = memberView, messageCode = messageData };
                return(Ok(returnObject));
            }
            catch (Exception ex)
            {
                string errorLogId   = _eventLog.WriteLogs(User.Identity.Name, ex, MethodBase.GetCurrentMethod().Name);
                var    messageData  = new { code = Constant.ErrorMessageCode, message = String.Format(Constant.MessageTaskmateError, errorLogId) };
                var    returnObject = new { messageCode = messageData };
                return(Ok(returnObject));
            }
        }