예제 #1
0
 //get by photo id
 public List <Proprietate> GetProprietatiById(int idPhoto)
 {
     using (ctx = new ModelBDContainer())
     {
         return(ctx.Proprietati.Where(p => p.Photo.PhotoId == idPhoto).ToList());
     }
 }
예제 #2
0
 //get by PropertyValue and propertyName
 public List <Proprietate> GetProprietatiByNameAndValue(String numeP, String valoareP)
 {
     using (ctx = new ModelBDContainer())
     {
         return(ctx.Proprietati.Where(p => p.ValoareProprietate == valoareP && p.NumeProprietate == numeP).ToList());
     }
 }
        //delete Prop
        public String DeleteProprietate(int idProp)
        {
            using (ctx = new ModelBDContainer())
            {
                try
                {
                    var number = ctx.Proprietati.Where(k => k.ProprietateId == idProp).Count();
                    if (number != 1)
                    {
                        return("Can't find property.");
                    }

                    var obj = ctx.Proprietati.Where(k => k.ProprietateId == idProp).SingleOrDefault();

                    if (obj == null)
                    {
                        return("Can't find property.");
                    }

                    ctx.Entry(obj).Reference(d => d.Photo).Load();
                    var tempPh = obj.Photo;
                    tempPh.Proprietates.Remove(obj);
                    ctx.Proprietati.Remove(obj);
                    ctx.SaveChanges();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                    return("Unexpected exception.");
                }

                return("Ok");
            }
        }
예제 #4
0
 // get by descriere
 public List <Photo> GetPhotosByDescriere(String descriere)
 {
     using (ctx = new ModelBDContainer())
     {
         return(ctx.Photos.Where(p => p.Descriere == descriere).ToList());
     }
 }
예제 #5
0
        //delete Prop
        public String DeleteProprietate(string path, string nume, string val)
        {
            using (ctx = new ModelBDContainer())
            {
                try
                {
                    var number = ctx.Proprietati.Where(k => k.Photo.Path == path && k.NumeProprietate == nume && k.ValoareProprietate == val).Count();
                    if (number != 1)
                    {
                        return("Can't find property.");
                    }

                    var obj = ctx.Proprietati.Where(k => k.Photo.Path == path && k.NumeProprietate == nume && k.ValoareProprietate == val).SingleOrDefault();

                    if (obj == null)
                    {
                        return("Can't find property.");
                    }

                    obj.Photo.Proprietates.Remove(obj);
                    ctx.Proprietati.Remove(obj);
                    ctx.SaveChanges();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                    return("Unexpected exception.");
                }

                return("Ok");
            }
        }
예제 #6
0
 // get by id
 public Photo GetPhotosById(int id)
 {
     using (ctx = new ModelBDContainer())
     {
         return(ctx.Photos.Include("Proprietates").Where(p => p.PhotoId == id).ToList().FirstOrDefault());
     }
 }
예제 #7
0
        //edit MYPhotos
        public Photo EditPhoto(int id, String path, DateTime data_creare, String description)
        {
            using (ctx = new ModelBDContainer())
            {
                try
                {
                    var photoEdit = ctx.Photos.Where(p => p.PhotoId == id).SingleOrDefault();
                    if (photoEdit == null)
                    {
                        Console.WriteLine("Can't find photo to edit.");
                        return(null);
                    }

                    photoEdit.Path        = path;
                    photoEdit.Data_creare = data_creare;
                    photoEdit.Descriere   = description;
                    ctx.SaveChanges();
                    return(photoEdit);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                    Console.WriteLine("More photos with the same id.");
                    return(null);
                }
            }
        }
예제 #8
0
 // get by data
 public List <Photo> GetPhotosByDate(DateTime date)
 {
     using (ctx = new ModelBDContainer())
     {
         return(ctx.Photos.Where(p => p.Data_creare == date).ToList());
     }
 }
예제 #9
0
 // get all
 public List <Photo> GetAllPhotos()
 {
     using (ctx = new ModelBDContainer())
     {
         return(ctx.Photos.Include("Proprietates").ToList());
     }
 }
예제 #10
0
 // get all
 public List <Photo> GetAllPhotos()
 {
     using (ctx = new ModelBDContainer())
     {
         return(ctx.Photos.ToList());
     }
 }
예제 #11
0
 // get by id
 public List <Photo> GetPhotosById(int id)
 {
     using (ctx = new ModelBDContainer())
     {
         return(ctx.Photos.Where(p => p.PhotoId == id).ToList());
     }
 }
예제 #12
0
 //get by id
 public List <Proprietate> GetAllProprietati()
 {
     using (ctx = new ModelBDContainer())
     {
         return(ctx.Proprietati.ToList());
     }
 }
