Esempio n. 1
0
        public void UpdateEnterprise(EnterpriseModel enterprise)
        {
            using (AppTourEntities data = new AppTourEntities())
            {
                ENTERPRISE current = data.ENTERPRISE.Where(x => enterprise.Id == x.ID).SingleOrDefault();
                if (current != null)
                {
                    try
                    {
                        current.NAME          = enterprise.Name;
                        current.DESCRIPTION   = enterprise.Description;
                        current.CREATION_DATE = enterprise.CreationDate;
                        current.UPDATE_DATE   = DateTime.Now;

                        data.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        if (e.InnerException != null)
                        {
                            throw new Exception(e.InnerException.Message);
                        }
                        throw;
                    }
                }
            }
        }
Esempio n. 2
0
        public Guid InsertEnterprise(EnterpriseModel enterprise)
        {
            Guid id = Guid.NewGuid();

            if (enterprise == null)
            {
                throw new NullReferenceException();
            }

            using (AppTourEntities data = new AppTourEntities())
            {
                ENTERPRISE _new = new ENTERPRISE
                {
                    ID            = id,
                    NAME          = enterprise.Name,
                    DESCRIPTION   = enterprise.Description,
                    CREATION_DATE = DateTime.Now,
                    UPDATE_DATE   = DateTime.Now
                };

                data.ENTERPRISE.AddObject(_new);
                data.SaveChanges();
            }

            return(id);
        }
Esempio n. 3
0
 public void DeleteEnterprise(EnterpriseModel enterprise)
 {
     if (enterprise == null)
     {
         throw new ArgumentNullException();
     }
     using (AppTourEntities data = new AppTourEntities())
     {
         ENTERPRISE current = data.ENTERPRISE.Where(p => p.ID == enterprise.Id).SingleOrDefault();
         if (current != null)
         {
             try
             {
                 data.DeleteObject(current);
                 data.SaveChanges();
             }
             catch (UpdateException ex)
             {
                 if (ex.InnerException != null)
                 {
                     throw new UpdateException(ex.InnerException.Message);
                 }
                 throw;
             }
             catch (Exception e)
             {
                 if (e.InnerException != null)
                 {
                     throw new Exception(e.InnerException.Message);
                 }
                 throw;
             }
         }
     }
 }