Esempio n. 1
0
        internal string SaveMapping(PLOToPEO PLOToPEO, string name)
        {
            try
            {
                PLOToPEO.PLO = PLOService.FindById(PLOToPEO.PLO.Id, name);

                if (PLOToPEO.MapPEOLists.Count > 0)
                {
                    foreach (var item in PLOToPEO.MapPEOLists)
                    {
                        PLOToPEOMapping PLOToPEOMapping = new PLOToPEOMapping()
                        {
                            PLO    = PLOToPEO.PLO,
                            PEO    = PEOService.FindById(item.PEO.Id, name),
                            Points = item.Points
                        };
                        if (!IsExistMapping(PLOToPEOMapping, name))
                        {
                            Save(PLOToPEOMapping, name);
                        }
                    }
                    return(null);
                }
                else
                {
                    return(Messages.InvalidField);
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
                return(ex.Message);
            }
        }
        public bool Update(PLOToPEOMapping PLOToPEOMapping)
        {
            int status = 0;

            using (connection = Database.GetConnection())
            {
                try
                {
                    using (command = new MySqlCommand(Procedures.UpdatePLOToPEOMapping, connection))
                    {
                        command.CommandType = CommandType.StoredProcedure;
                        command.Parameters.Add(new MySqlParameter("@Id", PLOToPEOMapping.Id));
                        SetAllParameters(PLOToPEOMapping);

                        connection.Open();
                        status = command.ExecuteNonQuery();
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log(ex);
                }
            }
            return((status > 0) ? true : false);
        }
Esempio n. 3
0
        public string Delete(int Id, string CurrentUsername)
        {
            PLOToPEOMapping PLOToPEOMapping = FindById(Id, CurrentUsername);

            if (PLOToPEOMapping != null)
            {
                return(PLOToPEOMappingRepository.Delete(Id) ? null : Messages.IssueInDatabase);
            }
            else
            {
                return(Messages.NotFound);
            }
        }
Esempio n. 4
0
 private bool IsExistMapping(PLOToPEOMapping PLOToPEOMapping, string name)
 {
     try
     {
         var ExistmapPEOs = FindByPLOId(PLOToPEOMapping.PLO.Id, name).MapPEOLists.FindAll(st => st.PEO.Id == PLOToPEOMapping.PEO.Id);
         return((ExistmapPEOs.Count > 0) ? true : false);
     }
     catch (Exception ex)
     {
         Logger.Log(ex);
         return(false);
     }
 }
Esempio n. 5
0
 internal string UpdateMapping(PLOToPEO PLOToPEO, string name)
 {
     try
     {
         if (PLOToPEO.MapPEOLists.Count > 0)
         {
             PLOToPEO.PLO = PLOService.FindById(PLOToPEO.PLO.Id, name);
             if (PLOToPEO != null)
             {
                 foreach (var item in PLOToPEO.MapPEOLists)
                 {
                     PLOToPEOMapping PLOToPEOMapping = new PLOToPEOMapping()
                     {
                         PLO    = PLOToPEO.PLO,
                         PEO    = PEOService.FindById(item.PEO.Id, name),
                         Points = item.Points
                     };
                     if (!IsExistMapping(PLOToPEOMapping, name))
                     {
                         Save(PLOToPEOMapping, name);
                     }
                     else
                     {
                         var deleteorUpdate = FindAll(name).Find(mp => mp.PLO.Id == PLOToPEOMapping.PLO.Id && mp.PEO.Id == PLOToPEOMapping.PEO.Id);
                         PLOToPEOMapping.Id = deleteorUpdate.Id;
                         Update(PLOToPEOMapping, name);
                     }
                 }
                 return(null);
             }
             else
             {
                 return(Messages.PLONotFound);
             }
         }
         else
         {
             return(Messages.InvalidField);
         }
     }
     catch (Exception ex)
     {
         Logger.Log(ex);
         return(ex.Message);
     }
 }
Esempio n. 6
0
 private string IsValidPLOToPEOMapping(PLOToPEOMapping PLOToPEOMapping, string currentUsername)
 {
     if (PLOService.FindById(PLOToPEOMapping.PLO.Id, currentUsername) != null)
     {
         if (PEOService.FindById(PLOToPEOMapping.PEO.Id, currentUsername) != null)
         {
             return(null);
         }
         else
         {
             return(Messages.PEONotFound);
         }
     }
     else
     {
         return(Messages.PLONotFound);
     }
 }
Esempio n. 7
0
        public string Update(PLOToPEOMapping PLOToPEOMapping, string CurrentUsername)
        {
            string message = IsValidPLOToPEOMapping(PLOToPEOMapping, CurrentUsername);

            if (FindById(PLOToPEOMapping.Id, CurrentUsername) != null)
            {
                if (String.IsNullOrEmpty(message))
                {
                    return(PLOToPEOMappingRepository.Update(PLOToPEOMapping) ? null : Messages.IssueInDatabase);
                }
                else
                {
                    return(Messages.PLONotFound);
                }
            }
            else
            {
                return(Messages.NotFound);
            }
        }
        public List <PLOToPEOMapping> FindAll()
        {
            List <PLOToPEOMapping> allPLOToPEOMapping = new List <PLOToPEOMapping>();

            try
            {
                using (connection = Database.GetConnection())
                {
                    using (command = new MySqlCommand(Views.ALLPLOToPEOMapping, connection))
                    {
                        command.CommandType = CommandType.Text;
                        connection.Open();
                        using (reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                PLOToPEOMapping PLOToPEOMapping = new PLOToPEOMapping
                                {
                                    Id  = reader.GetInt32("id"),
                                    PLO = new PLO()
                                    {
                                        Id = reader.GetInt32("plo_id")
                                    },
                                    PEO = new PEO()
                                    {
                                        Id = reader.GetInt32("peo_id")
                                    },
                                    Points = reader.GetFloat("points")
                                };
                                allPLOToPEOMapping.Add(PLOToPEOMapping);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }
            return(allPLOToPEOMapping);
        }
Esempio n. 9
0
        public PLOToPEOMapping FindById(int id, string CurrentUsername)
        {
            PLOToPEOMapping PLOToPEOMapping = FindAll(CurrentUsername).Find(mtp => mtp.Id == id);

            return(PLOToPEOMapping);
        }
 private void SetAllParameters(PLOToPEOMapping PLOToPEOMapping)
 {
     command.Parameters.Add(new MySqlParameter("@PLOId", PLOToPEOMapping.PLO.Id));
     command.Parameters.Add(new MySqlParameter("@PEOId", PLOToPEOMapping.PEO.Id));
     command.Parameters.Add(new MySqlParameter("@Points", PLOToPEOMapping.Points));
 }