예제 #13
0
        // edit Prop
        public String EditProprietate(int id, String numeP, String valoareP)
        {
            using (ctx = new ModelBDContainer())
            {
                try
                {
                    var number = ctx.Proprietati.Where(k => k.ProprietateId == id).Count();
                    if (number != 1)
                    {
                        Console.WriteLine("Can't find property or too many.");
                        return("Can't find property.");
                    }

                    var obj = ctx.Proprietati.Where(k => k.ProprietateId == id).SingleOrDefault();

                    if (obj == null)
                    {
                        return("Can't find property.");
                    }

                    obj.NumeProprietate    = numeP;
                    obj.ValoareProprietate = valoareP;
                    ctx.SaveChanges();
                    return("OK");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                    return("Unexpected exception.");
                }
            }
        }
예제 #14
0
 // get by path
 public List <Photo> GetPhotosByPath(string path)
 {
     using (ctx = new ModelBDContainer())
     {
         if (path == null)
         {
             return(null);
         }
         return(ctx.Photos.Where(p => p.Path == path).ToList());
     }
 }
        // insert : adauga o proprietate nou la o poza existenta
        public string AddProprietate(int photoid, string numeProp, string valoareProp)
        {
            using (ctx = new ModelBDContainer())
            {
                // verificare parametri
                if (photoid == 0 || numeProp == null || valoareProp == null)
                {
                    return("Empty parameters.");
                }

                try
                {
                    Photo photo = ctx.Photos.Where(p => p.PhotoId == photoid).SingleOrDefault();
                    if (photo == null)
                    {
                        return("No photo with that id.");
                    }

                    if (photo.Deleted == true)
                    {
                        return("Photo marked as deleted.");
                    }

                    Proprietate propNew = new Proprietate(numeProp, valoareProp, photo);

                    //verificare daca exista deja
                    if (ctx.Proprietati.Where(p => p.NumeProprietate == propNew.NumeProprietate && p.ValoareProprietate == propNew.ValoareProprietate && p.Photo.PhotoId == propNew.Photo.PhotoId).Any())
                    {
                        return("Already exists.");
                    }

                    ctx.Entry(photo).Collection(d => d.Proprietates).Load();
                    ctx.Proprietati.Add(propNew);
                    var colectieProp = photo.Proprietates;
                    colectieProp.Add(propNew);
                    photo.Proprietates = colectieProp;
                    ctx.SaveChanges();
                    return("OK");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                    return("More than one photo with that id.");
                }
            }
        }
예제 #16
0
        // insert : adauga in Photos o noua poza, doar fisier
        public String AddPhoto(String path, DateTime data_creare, String description)
        {
            using (ctx = new ModelBDContainer())
            {
                Photo new_photo;

                // verificare parametri
                if (path == null || data_creare == null || description == null)
                {
                    return("Empty parameters.");
                }

                // daca exista calea
                if (!File.Exists(path))
                {
                    return("File doesn't exist.");
                }

                // verificare sa nu fie deja salvata imaginea
                if (ctx.Photos.Where(p => p.Path.Equals(path)).Any() == true)
                {
                    return("File already exists.");
                }

                //verificare data -> trecut
                if (data_creare >= DateTime.Now.AddDays(1))
                {
                    return("Date not good.");
                }

                new_photo = new Photo(path, data_creare, description);

                try
                {
                    ctx.Photos.Add(new_photo);
                    ctx.SaveChanges();
                }
                catch (Exception e)
                {
                    return(e.ToString());
                }


                return("OK");
            }
        }
예제 #17
0
        //delete MYPhotos
        public String DeletePhoto(int id)
        {
            using (ctx = new ModelBDContainer())
            {
                if (id <= 0)
                {
                    return("Empty parameters");
                }

                try
                {
                    var number = ctx.Photos.Where(k => k.PhotoId == id).Count();
                    if (number != 1)
                    {
                        return("Can't find file.");
                    }

                    Photo obj = ctx.Photos.Where(k => k.PhotoId == id).SingleOrDefault();
                    if (obj == null)
                    {
                        return("Can't find file.");
                    }

                    ctx.Entry(obj).Collection(d => d.Proprietates).Load();
                    var prop = obj.Proprietates;

                    // stergem proprietatile si apoi poza
                    foreach (Proprietate item in prop)
                    {
                        ctx.Proprietati.Remove(item);
                    }


                    ctx.Photos.Remove(obj);
                    ctx.SaveChanges();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                    return(e.ToString());
                }

                return("Ok");
            }
        }
예제 #18
0
        // set deleted true
        public String MarkDeleted(int id)
        {
            using (ctx = new ModelBDContainer())
            {
                try
                {
                    var ph = ctx.Photos.Where(p => p.PhotoId == id).SingleOrDefault();
                    if (ph == null)
                    {
                        return("No file with that id to mark as deleted.");
                    }

                    ph.Deleted = true;
                    ctx.SaveChanges();
                    return("OK");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                    return("More than one file with that id");
                }
            }
        }