Ejemplo n.º 1
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;
             }
         }
     }
 }
Ejemplo n.º 2
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;
                    }
                }
            }
        }
Ejemplo n.º 3
0
 public void DeleteCountry(CountryModel Country)
 {
     if (Country == null)
     {
         throw new ArgumentNullException();
     }
     using (AppTourEntities data = new AppTourEntities())
     {
         COUNTRY current = data.COUNTRY.Where(x => x.ID == Country.Id).SingleOrDefault();
         if (current != null)
         {
             try
             {
                 data.DeleteObject(current);
                 data.SaveChanges();
             }
             catch (Exception e)
             {
                 if (e.InnerException != null)
                 {
                     throw new Exception(e.InnerException.Message);
                 }
                 throw;
             }
         }
     }
 }
Ejemplo n.º 4
0
        public void UpdateCountry(CountryModel Country)
        {
            using (AppTourEntities data = new AppTourEntities())
            {
                COUNTRY current = data.COUNTRY.Where(x => Country.Id == x.ID).SingleOrDefault();
                if (current != null)
                {
                    try
                    {
                        current.COUNTRY_CODE = Country.CountryCode;
                        current.NAME         = Country.Name;
                        current.ISO          = Country.ISO;
                        current.ISO3         = Country.ISO3;
                        current.COUNTRY_NAME = Country.CountryName;

                        data.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        if (e.InnerException != null)
                        {
                            throw new Exception(e.InnerException.Message);
                        }
                        throw;
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public Guid InsertAuthor(AuthorModel Author)
        {
            Guid id = Guid.NewGuid();

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

            using (AppTourEntities data = new AppTourEntities())
            {
                AUTHOR _new = new AUTHOR
                {
                    ID            = id,
                    ENTERPRISE    = data.ENTERPRISE.Where(f => f.ID == Author.Enterprise.Id).FirstOrDefault(),
                    NAME          = Author.Name,
                    REALNAME      = Author.RealName,
                    EMAIL         = Author.Email,
                    CREATION_DATE = DateTime.Now,
                    UPDATE_DATE   = DateTime.Now
                };

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

            return(id);
        }
Ejemplo n.º 6
0
        public Guid InsertCountry(CountryModel Country)
        {
            Guid id = Guid.NewGuid();

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

            using (AppTourEntities data = new AppTourEntities())
            {
                COUNTRY _new = new COUNTRY
                {
                    ID           = id,
                    NAME         = Country.Name,
                    COUNTRY_CODE = Country.CountryCode,
                    COUNTRY_NAME = Country.CountryName,
                    ISO          = Country.ISO,
                    ISO3         = Country.ISO3
                };

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

            return(id);
        }
Ejemplo n.º 7
0
        public bool Deactivate(UserModel user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            using (AppTourEntities data = new AppTourEntities())
            {
                USER current = data.USER.Where(p => p.ID == user.Id).SingleOrDefault();
                if (current != null)
                {
                    try
                    {
                        current.IS_ACTIVE   = false;
                        current.UPDATE_DATE = DateTime.Now;

                        data.SaveChanges();

                        return(true);
                    }
                    catch (Exception e)
                    {
                        if (e.InnerException != null)
                        {
                            throw new Exception(e.InnerException.Message);
                        }
                        throw;
                    }
                }
                return(false);
            }
        }
Ejemplo n.º 8
0
        public void UpdateAuthor(AuthorModel Author)
        {
            using (AppTourEntities data = new AppTourEntities())
            {
                AUTHOR current = data.AUTHOR.Where(x => Author.Id == x.ID).SingleOrDefault();
                if (current != null)
                {
                    try
                    {
                        current.ENTERPRISE    = data.ENTERPRISE.Where(f => f.ID == Author.Id).FirstOrDefault();
                        current.NAME          = Author.Name;
                        current.REALNAME      = Author.RealName;
                        current.EMAIL         = Author.Email;
                        current.CREATION_DATE = Author.CreationDate;
                        current.UPDATE_DATE   = DateTime.Now;

                        data.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        if (e.InnerException != null)
                        {
                            throw new Exception(e.InnerException.Message);
                        }
                        throw;
                    }
                }
            }
        }
Ejemplo n.º 9
0
 public void DeleteUser(UserModel user)
 {
     if (user == null)
     {
         throw new ArgumentNullException();
     }
     using (AppTourEntities data = new AppTourEntities())
     {
         USER current = data.USER.Where(p => p.ID == user.Id).SingleOrDefault();
         if (current != null)
         {
             try
             {
                 data.DeleteObject(current);
                 data.SaveChanges();
             }
             catch (Exception e)
             {
                 if (e.InnerException != null)
                 {
                     throw new Exception(e.InnerException.Message);
                 }
                 throw;
             }
         }
     }
 }
Ejemplo n.º 10
0
        public void UpdateUser(UserModel user)
        {
            using (AppTourEntities data = new AppTourEntities())
            {
                USER current = data.USER.Where(x => user.Id == x.ID).SingleOrDefault();
                if (current != null)
                {
                    try
                    {
                        current.REALNAME      = user.RealName;
                        current.IS_ACTIVE     = user.IsActive;
                        current.CREATION_DATE = user.CreationDate;
                        current.UPDATE_DATE   = DateTime.Now;

                        data.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        if (e.InnerException != null)
                        {
                            throw new Exception(e.InnerException.Message);
                        }
                        throw;
                    }
                }
            }
        }
Ejemplo n.º 11
0
        public void UpdateAgent(AgentModel agentModel)
        {
            using (AppTourEntities data = new AppTourEntities())
            {
                AGENTS current = data.AGENTS.SingleOrDefault(x => x.ID == agentModel.Id);

                if (current != null)
                {
                    try
                    {
                        current.NAME                = agentModel.Name;
                        current.IS_ACTIVE           = agentModel.IsActive;
                        current.LAST_EXECUTION_DATE = agentModel.LastExecutionDate;
                        current.MAX_REQUEST_PER_DAY = agentModel.MaxRequestPerDay;
                        current.PERIODICITY         = agentModel.Periodicity;
                        current.RATING              = agentModel.Rating;
                        current.LAST_REFERENCE      = agentModel.LastReference;

                        data.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        if (e.InnerException != null)
                        {
                            throw new Exception(e.InnerException.Message);
                        }
                        throw;
                    }
                }
            }
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
0
        public Guid InsertApp(AppModel App)
        {
            Guid id = Guid.NewGuid();

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

            using (AppTourEntities data = new AppTourEntities())
            {
                APP _new = new APP
                {
                    ID            = id,
                    ENTERPRISE    = data.ENTERPRISE.Where(f => f.ID == App.Enterprise.Id).FirstOrDefault(),
                    NAME          = App.Name,
                    DESCRIPTION   = App.Description,
                    VERSION       = App.Version,
                    URL           = App.URL,
                    CREATION_DATE = DateTime.Now,
                    UPDATE_DATE   = DateTime.Now
                };

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

            return(id);
        }
Ejemplo n.º 14
0
        public Guid InsertLanguage(LanguageModel language)
        {
            if (language == null)
            {
                throw new NullReferenceException("language");
            }

            Guid id = (language.Id == null || language.Id == Guid.Empty ? Guid.NewGuid() : language.Id);

            using (AppTourEntities data = new AppTourEntities())
            {
                LANGUAGE _new = new LANGUAGE
                {
                    ID        = id,
                    NAME      = language.Name,
                    ISO2      = language.ISO2,
                    IS_ACTIVE = language.IsActive
                };

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

            return(id);
        }
Ejemplo n.º 15
0
        public Guid InsertComment(CommentModel Comment)
        {
            if (Comment == null)
            {
                throw new NullReferenceException();
            }

            using (AppTourEntities data = new AppTourEntities())
            {
                COMMENT _new = new COMMENT
                {
                    ID            = (Comment.Id == null || Comment.Id == Guid.Empty ? Guid.NewGuid() : Comment.Id),
                    EVENT         = (Comment.Event != null ? data.EVENT.SingleOrDefault(x => x.ID.Equals(Comment.Event.Id)) : null),
                    POINT         = (Comment.Point != null ? data.POINT.SingleOrDefault(x => x.ID.Equals(Comment.Point.Id)) : null),
                    IS_REPORTED   = Comment.IsReported,
                    IS_ACTIVE     = Comment.IsActive,
                    USER          = data.USER.SingleOrDefault(x => x.ID.Equals(Comment.User.Id)),
                    COMMENT1      = Comment.Comment,
                    CREATION_DATE = DateTime.Now
                };

                data.COMMENT.AddObject(_new);
                data.SaveChanges();

                return(_new.ID);
            }
        }
Ejemplo n.º 16
0
        public void DeleteEnterprise(LanguageModel language)
        {
            if (language == null)
            {
                throw new ArgumentNullException("language");
            }

            using (AppTourEntities data = new AppTourEntities())
            {
                LANGUAGE current = data.LANGUAGE.Where(p => p.ID == language.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)
                    {
                        throw;
                    }
                }
            }
        }
Ejemplo n.º 17
0
        public void UpdateLanguage(LanguageModel language)
        {
            using (AppTourEntities data = new AppTourEntities())
            {
                LANGUAGE current = data.LANGUAGE.Where(x => language.Id == x.ID).SingleOrDefault();

                if (current != null)
                {
                    try
                    {
                        current.NAME      = language.Name;
                        current.ISO2      = language.ISO2;
                        current.IS_ACTIVE = language.IsActive;

                        data.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        if (e.InnerException != null)
                        {
                            throw new Exception(e.InnerException.Message);
                        }
                        throw;
                    }
                }
            }
        }
Ejemplo n.º 18
0
        public void UpdateCity(CityModel City)
        {
            using (AppTourEntities data = new AppTourEntities())
            {
                CITY current = data.CITY.Where(x => City.Id == x.ID).SingleOrDefault();
                if (current != null)
                {
                    try
                    {
                        current.COUNTRY = data.COUNTRY.Where(x => x.ID == City.Country.Id).SingleOrDefault();
                        current.NAME    = City.Name;

                        data.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        if (e.InnerException != null)
                        {
                            throw new Exception(e.InnerException.Message);
                        }
                        throw;
                    }
                }
            }
        }
Ejemplo n.º 19
0
 public void DeleteCity(CityModel City)
 {
     if (City == null)
     {
         throw new ArgumentNullException();
     }
     using (AppTourEntities data = new AppTourEntities())
     {
         CITY current = data.CITY.Where(x => x.ID == City.Id).SingleOrDefault();
         if (current != null)
         {
             try
             {
                 data.DeleteObject(current);
                 data.SaveChanges();
             }
             catch (UpdateException upx)
             {
                 throw new UpdateException(upx.InnerException.Message);
             }
             catch (Exception e)
             {
                 if (e.InnerException != null)
                 {
                     throw new Exception(e.InnerException.Message);
                 }
                 throw;
             }
         }
     }
 }
Ejemplo n.º 20
0
        public void DeleteTheme(ThemeModel theme)
        {
            if (theme == null)
            {
                throw new ArgumentNullException();
            }
            using (AppTourEntities data = new AppTourEntities())
            {
                THEME current = data.THEME.Where(p => p.ID == theme.Id).SingleOrDefault();
                if (current != null)
                {
                    try
                    {
                        current.IS_ACTIVE = false;

                        data.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        if (e.InnerException != null)
                        {
                            throw new Exception(e.InnerException.Message);
                        }
                        throw;
                    }
                }
            }
        }
Ejemplo n.º 21
0
        public void UpdateTheme(ThemeModel theme)
        {
            using (AppTourEntities data = new AppTourEntities())
            {
                THEME current = data.THEME.Where(x => theme.Id == x.ID).SingleOrDefault();
                if (current != null)
                {
                    try
                    {
                        current.NAME          = theme.Name;
                        current.DESCRIPTION   = theme.Description;
                        current.IMAGE         = theme.Image;
                        current.IS_ACTIVE     = theme.IsActive;
                        current.CREATION_DATE = theme.CreationDate;
                        current.UPDATE_DATE   = DateTime.Now;

                        data.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        if (e.InnerException != null)
                        {
                            throw new Exception(e.InnerException.Message);
                        }
                        throw;
                    }
                }
            }
        }
Ejemplo n.º 22
0
        public void AddNewVote(ClassificationModel Classification)
        {
            if (Classification == null)
            {
                throw new NullReferenceException();
            }

            if (Classification.Point != null)
            {
                int value = GetClassificationForPoint(Classification.Point).Where(x => x.User.Id == Classification.User.Id).Count();

                if (value > 0)
                {
                    return;
                }
            }

            using (AppTourEntities data = new AppTourEntities())
            {
                CLASSIFICATION _new = new CLASSIFICATION
                {
                    ID              = (Classification.Id == null || Classification.Id == Guid.Empty ? Guid.NewGuid() : Classification.Id),
                    EVENT           = (Classification.Event != null ? data.EVENT.SingleOrDefault(x => x.ID.Equals(Classification.Event.Id)) : null),
                    POINT           = (Classification.Point != null ? data.POINT.SingleOrDefault(x => x.ID.Equals(Classification.Point.Id)) : null),
                    CLASSIFICATION1 = Classification.Classification,
                    USER            = data.USER.SingleOrDefault(x => x.ID.Equals(Classification.User.Id)),
                    CREATION_DATE   = DateTime.Now
                };

                data.CLASSIFICATION.AddObject(_new);
                data.SaveChanges();
            }
        }
Ejemplo n.º 23
0
        public Guid InsertTheme(ThemeModel theme)
        {
            Guid id = Guid.NewGuid();

            if (theme == null)
            {
                throw new NullReferenceException("theme");
            }

            using (AppTourEntities data = new AppTourEntities())
            {
                THEME _new = new THEME
                {
                    ID            = id,
                    NAME          = theme.Name,
                    DESCRIPTION   = theme.Description,
                    IMAGE         = theme.Image,
                    IS_ACTIVE     = theme.IsActive,
                    CREATION_DATE = DateTime.Now,
                    UPDATE_DATE   = DateTime.Now
                };

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

            return(id);
        }
Ejemplo n.º 24
0
        public Guid InsertPointAttribute(PointAttributeModel pointAttribute)
        {
            if (pointAttribute == null)
            {
                throw new NullReferenceException("pointAttribute");
            }

            using (AppTourEntities data = new AppTourEntities())
            {
                POINTS_ATTRIBUTES novo = new POINTS_ATTRIBUTES
                {
                    ID           = (pointAttribute.Id == null || pointAttribute.Id == Guid.Empty ? Guid.NewGuid() : pointAttribute.Id),
                    POINT        = data.POINT.Single(x => x.ID.Equals(pointAttribute.Point.Id)),
                    KEYPAIR      = pointAttribute.KeyPair,
                    VALUE_BOOL   = pointAttribute.Value_bool,
                    VALUE_STRING = pointAttribute.Value_string,
                    VALUE_DATE   = pointAttribute.Value_Date,
                    VALUE_NUMBER = pointAttribute.Value_number,
                    VALUE_TYPE   = pointAttribute.Value_Type,
                    IS_ACTIVE    = pointAttribute.IsActive
                };

                data.POINTS_ATTRIBUTES.AddObject(novo);
                data.SaveChanges();

                return(novo.ID);
            }
        }
Ejemplo n.º 25
0
        public void UpdateTranslation(TranslationModel translation)
        {
            using (AppTourEntities data = new AppTourEntities())
            {
                try
                {
                    TRANSLATIONS edited = data.TRANSLATIONS.Single(x => translation.Id == x.ID);

                    if (edited != null)
                    {
                        edited.TABLE_NAME = translation.TableName;
                        edited.FIELD_NAME = translation.FieldName;
                        edited.VALUE      = translation.Value;
                        edited.LANGUAGE   = data.LANGUAGE.Single(x => x.ID.Equals(translation.Language.Id));
                        edited.FOREIGN_ID = translation.ForeignId;
                        data.SaveChanges();
                    }
                }
                catch (Exception e)
                {
                    if (e.InnerException != null)
                    {
                        throw new Exception(e.InnerException.Message);
                    }
                    throw;
                }
            }
        }
Ejemplo n.º 26
0
        public void DeletePointAttribute(PointAttributeModel pointAttributeModel)
        {
            if (pointAttributeModel == null)
            {
                throw new ArgumentNullException("pointAttributeModel");
            }

            using (AppTourEntities data = new AppTourEntities())
            {
                try
                {
                    POINTS_ATTRIBUTES current = data.POINTS_ATTRIBUTES.Single(p => p.ID == pointAttributeModel.Id);

                    if (current != null)
                    {
                        data.POINTS_ATTRIBUTES.DeleteObject(current);
                        data.SaveChanges();
                    }
                }
                catch (Exception e)
                {
                    if (e.InnerException != null)
                    {
                        throw new Exception(e.InnerException.Message);
                    }
                    throw;
                }
            }
        }
Ejemplo n.º 27
0
        public void UpdateApp(AppModel App)
        {
            using (AppTourEntities data = new AppTourEntities())
            {
                APP current = data.APP.Where(x => App.Id == x.ID).SingleOrDefault();
                if (current != null)
                {
                    try
                    {
                        current.NAME          = App.Name;
                        current.ENTERPRISE    = data.ENTERPRISE.Where(f => f.ID == App.Enterprise.Id).FirstOrDefault();
                        current.DESCRIPTION   = App.Description;
                        current.VERSION       = App.Version;
                        current.URL           = App.URL;
                        current.CREATION_DATE = App.CreationDate;
                        current.UPDATE_DATE   = DateTime.Now;

                        data.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        if (e.InnerException != null)
                        {
                            throw new Exception(e.InnerException.Message);
                        }
                        throw;
                    }
                }
            }
        }
Ejemplo n.º 28
0
 public void DeleteApp(AppModel App)
 {
     if (App == null)
     {
         throw new ArgumentNullException();
     }
     using (AppTourEntities data = new AppTourEntities())
     {
         APP current = data.APP.Where(p => p.ID == App.Id).SingleOrDefault();
         if (current != null)
         {
             try
             {
                 data.DeleteObject(current);
                 data.SaveChanges();
             }
             catch (Exception e)
             {
                 if (e.InnerException != null)
                 {
                     throw new Exception(e.InnerException.Message);
                 }
                 throw;
             }
         }
     }
 }
Ejemplo n.º 29
0
 public void DeleteTopic(TopicModel topic)
 {
     if (topic == null)
     {
         throw new ArgumentNullException();
     }
     using (AppTourEntities data = new AppTourEntities())
     {
         TOPIC current = data.TOPIC.Where(p => p.ID == topic.Id).SingleOrDefault();
         if (current != null)
         {
             try
             {
                 data.DeleteObject(current);
                 data.SaveChanges();
             }
             catch (Exception e)
             {
                 if (e.InnerException != null)
                 {
                     throw new Exception(e.InnerException.Message);
                 }
                 throw;
             }
         }
     }
 }
Ejemplo n.º 30
0
        public Guid InsertSearchProfile(SearchProfileModel searchProfile)
        {
            using (AppTourEntities data = new AppTourEntities())
            {
                try
                {
                    SEARCH_PROFILE novo = new SEARCH_PROFILE
                    {
                        ID   = searchProfile.Id == null || searchProfile.Id == Guid.Empty ? Guid.NewGuid() : searchProfile.Id,
                        NAME = searchProfile.Name,
                        POINTS_RANGE_DISTANCE = searchProfile.PointsRangeDistance,
                        SEARCH_CRITERIA       = searchProfile.SearchCriteria,
                        EVENTS_SEARCH_DAYS    = searchProfile.EventsSearchDays,
                        CREATION_DATE         = DateTime.Now,
                        UPDATE_DATE           = DateTime.Now,
                        IS_ACTIVE             = searchProfile.IsActive,
                        USER = data.USER.Single(x => x.ID == searchProfile.Utilizador.Id)
                    };

                    if (searchProfile.SearchProfileTopics != null && searchProfile.SearchProfileTopics.Count() > 0)
                    {
                        // Adicionar Atributos
                        searchProfile.SearchProfileTopics.ToList().ForEach(x => novo.SEARCH_PROFILE_TOPIC.Add(new SEARCH_PROFILE_TOPIC
                        {
                            ID             = Guid.NewGuid(),
                            TOPIC          = data.TOPIC.SingleOrDefault(y => y.ID == x.Id),
                            SEARCH_PROFILE = novo
                        }));
                    }

                    // Guardar tudo

                    data.SEARCH_PROFILE.AddObject(novo);
                    data.SaveChanges();

                    return(novo.ID);
                }
                catch (UpdateException upd)
                {
                    throw new UpdateException(upd.InnerException.Message);
                }
                catch (Exception e)
                {
                    if (e.InnerException != null)
                    {
                        throw new ApplicationException(e.InnerException.Message);
                    }

                    throw;
                }
            }
        }