internal string SaveMapping(CLOToPLO CLOToPLO, string name)
        {
            try
            {
                CLOToPLO.CLO = CLOService.FindById(CLOToPLO.CLO.Id, name);

                if (CLOToPLO.MapPLOLists.Count > 0)
                {
                    foreach (var item in CLOToPLO.MapPLOLists)
                    {
                        CLOToPLOMapping CLOToPLOMapping = new CLOToPLOMapping()
                        {
                            CLO    = CLOToPLO.CLO,
                            PLO    = PLOService.FindById(item.PLO.Id, name),
                            Points = item.Points
                        };
                        if (!IsExistMapping(CLOToPLOMapping, name))
                        {
                            Save(CLOToPLOMapping, name);
                        }
                    }
                    return(null);
                }
                else
                {
                    return(Messages.InvalidField);
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
                return(ex.Message);
            }
        }
 private string IsValidCLOToPLOMapping(CLOToPLOMapping CLOToPLOMapping, string currentUsername)
 {
     try
     {
         if (CLOService.FindById(CLOToPLOMapping.CLO.Id, currentUsername) != null)
         {
             if (PLOService.FindById(CLOToPLOMapping.PLO.Id, currentUsername) != null)
             {
                 return(null);
             }
             else
             {
                 return(Messages.PLONotFound);
             }
         }
         else
         {
             return(Messages.CLONotFound);
         }
     }
     catch (Exception ex)
     {
         Logger.Log(ex);
         return(Messages.Issue);
     }
 }
        public string Delete(int Id, string CurrentUsername)
        {
            CLOToPLOMapping CLOToPLOMapping = FindById(Id, CurrentUsername);

            if (CLOToPLOMapping != null)
            {
                return(CLOToPLOMappingRepository.Delete(Id) ? null : Messages.IssueInDatabase);
            }
            else
            {
                return(Messages.NotFound);
            }
        }
 private bool IsExistMapping(CLOToPLOMapping CLOToPLOMapping, string name)
 {
     try
     {
         var ExistmapPLOs = FindByCLOId(CLOToPLOMapping.CLO.Id, name).MapPLOLists.FindAll(st => st.PLO.Id == CLOToPLOMapping.PLO.Id);
         return((ExistmapPLOs.Count > 0) ? true : false);
     }
     catch (Exception ex)
     {
         Logger.Log(ex);
         return(false);
     }
 }
 internal string UpdateMapping(CLOToPLO CLOToPLO, string name)
 {
     try
     {
         if (CLOToPLO.MapPLOLists.Count > 0)
         {
             CLOToPLO.CLO = CLOService.FindById(CLOToPLO.CLO.Id, name);
             if (CLOToPLO != null)
             {
                 foreach (var item in CLOToPLO.MapPLOLists)
                 {
                     CLOToPLOMapping CLOToPLOMapping = new CLOToPLOMapping()
                     {
                         CLO    = CLOToPLO.CLO,
                         PLO    = PLOService.FindById(item.PLO.Id, name),
                         Points = item.Points
                     };
                     if (!IsExistMapping(CLOToPLOMapping, name))
                     {
                         Save(CLOToPLOMapping, name);
                     }
                     else
                     {
                         var deleteorUpdate = FindAll(name).Find(mp => mp.CLO.Id == CLOToPLOMapping.CLO.Id && mp.PLO.Id == CLOToPLOMapping.PLO.Id);
                         CLOToPLOMapping.Id = deleteorUpdate.Id;
                         Update(CLOToPLOMapping, name);
                     }
                 }
                 return(null);
             }
             else
             {
                 return(Messages.CLONotFound);
             }
         }
         else
         {
             return(Messages.InvalidField);
         }
     }
     catch (Exception ex)
     {
         Logger.Log(ex);
         return(ex.Message);
     }
 }
        public string Update(CLOToPLOMapping CLOToPLOMapping, string CurrentUsername)
        {
            string message = IsValidCLOToPLOMapping(CLOToPLOMapping, CurrentUsername);

            if (FindById(CLOToPLOMapping.Id, CurrentUsername) != null)
            {
                if (String.IsNullOrEmpty(message))
                {
                    return(CLOToPLOMappingRepository.Update(CLOToPLOMapping) ? null : Messages.IssueInDatabase);
                }
                else
                {
                    return(Messages.CLONotFound);
                }
            }
            else
            {
                return(Messages.NotFound);
            }
        }
        public List <CLOToPLOMapping> FindAll()
        {
            List <CLOToPLOMapping> allCLOToPLOMapping = new List <CLOToPLOMapping>();

            try
            {
                using (connection = Database.GetConnection())
                {
                    using (command = new MySqlCommand(Views.ALLCLOToPLOMapping, connection))
                    {
                        command.CommandType = CommandType.Text;
                        connection.Open();
                        using (reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                CLOToPLOMapping CLOToPLOMapping = new CLOToPLOMapping
                                {
                                    Id  = reader.GetInt32("id"),
                                    PLO = new PLO()
                                    {
                                        Id = reader.GetInt32("plo_id")
                                    },
                                    CLO = new CLO()
                                    {
                                        Id = reader.GetInt32("clo_id")
                                    },
                                    Points = reader.GetFloat("points")
                                };
                                allCLOToPLOMapping.Add(CLOToPLOMapping);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }
            return(allCLOToPLOMapping);
        }
        public bool Save(CLOToPLOMapping CLOToPLOMapping)
        {
            int status = 0;

            using (connection = Database.GetConnection())
            {
                try
                {
                    using (command = new MySqlCommand(Procedures.SaveCLOToPLOMapping, connection))
                    {
                        command.CommandType = CommandType.StoredProcedure;
                        SetAllParameters(CLOToPLOMapping);

                        connection.Open();
                        status = command.ExecuteNonQuery();
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log(ex);
                }
            }
            return((status > 0) ? true : false);
        }
        public CLOToPLOMapping FindById(int id, string CurrentUsername)
        {
            CLOToPLOMapping CLOToPLOMapping = FindAll(CurrentUsername).Find(mtp => mtp.Id == id);

            return(CLOToPLOMapping);
        }
 private void SetAllParameters(CLOToPLOMapping CLOToPLOMapping)
 {
     command.Parameters.Add(new MySqlParameter("@PLOId", CLOToPLOMapping.PLO.Id));
     command.Parameters.Add(new MySqlParameter("@CLOId", CLOToPLOMapping.CLO.Id));
     command.Parameters.Add(new MySqlParameter("@Points", CLOToPLOMapping.Points));
 }