Avatar of lulu50
lulu50
Flag for United States of America asked on

Populate the list if there's not match

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

.NET MVC* ASP .NET MVC 5C#

Avatar of undefined
Last Comment
lulu50

8/22/2022 - Mon
ste5an

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?
lulu50

ASKER
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
lulu50

ASKER
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

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER CERTIFIED SOLUTION
it_saige

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
lulu50

ASKER
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!!!!!!!!
lulu50

ASKER
saige,

Thank you is not enough

can I say Thank you ++   lol lol