Esempio n. 1
0
        public User getUserById(int _id)
        {
            try
            {
                using (var context = new altinsofraDbEntities())
                {
                    if (_id != 0)
                    {
                        var user = context.Users.Find(_id);
                        return(user);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (DbEntityValidationException e)
            {
                helper hp = new helper();
                hp.custonexception(e, "getuserbyid", "userdb");

                return(null);
            }
        }
Esempio n. 2
0
        public User updateUser(User u)
        {
            try
            {
                using (var context = new  altinsofraDbEntities())
                {
                    var user = context.Users.Find(u.Id);
                    user.Name         = u.Name;
                    user.IsActivated  = u.IsActivated;
                    user.Email        = u.Email;
                    user.Phone1       = u.Phone1;
                    user.Phone2       = u.Phone2;
                    user.Surname      = u.Surname;
                    user.UserAdresses = u.UserAdresses;
                    u.OrderCarts      = u.OrderCarts;
                    u.UserType        = u.UserType;
                    int result = context.SaveChanges();
                    return(result > 0 ? u : null);
                }
            }
            catch (DbEntityValidationException e)
            {
                helper hp = new helper();
                hp.custonexception(e, "updateUser", "userdb", u.Serializer());

                throw;
            }
        }
Esempio n. 3
0
 public Ordered AddOrdered(Ordered ordered)
 {
     try
     {
         using (var context = new altinsofraDbEntities())
         {
             context.Ordereds.Add(ordered);
             int result = context.SaveChanges();
             return((result > 0) ? ordered : null);
         }
     }
     catch (DbEntityValidationException e)
     {
         foreach (var eve in e.EntityValidationErrors)
         {
             Console.WriteLine("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)
             {
                 Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                   ve.PropertyName, ve.ErrorMessage);
             }
         }
         throw;
     }
 }
Esempio n. 4
0
        public User addUser(User user)
        {
            try
            {
                using (var context = new altinsofraDbEntities())
                {
                    context.Users.Add(user);
                    int result = context.SaveChanges();
                    return(result > 0 ? user : null);
                }
            }
            catch (DbEntityValidationException e)
            {
                helper hp = new helper();
                hp.custonexception(e, "adduser", "userdb", user.Serializer());

                throw;
            }
        }
Esempio n. 5
0
        public void custonexception(DbEntityValidationException e, string functionname, string source, params string [] parametre)
        {
            var context = new altinsofraDbEntities();

            string message = "";

            foreach (var eve in e.EntityValidationErrors)
            {
                message = "Entity of type" + eve.Entry.Entity.GetType().Name + " in state " + eve.Entry.State + "has the following validation errors:";
                foreach (var ve in eve.ValidationErrors)
                {
                    message += "- Property:" + ve.PropertyName + ", Error:" + ve.ErrorMessage + "";
                }
            }
            var log = new ExceptionLog();

            log.Message = message;

            log.FunctionName = functionname;
            log.Source       = source;
            if (parametre.Length > 0)
            {
                List <ExceptionInParameter> parameters = new List <ExceptionInParameter>();


                foreach (var item in parametre)
                {
                    parameters.Add(new ExceptionInParameter()
                    {
                        Parameter = item
                    });
                }
                log.ExceptionInParameters = parameters;
            }



            context.ExceptionLogs.Add(log);
            context.SaveChanges();
        }
Esempio n. 6
0
        public User blockeUser(int _id)
        {
            try
            {
                using (var context = new altinsofraDbEntities())
                {
                    var selected = context.Users.Find(_id);

                    selected.IsActivated = 1;

                    int result = context.SaveChanges();

                    return(result > 0 ? selected : null);
                }
            }
            catch (DbEntityValidationException e)
            {
                helper hp = new helper();
                hp.custonexception(e, "blockeuser", "userdb", _id.Serializer());
                throw;
            }
        }
Esempio n. 7
0
        public List <User> getUsers()
        {
            try
            {
                using (var context = new altinsofraDbEntities())

                {
                    var users = context.Users.ToList();

                    return(users.Count > 0 ? users : null);
                }
            }
            catch (DbEntityValidationException e)
            {
                helper hp = new helper();
                hp.custonexception(e, "getusers", "userdb");


                return(null);
            }
            ;
        }