//------------------------------------------------------------------------------
// <auto-generated>
//    This code was generated from a template.
//
//    Manual changes to this file may cause unexpected behavior in your application.
//    Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace Terminals.Data.DB
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Infrastructure;
    using System.Data.Objects;
    using System.Data.Objects.DataClasses;
    using System.Linq;
    
    internal partial class Database : DbContext
    {
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }
    
        internal DbSet<DbBeforeConnectExecute> BeforeConnectExecute { get; set; }
        internal DbSet<DbCredentialBase> CredentialBase { get; set; }
        internal DbSet<DbDisplayOptions> DisplayOptions { get; set; }
        internal DbSet<DbFavorite> Favorites { get; set; }
        internal DbSet<DbGroup> Groups { get; set; }
        internal DbSet<DbSecurityOptions> Security { get; set; }
    
        private ObjectResult<string> GetFavoriteProtocolProperties(Nullable<int> favoriteId)
        {
            var favoriteIdParameter = favoriteId.HasValue ?
                new ObjectParameter("FavoriteId", favoriteId) :
                new ObjectParameter("FavoriteId", typeof(int));
    
            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<string>("GetFavoriteProtocolProperties", favoriteIdParameter);
        }
    
        internal virtual ObjectResult<Nullable<int>> GetFavoritesHistoryByDate(Nullable<System.DateTime> from, Nullable<System.DateTime> to)
        {
            var fromParameter = from.HasValue ?
                new ObjectParameter("From", from) :
                new ObjectParameter("From", typeof(System.DateTime));
    
            var toParameter = to.HasValue ?
                new ObjectParameter("To", to) :
                new ObjectParameter("To", typeof(System.DateTime));
    
            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<Nullable<int>>("GetFavoritesHistoryByDate", fromParameter, toParameter);
        }
    
        internal virtual int InsertHistory(Nullable<int> favoriteId, Nullable<System.DateTime> date, string userSid)
        {
            var favoriteIdParameter = favoriteId.HasValue ?
                new ObjectParameter("FavoriteId", favoriteId) :
                new ObjectParameter("FavoriteId", typeof(int));
    
            var dateParameter = date.HasValue ?
                new ObjectParameter("Date", date) :
                new ObjectParameter("Date", typeof(System.DateTime));
    
            var userSidParameter = userSid != null ?
                new ObjectParameter("UserSid", userSid) :
                new ObjectParameter("UserSid", typeof(string));
    
            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("InsertHistory", favoriteIdParameter, dateParameter, userSidParameter);
        }
    
        internal virtual int UpdateFavoriteProtocolProperties(Nullable<int> favoriteId, string protocolProperties)
        {
            var favoriteIdParameter = favoriteId.HasValue ?
                new ObjectParameter("FavoriteId", favoriteId) :
                new ObjectParameter("FavoriteId", typeof(int));
    
            var protocolPropertiesParameter = protocolProperties != null ?
                new ObjectParameter("ProtocolProperties", protocolProperties) :
                new ObjectParameter("ProtocolProperties", typeof(string));
    
            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("UpdateFavoriteProtocolProperties", favoriteIdParameter, protocolPropertiesParameter);
        }
    
        private int UpdateMasterPasswordKey(string newKey)
        {
            var newKeyParameter = newKey != null ?
                new ObjectParameter("NewKey", newKey) :
                new ObjectParameter("NewKey", typeof(string));
    
            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("UpdateMasterPasswordKey", newKeyParameter);
        }
    
        private ObjectResult<string> GetMasterPasswordKey()
        {
            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<string>("GetMasterPasswordKey");
        }
    
        public virtual int SetFavoriteIcon(Nullable<int> favoriteId, byte[] iconData)
        {
            var favoriteIdParameter = favoriteId.HasValue ?
                new ObjectParameter("FavoriteId", favoriteId) :
                new ObjectParameter("FavoriteId", typeof(int));
    
            var iconDataParameter = iconData != null ?
                new ObjectParameter("IconData", iconData) :
                new ObjectParameter("IconData", typeof(byte[]));
    
            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("SetFavoriteIcon", favoriteIdParameter, iconDataParameter);
        }
    
        private ObjectResult<byte[]> GetFavoriteIcon(Nullable<int> favoriteId)
        {
            var favoriteIdParameter = favoriteId.HasValue ?
                new ObjectParameter("FavoriteId", favoriteId) :
                new ObjectParameter("FavoriteId", typeof(int));
    
            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<byte[]>("GetFavoriteIcon", favoriteIdParameter);
        }
    
        public virtual ObjectResult<Nullable<int>> GetFavoritesInGroup(Nullable<int> groupId)
        {
            var groupIdParameter = groupId.HasValue ?
                new ObjectParameter("groupId", groupId) :
                new ObjectParameter("groupId", typeof(int));
    
            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<Nullable<int>>("GetFavoritesInGroup", groupIdParameter);
        }
    
        public virtual ObjectResult<Nullable<int>> GetFavoriteGroups(Nullable<int> favoriteId)
        {
            var favoriteIdParameter = favoriteId.HasValue ?
                new ObjectParameter("favoriteId", favoriteId) :
                new ObjectParameter("favoriteId", typeof(int));
    
            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<Nullable<int>>("GetFavoriteGroups", favoriteIdParameter);
        }
    
        public virtual int InsertFavoritesInGroup(Nullable<int> favoriteId, Nullable<int> groupId)
        {
            var favoriteIdParameter = favoriteId.HasValue ?
                new ObjectParameter("FavoriteId", favoriteId) :
                new ObjectParameter("FavoriteId", typeof(int));
    
            var groupIdParameter = groupId.HasValue ?
                new ObjectParameter("GroupId", groupId) :
                new ObjectParameter("GroupId", typeof(int));
    
            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("InsertFavoritesInGroup", favoriteIdParameter, groupIdParameter);
        }
    
        public virtual int DeleteFavoritesInGroup(Nullable<int> favoriteId, Nullable<int> groupId)
        {
            var favoriteIdParameter = favoriteId.HasValue ?
                new ObjectParameter("FavoriteId", favoriteId) :
                new ObjectParameter("FavoriteId", typeof(int));
    
            var groupIdParameter = groupId.HasValue ?
                new ObjectParameter("GroupId", groupId) :
                new ObjectParameter("GroupId", typeof(int));
    
            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("DeleteFavoritesInGroup", favoriteIdParameter, groupIdParameter);
        }
    
        public virtual int ClearHistory()
        {
            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("ClearHistory");
        }
    }
}
