Example #1
0
        public bool DeleteUser(string user)
        {
            string provjera = "";
            try
            {
                fantasyEntities db = new fantasyEntities();

                user a = db.user.Where(k => k.email == user).FirstOrDefault();
                if (a == null) provjera = "nema";
                else
                {
                    db.user.Attach(a);
                    db.user.Remove(a);

                    db.SaveChanges();
                }
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    provjera = eve.Entry.Entity.GetType().Name + " " + eve.Entry.State;
                    foreach (var ve in eve.ValidationErrors)
                    {
                        provjera = ve.PropertyName + " " + ve.ErrorMessage;
                    }
                }

            }

            if (provjera.Equals("")) return true;
            else return false;
        }
Example #2
0
        public bool DeleteEvent(string ID)
        {
            string provjera = "";
            try
            {
                fantasyEntities db = new fantasyEntities();

                events e = db.events.Where(k => k.idEvents.ToString() == ID).FirstOrDefault();
                if (e == null) provjera = "nema";
                else
                {
                    db.events.Attach(e);
                    db.events.Remove(e);

                    db.SaveChanges();
                }
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    provjera = eve.Entry.Entity.GetType().Name + " " + eve.Entry.State;
                    foreach (var ve in eve.ValidationErrors)
                    {
                        provjera = ve.PropertyName + " " + ve.ErrorMessage;
                    }
                }

            }

            if (provjera.Equals("")) return true;
            else return false;
        }
Example #3
0
        public bool CreateUser(string obj)
        {
            string provjera="";

            try
            {
                fantasyEntities db = new fantasyEntities();

                DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(user));
                MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(obj));
                user a = db.user.Add((user)ser.ReadObject(ms));
                db.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    provjera = eve.Entry.Entity.GetType().Name + " " + eve.Entry.State;
                    foreach (var ve in eve.ValidationErrors)
                    {
                        provjera= ve.PropertyName+" "+ve.ErrorMessage;
                    }
                }

            }

            if(provjera.Equals("")) return true;
            else return false;
        }
Example #4
0
 public bool InsertImage(string path, string mail)
 {
     string provjera = "";
     try
     {
         fantasyEntities db = new fantasyEntities();
         var context = db.user.Where(a => a.email == mail).FirstOrDefault();
         if (context == null)
             provjera = "nema";
         else
         {
             context.image = path;
             db.SaveChanges();
         }
     }
     catch (DbEntityValidationException e)
     {
         foreach (var eve in e.EntityValidationErrors)
         {
             provjera = eve.Entry.Entity.GetType().Name + " " + eve.Entry.State;
             foreach (var ve in eve.ValidationErrors)
             {
                 provjera = ve.PropertyName + " " + ve.ErrorMessage;
             }
         }
     }
     if (provjera.Equals("")) return true;
     else return false;
 }
Example #5
0
        public bool UpdateEvent(string obj, string ID)
        {
            string provjera = "";

            try
            {
                fantasyEntities db = new fantasyEntities();

                DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(events));
                MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(obj));
                events e = db.events.Where(k => k.idEvents.ToString() == ID).FirstOrDefault();
                if (e == null) provjera = "nema";
                e = (events)ser.ReadObject(ms);

                db.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    provjera = eve.Entry.Entity.GetType().Name + " " + eve.Entry.State;
                    foreach (var ve in eve.ValidationErrors)
                    {
                        provjera = ve.PropertyName + " " + ve.ErrorMessage;
                    }
                }

            }

            if (provjera.Equals("")) return true;
            else return false;
        }