Example #1
0
        public static void DeleteScore(int idGame)
        {
            try
            {
                using (var ctx = new PollaExpressDBEntities())
                {
                    //verify if the school exists
                    Score oScore = GetScoreByKey(idGame);

                    if (oScore != null)
                    {
                        // if exists then edit
                        ctx.Score.Attach(oScore);
                        ctx.Score.Remove(oScore);
                        ctx.SaveChanges();
                    }
                }
            }
            catch (DbUpdateException ex)
            {
                if (ex.InnerException.InnerException.Message.Contains("REFERENCE constraint"))
                {
                    throw new Exception("No se puede eliminar esta sede porque existe informaciĆ³n asociada a esta.");
                }
            }
            catch (Exception ex) { throw ex; }
        }
        /// <summary>
        /// Delete a mimetype
        /// </summary>
        /// <param name="mimetypeTarget"></param>
        public static void Deletemimetype(mimetype mimetypeTarget)
        {
            try
            {
                using (var ctx = new PollaExpressDBEntities())
                {
                    //verify if the school exists
                    mimetype omimetype = GetMimeType(mimetypeTarget.Id);

                    if (omimetype != null)
                    {
                        // if exists then edit
                        ctx.mimetype.Attach(omimetype);
                        ctx.mimetype.Remove(omimetype);
                        ctx.SaveChanges();
                    }
                }
            }
            catch (DbUpdateException ex)
            {
                if (ex.InnerException.InnerException.Message.Contains("REFERENCE constraint"))
                {
                    throw new Exception("No se puede eliminar este grado porque existe informaciĆ³n asociada a este.");
                }
            }
            catch (Exception ex) { throw ex; }
        }
Example #3
0
        /*CRUD score*/
        public static List<Score> GetScoreList()
        {
            List<Score> lstScore = new List<Score>();

            try
            {
                using (var ctx = new PollaExpressDBEntities())
                {
                    ctx.Configuration.ProxyCreationEnabled = false;
                    lstScore = ctx.Score.ToList();
                }
            }
            catch (Exception ex) { throw ex; }

            return lstScore;
        }
        /*CRUD customer*/
        public static List<Customer> GetCustomerList()
        {
            List<Customer> lstCustomer = new List<Customer>();

            try
            {
                using (var ctx = new PollaExpressDBEntities())
                {
                    ctx.Configuration.ProxyCreationEnabled = false;
                    lstCustomer = ctx.Customer.ToList();
                }
            }
            catch (Exception ex) { throw ex; }

            return lstCustomer;
        }
        /// <summary>
        /// Retrieve mimetype information based in the primary key
        /// </summary>
        /// <param name="mimetypeTarget"></param>
        /// <returns></returns>
        public static mimetype GetMimeType(string extension)
        {
            mimetype omimetype = new mimetype();

            try
            {
                using (var ctx = new PollaExpressDBEntities())
                {
                    ctx.Configuration.ProxyCreationEnabled = false;

                    omimetype = ctx.mimetype.Where(x => x.extension == extension).FirstOrDefault();
                }
            }
            catch (Exception ex) { throw ex; }

            return omimetype;
        }
Example #6
0
        public static Score GetScoreByKey(int idGame)
        {
            Score oScore = new Score();

            try
            {
                using (var ctx = new PollaExpressDBEntities())
                {
                    ctx.Configuration.ProxyCreationEnabled = false;

                    oScore =
                        ctx.Score.Where(x => x.idGame.Equals(idGame)).FirstOrDefault();
                }
            }
            catch (Exception ex) { throw ex; }

            return oScore;
        }
        public static Customer GetCustomerByKey(string id)
        {
            Customer oCustomer = new Customer();

            try
            {
                using (var ctx = new PollaExpressDBEntities())
                {
                    ctx.Configuration.ProxyCreationEnabled = false;

                    oCustomer =
                        ctx.Customer.Where(x => x.id == id).FirstOrDefault();
                }
            }
            catch (Exception ex) { throw ex; }

            return oCustomer;
        }
Example #8
0
        public static void SaveScore(Score score)
        {
            try
            {
                using (var ctx = new PollaExpressDBEntities())
                {
                    //verify if the student exists
                    Score oScore = GetScoreByKey(score.idGame);

                    if (oScore != null)
                    {
                        // if exists then edit
                        ctx.Score.Attach(oScore);
                        EntityFrameworkHelper.EnumeratePropertyDifferences(oScore, score);
                        ctx.SaveChanges();
                    }
                    else
                    {
                        // else create
                        ctx.Score.Add(score);
                        ctx.SaveChanges();
                    }
                }

            }
            catch (DbEntityValidationException e)
            {
                StringBuilder oError = new StringBuilder();
                foreach (var eve in e.EntityValidationErrors)
                {
                    oError.AppendLine(string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                        eve.Entry.Entity.GetType().Name, eve.Entry.State));

                    foreach (var ve in eve.ValidationErrors)
                    {
                        oError.AppendLine(string.Format("- Property: \"{0}\", Error: \"{1}\"",
                            ve.PropertyName, ve.ErrorMessage));
                    }
                }
                string msg = oError.ToString();
                throw new Exception(msg);
            }
            catch (Exception ex) { throw ex; }
        }