Beispiel #1
0
        public int UpdateEsameByPk(IDAL.VO.EsameVO data, string esamidid)
        {
            Stopwatch tw = new Stopwatch();

            tw.Start();

            int result = 0;

            try
            {
                long           esamidid_ = long.Parse(esamidid);
                hlt_esameradio esam      = hltCC.hlt_esameradio.First(t => t.esameidid == esamidid_);

                hlt_esameradio data_ = EsameMapper.EsamMapper(data);

                foreach (System.Reflection.PropertyInfo prop in data_.GetType().GetProperties())
                {
                    if (esam.GetType().GetProperty(prop.Name) != null)
                    {
                        object val = prop.GetValue(data_, null);
                        esam.GetType().GetProperty(prop.Name).SetValue(esam, Convert.ChangeType(val, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType), null);
                    }
                }

                result = hltCC.SaveChanges();
                log.Info(string.Format("Entity Framework Query Executed! Updated {0} record!", result));
            }
            catch (Exception ex)
            {
                log.Info(string.Format("Entity Framework Query Executed! Updated 0 record!"));
                string msg = "An Error occured! Exception detected!";
                log.Info(msg);
                log.Error(msg + "\n" + ex.Message);
            }

            tw.Stop();

            log.Info(string.Format("Completed! Elapsed time {0}", LibString.TimeSpanToTimeHmsms(tw.Elapsed)));

            return(result);
        }
Beispiel #2
0
        public int AddEsame(Dictionary <string, object> data)
        {
            Stopwatch tw = new Stopwatch();

            tw.Start();

            int result = 0;

            try
            {
                hlt_esameradio esam = new hlt_esameradio();

                foreach (KeyValuePair <string, object> d_ in data)
                {
                    string origPName = d_.Key;
                    object val       = d_.Value;
                    string destPName = origPName;

                    System.Reflection.PropertyInfo prop = esam.GetType().GetProperty(destPName);

                    if (prop != null)
                    {
                        prop.SetValue(esam, Convert.ChangeType(val, prop.PropertyType), null);
                    }
                }

                hltCC.hlt_esameradio.Add(esam);
                result = hltCC.SaveChanges();
                log.Info(string.Format("Entity Framework Query Executed! Added {0} record!", result));
            }
            catch (Exception ex)
            {
                log.Info(string.Format("Entity Framework Query Executed! Added 0 record!"));
                string msg = "An Error occured! Exception detected!";
                log.Info(msg);
                log.Error(msg + "\n" + ex.Message);
            }

            tw.Stop();

            log.Info(string.Format("Completed! Elapsed time {0}", LibString.TimeSpanToTimeHmsms(tw.Elapsed)));

            return(result);
        }