Ejemplo n.º 1
0
 public static bool add(ProductToGMH pTgmh, List <string> photos)
 {
     using (DAL.Charity_DBEntities db = new DAL.Charity_DBEntities())
     {
         db.PRODUCTtoGMH.Add(Converters.ProductToGmhConverter.convertToDal(pTgmh));
         photos.ForEach(p =>
         {
             DAL.Images image       = new DAL.Images();
             image.Path             = p;
             image.ProductCodeToGMH = pTgmh.ProductCodeToGMH;
             db.Images.Add(image);
         });
         try
         {
             db.SaveChanges();
             return(true);
         }
         catch (DbEntityValidationException ex) {
             foreach (var entityValidationErrors in ex.EntityValidationErrors)
             {
                 foreach (var validationError in entityValidationErrors.ValidationErrors)
                 {
                     System.Diagnostics.Debug.WriteLine(
                         "Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);
                 }
             }
             System.Diagnostics.Debug.WriteLine("no");
             return(false);
         }
     }
 }
Ejemplo n.º 2
0
 public static DTO.Images convertToDTO(DAL.Images i)
 {
     return(new DTO.Images
     {
         ProductCodeToGMH = i.ProductCodeToGMH,
         Path = i.Path,
         ImageCode = i.ImageCode
     });
 }
Ejemplo n.º 3
0
        public static bool edit(ProductToGMH pTgmh, List <string> photos)
        {
            using (DAL.Charity_DBEntities db = new DAL.Charity_DBEntities())
            {
                db.PRODUCTtoGMH.FirstOrDefault(p => p.ProductCodeToGMH == pTgmh.ProductCodeToGMH).FreeDescription       = pTgmh.FreeDescription;
                db.PRODUCTtoGMH.FirstOrDefault(p => p.ProductCodeToGMH == pTgmh.ProductCodeToGMH).IsDisposable          = pTgmh.IsDisposable;
                db.PRODUCTtoGMH.FirstOrDefault(p => p.ProductCodeToGMH == pTgmh.ProductCodeToGMH).Status                = pTgmh.Status;
                db.PRODUCTtoGMH.FirstOrDefault(p => p.ProductCodeToGMH == pTgmh.ProductCodeToGMH).SecurityDepositAmount = pTgmh.SecurityDepositAmount;
                db.PRODUCTtoGMH.FirstOrDefault(p => p.ProductCodeToGMH == pTgmh.ProductCodeToGMH).ProductCode           = pTgmh.ProductCode;

                photos.ForEach(p =>
                {
                    DAL.Images image       = new DAL.Images();
                    image.Path             = p;
                    image.ProductCodeToGMH = pTgmh.ProductCodeToGMH;
                    db.Images.Add(image);
                });
                try
                {
                    db.SaveChanges();
                    return(true);
                }
                catch (DbEntityValidationException ex)
                {
                    foreach (var entityValidationErrors in ex.EntityValidationErrors)
                    {
                        foreach (var validationError in entityValidationErrors.ValidationErrors)
                        {
                            System.Diagnostics.Debug.WriteLine(
                                "Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);
                        }
                    }
                    System.Diagnostics.Debug.WriteLine("no");
                    return(false);
                }
            }
        }