We help IT Professionals succeed at work.

Populate the list if there's not match

lulu50
lulu50 asked
on
High Priority
84 Views
Last Modified: 2020-03-01
Hi,

my syntax is wrong

I need your help please

  public List<MissedCommitID> MissedCommitIDList(CABRManagement model)
        {
            List<MissedCommitID> MissedCommitIDList = new List<MissedCommitID>();

       
          // Here I want to check if MigrationCommitID  matches CommitID then populate the list MissedCommitIDList 


          // MigrationCommitID and CommitID fields are stored in the model.RuleDetailList
 

          //if both fields do not have the same data then populate the new list. "MissedCommitIDList "



 var MissedCommitID = _unitOfWorkCABusinessRules.RuleDetailRepo.Where(x => x.RuleDetailId == model.RuleDetailList.Where(m => m.RuleDetailID == x.RuleDetailId));

 MissedCommitIDList = MissedCommitIDList.ToList().Select(x => new MissedCommitID
            {
                CQticket = model.RuleDetailList.Select(x => x.CQTicket);
                UserName =
                Version =
                Environment =
                commitID =

               }).ToList();

Open in new window




   public List<RuleDetailMgm> RuleDetailList { get; set; }

        public class RuleDetailMgm
        {
            public int RuleDetailID { get; set; }
            public string CQTicket { get; set; }
            public string Environments { get; set; }
            public string Versions { get; set; }
            public string RuleSet { get; set; }
            public string RuleIdentifier { get; set; }
            public string CommitID { get; set; }
            public string MigrationCommitID { get; set; }
            public string SubmitterLastNameFirstName { get; set; }
            public DateTime MigrationDate { get; set; }
            public DateTime CreatedDate { get; set; }
            public int CountOfAttachedDocuments { get; set; }
            
        }


RuleDetailRepo table fields

RuleDetailId	int	Unchecked
isActive	bit	Checked
RuleSetId	int	Unchecked
RuleIdentifierId	int	Unchecked
Version	varchar(50)	Unchecked
Environment	varchar(50)	Unchecked
CQTicket	varchar(250)	Unchecked
CommitID	varchar(1000)	Checked
MigrationCommitID	varchar(1000)	Checked



 public List<MissedCommitID> MissedCommitIDList { get; set; }

        public class MissedCommitID
        {
            public string CQticket { get; set; }
            public string UserName { get; set; }
            public string Version { get; set; }
            public string Environment { get; set; }
            public string commitID { get; set;  }
            public string MigrationCommitID { get; set; }
        }

Open in new window

Comment
Watch Question

ste5anSenior Developer
CERTIFIED EXPERT

Commented:
Please post a concise and complete example. This normally means a console program as a single file showing your concrete problem. When such a concise sample is too hard to craft - well, I never had such a case - then post only compiling, partial classes showing your problem.

At least: Format your posted code. Unnecessary empty lines or unnecessary comments are making reading too hard..

And finally: Post your error message, what CS code?
lulu50Web application

Author

Commented:
Hi ste5an,

Thank you for your help.

ok

I'm having problem explaining what I'm trying to do.

I have a list and a table .

What I want is to check to see if the Version, CQticket exist in the list matches with what's in the table.
once I have a matching version and CQtickets then I need to check if the commitID that is in the list exist in the table MigrationCommitID

so if the MigrationCommitID from the list do not exist in the CommitID then I need to populate the data in a new list.




this is where the data stored in my list.

  public List<RuleDetailMgm> RuleDetailList { get; set; }

        public class RuleDetailMgm
        {
            public int RuleDetailID { get; set; }
            public string CQTicket { get; set; }
            public string Versions { get; set; }
            public string CommitID { get; set; }
            public DateTime MigrationDate { get; set; }
        }


the table is called  "MissedMigration"

MissedMigration

MissedMigrationID      int      Unchecked
Version      varchar(250)      Unchecked
CQTicket      varchar(250)      Unchecked
MigrationCommitID      varchar(250)      Unchecked
MigrationDate      datetime      Unchecked



so I started working on the function

 public List<MissedCommitID> MissedCommitIDList(CABRManagement model)
        {
            List<MissedCommitID> MissedCommitIDList = new List<MissedCommitID>();

            IEnumerable<CABR_MissedMigration> list = new List<CABR_MissedMigration>();

            list = _unitOfWorkCABusinessRules.MissedMigrationRepo.GetAll().ToList();

           foreach (var element in model.RuleDetailList)
            {
               

            }

          //I don't know how to do this here
         
          //I want to loop thru my list and select all the version and CQticket that matches in the table called MissedMigration
         //then I have to compare between the two if the commitID has any data in the MigrationCommitID

         //if commitID

return MissedCommitIDList;
        }


the data inside each tables are as follow:

MissedMigration Table

MissedMigrationID         Version              CQTicket        MigrationCommitID            MigrationDate
1                                       Version33        ENT19293          346365676                         2020-02-12 00:00:00.000   //Passed because it exist in the list
3                                       Version22        ENT95837          553564646                         2020-02-01 00:00:00.000   //Passed because it exist in the list
4                                       version 5        ENT83745          756555666                         2020-02-07 00:00:00.000   //will not pass, not in the list  
5                                      Version33        ENT19293          844333556                          2020-02-12 00:00:00.000  //will not pass, not in the list  

RuleDetailList

 RuleDetailID    CQTicket             Versions               CommitID                                        MigrationDate
16                      ENT19293             Version33            344555533, 346365676            2020-02-12 00:00:00.000              
17                      ENT19293             Version33            343322234                                   2020-02-12 00:00:00.000              
18                      ENT95837             Version22            553564646                                   2020-02-01 00:00:00.000
19                      ENT83745             version 5               755446654                                   2020-02-07 00:00:00.000


The output that I want will look list this:

Version             CQticket           MigrationCommitID
version 5                ENT83745          756555666
Version33        ENT19293          844333556
lulu50Web application

Author

Commented:
It's not working   (I want x.MigrationCommitID is not in element.CommitID.

  public List<MissedCommitID> MissedCommitIDList(CABRManagement model)
        {
            List<MissedCommitID> MissedCommitIDList = new List<MissedCommitID>();

            IEnumerable<CABR_MissedMigration> list = new List<CABR_MissedMigration>();

            list = _unitOfWorkCABusinessRules.MissedMigrationRepo.GetAll().ToList();


            foreach (var element in model.RuleDetailList)
            {
                list = list.Where(x => x.Version == element.Versions && x.CQTicket == element.CQTicket && !x.MigrationCommitID.Contains(element.CommitID)).ToList();
            }


            return MissedCommitIDList;
        }

Open in new window



  foreach (var element in model.RuleDetailList)
            {
                list = list.Where(x => x.Version == element.Versions && x.CQTicket == element.CQTicket && !x.MigrationCommitID.Any(m => Equals(element.CommitID)));
            }

Open in new window

Developer
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
You could do something like this:
private List<MissedCommit> GetMissedCommits(CABRManagement model)
{
    var missed = _unitOfWorkCABusinessRules.MissedMigrationRepo.GetAll().ToList();
    var groups = model.RuleDetailList.GroupBy(d => new { d.CQTicket, d.Versions }).Select(g => new RuleDetailMgm { CQTicket = g.Key.CQTicket, Versions = g.Key.Versions, CommitID = string.Join(", ", g.Select(d => d.CommitID)) });
    return (from miss in missed
            from detail in groups
            let commits = detail.CommitID.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(c => c.Trim())
            where Equals(detail.CQTicket, miss.CQTicket) && Equals(detail.Versions, miss.Version) && !commits.Any(c => Equals(c, miss.MigrationCommitId))
            select new MissedCommit { CQTicket = miss.CQTicket, Version = miss.Version, MigrationCommitId = miss.MigrationCommitId }).ToList();
}

Open in new window

Proof of concept -
using System;
using System.Collections.Generic;
using System.Linq;

namespace EE_Q29174095
{
    class Program
    {
        static void Main(string[] args)
        {
            var details = new[]
            {
                new RuleDetailMgm { RuleDetailID = 16, CQTicket = "ENT19293", Versions = "Version33", CommitID = "344555533, 346365676", MigrationDate = new DateTime(2020, 2, 12) },
                new RuleDetailMgm { RuleDetailID = 17, CQTicket = "ENT19293", Versions = "Version33", CommitID = "343322234", MigrationDate = new DateTime(2020, 2, 12) },
                new RuleDetailMgm { RuleDetailID = 18, CQTicket = "ENT95837", Versions = "Version22", CommitID = "553564646", MigrationDate = new DateTime(2020, 2, 1) },
                new RuleDetailMgm { RuleDetailID = 19, CQTicket = "ENT83745", Versions = "Version 5", CommitID = "755446654", MigrationDate = new DateTime(2020, 2, 7) }
            };

            var missed = GetMissedCommits(details);
            foreach (var miss in missed)
            {
                Console.WriteLine(miss);
            }
            Console.ReadLine();
        }

        static List<MissedCommit> GetMissedCommits(RuleDetailMgm[] details)
        {
            var missed = new[]
            {
                new MissedMigration { MissedMigrationId = 1, Version = "Version33", CQTicket = "ENT19293", MigrationCommitId = "346365676", MigrationDate = new DateTime(2020, 2, 12)},
                new MissedMigration { MissedMigrationId = 3, Version = "Version22", CQTicket = "ENT95837", MigrationCommitId = "553564646", MigrationDate = new DateTime(2020, 2, 1)},
                new MissedMigration { MissedMigrationId = 4, Version = "Version 5", CQTicket = "ENT83745", MigrationCommitId = "756555666", MigrationDate = new DateTime(2020, 2, 7)},
                new MissedMigration { MissedMigrationId = 5, Version = "Version33", CQTicket = "ENT19293", MigrationCommitId = "844333556", MigrationDate = new DateTime(2020, 2, 12)}
            };

            var groups = details.GroupBy(d => new { d.CQTicket, d.Versions }).Select(g => new RuleDetailMgm { CQTicket = g.Key.CQTicket, Versions = g.Key.Versions, CommitID = string.Join(", ", g.Select(d => d.CommitID)) });
            return (from miss in missed
                    from detail in groups
                    let commits = detail.CommitID.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(c => c.Trim())
                    where Equals(detail.CQTicket, miss.CQTicket) && Equals(detail.Versions, miss.Version) && !commits.Any(c => Equals(c, miss.MigrationCommitId))
                    select new MissedCommit { CQTicket = miss.CQTicket, Version = miss.Version, MigrationCommitId = miss.MigrationCommitId }).ToList();
        }
    }

    class RuleDetailMgm
    {
        public int RuleDetailID { get; set; }
        public string CQTicket { get; set; }
        public string Versions { get; set; }
        public string CommitID { get; set; }
        public DateTime MigrationDate { get; set; }
    }

    class MissedMigration
    {
        public int MissedMigrationId { get; set; }
        public string Version { get; set; }
        public string CQTicket { get; set; }
        public string MigrationCommitId { get; set; }
        public DateTime MigrationDate { get; set; }
    }

    class MissedCommit
    {
        public string Version { get; set; } 
        public string CQTicket { get; set; }
        public string MigrationCommitId { get; set; }
        public override string ToString()
        {
            return $"{{ Version: {Version}, CQTicket = {CQTicket}, MigrationCommitId = {MigrationCommitId} }}";
        }
    }
}

Open in new window

Produces the following output -Capture.PNG-saige-
lulu50Web application

Author

Commented:
Saige,

I don't know what to say.

it is just beautiful!!!!!  

I love it !!!!!! I love it !!!!! and one more time I love it!!!!

What a gift you have and thank you for sharing your gift with me and everyone else that needs your help.

I have something that I need to fix
it's about the drop down list CommitID

I going to give it a try first but once I give up I'll post my question for it.  

Thank you so much

YOU ARE THE BEST!!!!!!!!
lulu50Web application

Author

Commented:
saige,

Thank you is not enough

can I say Thank you ++   lol lol

Explore More ContentExplore courses, solutions, and other research materials related to this topic.