/// <summary>
        /// Add a collection of test documents that are missing files on disk and are
        /// used to only test the document interface and file download issues
        ///
        /// Keywords and categories for document will be randomly selected.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="categories">The list of currently seeded categories</param>
        /// <param name="keywords">List of currently seeded keywords</param>
        public static void AddTestDocuments(DsContext context, List <Category> categories, List <Keyword> keywords)
        {
            var adminUser = context.Users.FirstOrDefault(user => user.Username == SeededUsernames.AdminUser);

            if (adminUser == null)
            {
                throw new NullReferenceException(
                          "Null pre-seeded admin user. Check Seeds and Configuratio before trying to seed Documents");
            }

            // pre-clean the list of categories and keywords

            if (categories == null)
            {
                categories = new List <Category>();
            }
            if (keywords == null)
            {
                keywords = new List <Keyword>();
            }


            AddTestDocument(context, adminUser, "Географија", "Дипломски проект за MVC апликација за изучување на географија", "Емир Османоски", categories, keywords);
            AddTestDocument(context, adminUser, "Тутор за изучување јазикот за глувонеми", "3d апликација за интерактивно изучување на македонскиот јазик на глувонемите.", "Марјан Ѓуроски", categories, keywords);
            AddTestDocument(context, adminUser, "Податочно Рударство, Уринарни Инфекции", "Опис на процес, рударење и резултат", "Емир Османоски", categories, keywords);
            AddTestDocument(context, adminUser, "Спецификација за мобилно банкарство", "Опис на систем за мобилно банкарство. Документот се состои од целокупни барања и специфицација за системот", "Група студенти", categories, keywords);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add the initial feature tiers to the system
        /// </summary>
        /// <param name="dsContext"></param>
        public static void SeedInitialFeatureTiers(DsContext dsContext)
        {
            AddFeatureTier(dsContext,
                           "Basic Feature Tier",
                           SeededTierAliases.BasicTier,
                           "The Basic Feature tier has the lowes counts for document downloads and votes for each user",
                           4,
                           4,
                           4);

            AddFeatureTier(dsContext,
                           "Standard Feature Tier",
                           SeededTierAliases.StandardTier,
                           "The Standard Feature Tier is the medium tier, providing a higher document and voting count",
                           15,
                           15,
                           15);

            AddFeatureTier(dsContext,
                           "Premium Feature Tier",
                           SeededTierAliases.PremiumTier,
                           "The Premium Tier provides the highest count of downloads and document activity per day",
                           30,
                           30,
                           30);
        }
Ejemplo n.º 3
0
        public async Task CreateCustomer(Customer customer)
        {
            var db = new DsContext();
            await db.customer.AddAsync(customer);

            await db.SaveChangesAsync();
        }
Ejemplo n.º 4
0
        public async Task CreateVendor(Vendors vendor)
        {
            var db = new DsContext();
            await db.Vendor.AddAsync(vendor);

            await db.SaveChangesAsync();
        }
        /// <summary>
        /// Add a single test document uploaded by the provided user and containing
        /// the provided properties.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="user"></param>
        /// <param name="documentTitle"></param>
        /// <param name="documentDescription"></param>
        /// <param name="authorName"></param>
        /// <param name="keywords"></param>
        /// <param name="isIndexed">Indicate if the document is indexed and is downloadable. Optional param set to true </param>
        /// <param name="categories"></param>
        public static void AddTestDocument(DsContext context, User user, string documentTitle, string documentDescription, string authorName, List <Category> categories = null, List <Keyword> keywords = null, bool isIndexed = true)
        {
            // Use current date as a mock for all the required date fields
            var currentDate = DateTime.Now;

            // only add the document if there is no such document inserted before based on the document title
            if (context.Documents.FirstOrDefault(x => x.Title == documentTitle) == null)
            {
                var document = new Document()
                {
                    AuthorName   = authorName,
                    Description  = documentDescription,
                    Title        = documentTitle,
                    User         = user,
                    Path         = "",
                    IsIndexed    = isIndexed,
                    DateCreated  = currentDate,
                    DateIndexed  = currentDate,
                    DateUploaded = currentDate,

                    Categories = ListUtilities.GetSublist(categories, _minCategories, _maxCategories > categories.Count ? categories.Count : _maxCategories),
                    Keywords   = ListUtilities.GetSublist(keywords, _minKeywords, _maxKeywords > keywords.Count ? keywords.Count : _maxKeywords),
                };

                context.Documents.AddOrUpdate(document);
            }
        }
Ejemplo n.º 6
0
        public static List <Keyword> SeedInitialKeywords(DsContext context)
        {
            SeedKeyword(context, "word", "word");
            SeedKeyword(context, "app", "app");
            SeedKeyword(context, "web", "web");
            SeedKeyword(context, "desktop", "desktop");
            SeedKeyword(context, "api", "api");
            SeedKeyword(context, "document", "document");
            SeedKeyword(context, "indexing", "indexing");

            return(_internalSeededCategories);
        }
Ejemplo n.º 7
0
 public List <Vendor> AuthenticateVendor(string username, string password)
 {
     try
     {
         var dbContext = new DsContext();
         var vendors   = dbContext.Vendors.Where(u => u.UserName == username && u.Password == password);
         return(vendors.ToList());
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
 public List <Preference> GetPreference()
 {
     try
     {
         var dbContext  = new DsContext();
         var preference = dbContext.Preferences.Where(u => u.Active == 1);
         return(preference.ToList());
     }
     catch (Exception e)
     {
         return(null);
     }
 }
Ejemplo n.º 9
0
 public List <Cities> GetActiveTowns()
 {
     try
     {
         var dbContext = new DsContext();
         var town      = dbContext.city.Where(u => u.Active == 1);
         return(town.ToList());
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Ejemplo n.º 10
0
 public List <Vendor> GetVendorsByTown(int townId)
 {
     try
     {
         var dbContext = new DsContext();
         var vendors   = dbContext.Vendors.Where(u => u.Active == 1 && u.TownId == townId);
         return(vendors.ToList());
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Ejemplo n.º 11
0
 public string GetCustomerByUserName(string username, string password)
 {
     try
     {
         var dbContext = new DsContext();
         var customers = dbContext.Customer.FirstOrDefault(u => u.UserName == username && u.Password == password);
         return(JsonConvert.SerializeObject(customers));
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
 }
Ejemplo n.º 12
0
 public List <Country> GetActiveCountries()
 {
     try
     {
         var dbContext = new DsContext();
         var ctry      = dbContext.Country.Where(u => u.Active == 1);
         return(ctry.ToList());
     }
     catch (Exception ex)
     {
         Cl.InsertLog(ex.Message);
         return(null);
     }
 }
 public List <Preferences> GetPreferences()
 {
     try
     {
         var dbContext = new DsContext();
         var pref      = dbContext.preferences.Where(u => u.Active == 1);
         return(pref.ToList());
     }
     catch (Exception ex)
     {
         Cl.InsertLog(ex.Message);
         return(null);
     }
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Seeds the initial system users, including the Administrator and the Users for each of the
        /// tiers
        /// </summary>
        /// <param name="context"></param>
        public static void SeedInitialUsers(DsContext context)
        {
            // Add the administrator user with the admin role
            AddUser(context, SeededUsernames.AdminUser, "developer", "*****@*****.**", SeededTierAliases.PremiumTier, SeededRoleAliases.Administrator, SeededRoleAliases.User);

            // Add the basic user with the user role and the basic feature tier
            AddUser(context, SeededUsernames.TestBasic, "developer", "*****@*****.**", SeededTierAliases.BasicTier, SeededRoleAliases.User);

            // Add the standard user with the user role and the standard feature tier
            AddUser(context, SeededUsernames.TestStandard, "developer", "*****@*****.**", SeededTierAliases.StandardTier, SeededRoleAliases.User);

            // Add the premium user with the user role and the premium feature tier
            AddUser(context, SeededUsernames.TestPremium, "developer", "*****@*****.**", SeededTierAliases.PremiumTier, SeededRoleAliases.User);
        }
Ejemplo n.º 15
0
 public List <State> GetActiveStatesByCountry(int countryId)
 {
     try
     {
         var dbContext = new DsContext();
         var state     = dbContext.State.Where(u => u.Active == 1 && u.CountryID == countryId);
         return(state.ToList());
     }
     catch (Exception ex)
     {
         Cl.InsertLog(ex.Message);
         return(null);
     }
 }
Ejemplo n.º 16
0
 public List <City> GetActiveTownsByState(string stateId)
 {
     try
     {
         var dbContext = new DsContext();
         var town      = dbContext.City.Where(u => u.Active == 1 && u.StateID == stateId);
         return(town.ToList());
     }
     catch (Exception ex)
     {
         Cl.InsertLog(ex.Message);
         return(null);
     }
 }
Ejemplo n.º 17
0
        public async Task <ActionResult <Vendor> > PostTodoItem(Vendor vendors)
        {
            var dbContext = new DsContext();
            var vend      = dbContext.Vendors.Where(u => u.UserName == vendors.UserName && u.Password == vendors.Password);

            if (vend != null)
            {
                dbContext.Vendors.Add(vendors);
                await dbContext.SaveChangesAsync();
            }


            //return CreatedAtAction("GetTodoItem", new { id = todoItem.Id }, todoItem);
            return(CreatedAtAction(nameof(Vendor), new { id = vendors.VendorId }, vendors));
        }
        //
        // GET: /ProfilerTests/
        public ActionResult Index()
        {
            var profiler = MiniProfiler.Current;

            var db = new DsContext();

            var data = new List <string>();

            using (profiler.Step("Geting data"))
            {
                data = db.Documents.Select(t => t.Title).ToList();
            }


            return(View(model: data));
        }
Ejemplo n.º 19
0
        public async Task<IList<VendorData>> GetVendorsByMobile(string Mobile)
        {
            var db = new DsContext();
            var user = from s in db.vendors
                       where s.MobileNumber == Mobile
                       select new VendorData()
                       {
                           VendorId = s.VendorId,
                           VendorName = s.VendorName,
                           Password = s.Password,
                           MobileNumber = s.MobileNumber,
                           EmailId = s.EmailId
                       };


            return (IList<VendorData>)await user.ToListAsync();
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Seed a single category with the given display name and category alias
        /// </summary>
        /// <param name="context"></param>
        /// <param name="categoryDisplayName"></param>
        /// <param name="categoryAlias"></param>
        public static void SeedCategory(DsContext context, string categoryDisplayName, string categoryAlias)
        {
            // only add the category if there is no previousy isnerted category
            // based on the categoru alias

            if (!context.Categories.Any(x => x.Alias == categoryAlias))
            {
                var newCategory = new Category()
                {
                    Alias = categoryAlias,
                    Name  = categoryDisplayName
                };

                context.Categories.AddOrUpdate(newCategory);
                _internalSeededCategories.Add(newCategory);
            }
        }
Ejemplo n.º 21
0
        public async Task <IList <UserData> > GetUsersByMobile(string Mobile)
        {
            var db   = new DsContext();
            var user = from s in db.customer
                       where s.MobileNumber == Mobile
                       select new UserData()
            {
                UserId       = s.CustomerId,
                CustomerName = s.CustomerName,
                Password     = s.Password,
                MobileNumber = s.MobileNumber,
                EmailId      = s.EmailId
            };


            return((IList <UserData>) await user.ToListAsync());
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Add a single role to the system uniquely defined by the role alias, with the given role properties
        /// </summary>
        /// <param name="context"></param>
        /// <param name="roleTitle"></param>
        /// <param name="roleAlias"></param>
        /// <param name="roleDescription"></param>
        public static void AddRoleToContext(DsContext context, string roleTitle, string roleAlias, string roleDescription = "")
        {
            // Initially check if the role has been already added
            // only only add the role if its not been previously added
            // again based on the alias
            if (!context.Roles.Any(x => x.Alias == roleAlias))
            {
                var role = new Role();

                role.Alias       = roleAlias;
                role.Title       = roleTitle;
                role.Description = roleDescription;

                context.Roles.Add(role);

                context.SaveChanges();
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Seed a single keyword with the given display name and keyword alias
        /// </summary>
        /// <param name="context"></param>
        /// <param name="name"></param>
        /// <param name="alias"></param>
        public static void SeedKeyword(DsContext context, string name, string alias)
        {
            // only add the category if there is no previousy isnerted category
            // based on the categoru alias

            if (!context.Keywords.Any(x => x.Alias == alias))
            {
                var newKeyword = new Keyword()
                {
                    Alias = alias,
                    Name  = name
                };

                context.Keywords.AddOrUpdate(newKeyword);

                _internalSeededCategories.Add(newKeyword);
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Seed initial document categories used for categorizing uploaded documents.
        /// </summary>
        /// <param name="context"></param>
        public static List <Category> SeedInitialCategories(DsContext context)
        {
            SeedCategory(context, "Web", "web");

            SeedCategory(context, "Graduation Paper", "graduationPaper");

            SeedCategory(context, "Databases", "databases");

            SeedCategory(context, "Games", "games");

            SeedCategory(context, "Educational", "educational");

            SeedCategory(context, "Desktop", "desktop");

            SeedCategory(context, "Mobile", "mobile");

            SeedCategory(context, "Design", "design");

            SeedCategory(context, "AI", "ai");

            SeedCategory(context, "Compilers", "compilers");

            SeedCategory(context, "Probablility", "probability");

            SeedCategory(context, "Software Design", "softwareDesign");

            SeedCategory(context, "Design Patterns", "designPatterns");

            SeedCategory(context, "Algebra", "algebra");

            SeedCategory(context, "Java", "java");

            SeedCategory(context, "ASP.NET", "aspNet");

            SeedCategory(context, "MVC", "mvc");

            SeedCategory(context, "Javascript", "javascript");

            SeedCategory(context, "Front-End", "frontEnd");

            SeedCategory(context, "Back-End", "backEnd");

            return(_internalSeededCategories);
        }
Ejemplo n.º 25
0
        public string InsertCustomer(Customer cust)
        {
            try
            {
                var      dbContext = new DsContext();
                Customer custTbl   = new Customer();
                custTbl.CustomerName    = cust.CustomerName;
                custTbl.CustomerAddress = cust.CustomerAddress;

                custTbl.EmailId = cust.EmailId;
                dbContext.Customer.Add(custTbl);
                dbContext.SaveChanges();
                return("Customer Saved Successfully");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Add a User Entitiy with the given user properties
        /// </summary>
        /// <param name="context">The context to which we will be adding User Data </param>
        /// <param name="username">The username for the created User</param>
        /// <param name="password">The password for the created User</param>
        /// <param name="email">The email for the created User</param>
        /// <param name="featureTierAlias">The alias for the feature tier that will be linked with the user.</param>
        /// <param name="roleAliases">The collection of role aliases for the roles that will be linked with the user.</param>
        public static void AddUser(DsContext context, string username, string password, string email, string featureTierAlias = "", params string[] roleAliases)
        {
            // only add the user if there is no such user based on the username
            if (context.Users.FirstOrDefault(x => x.Username == username) == null)
            {
                var newUser = new User()
                {
                    Username = username,
                    Password = password,
                    Email    = email
                };

                // Add the feature tier based on the alias if such tier exsists
                // Note the tier must be created before atempting to link it to the User
                var tier = context.UserFeatureTiers.FirstOrDefault(x => x.TierAlias == featureTierAlias);

                if (tier != null)
                {
                    newUser.UserFeatureTier = tier;
                }

                // Link users to existing  roles based on the aliases if the role exists
                newUser.UserRoles = new List <Role>();

                foreach (var roleAlias in roleAliases)
                {
                    var role = context.Roles.FirstOrDefault(x => x.Alias == roleAlias);

                    if (role != null)
                    {
                        newUser.UserRoles.Add(role);
                    }
                }

                // add the user to the context
                context.Users.AddOrUpdate(newUser);

                // Save the user changes after adding each user entitiy
                context.SaveChanges();
            }
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Add a single Feature Tier with the given properties.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="tierName"></param>
        /// <param name="tierAlias"></param>
        /// <param name="tierDescription"></param>
        /// <param name="downloadsPerDay"> </param>
        /// <param name="upvotesPerDay"> </param>
        /// <param name="downvotesPerDay"> </param>
        public static void AddFeatureTier(DsContext context, string tierName, string tierAlias, string tierDescription = "", int downloadsPerDay = 5, int upvotesPerDay = 5, int downvotesPerDay = 5)
        {
            // we will only add a tier if its not been added before
            // based on the tier alias

            if (!context.UserFeatureTiers.Any(x => x.TierAlias == tierAlias))
            {
                var userFeatureTier = new UserFeatureTier();

                userFeatureTier.TierAlias       = tierAlias;
                userFeatureTier.TierDescription = tierDescription;
                userFeatureTier.TierName        = tierName;

                userFeatureTier.DocumentDownloadsPerDay = downloadsPerDay;
                userFeatureTier.DocumentUpvotesPerDay   = upvotesPerDay;
                userFeatureTier.DocumentDownvotesPerDay = downvotesPerDay;

                context.UserFeatureTiers.Add(userFeatureTier);

                context.SaveChanges();
            }
        }
 public KeywordRepository()
 {
     _context = (DsContext)ObjectFactory.GetInstance <DbContext>();
 }
Ejemplo n.º 29
0
 /// <summary>
 /// Add the initial seed of roles used in the system on the given context
 /// </summary>
 /// <param name="context"></param>
 public static void SeedInitialRoles(DsContext context)
 {
     AddRoleToContext(context, "Administrator", SeededRoleAliases.Administrator, "The Administrators control and have access to management functionality for users and uploaded documents");
     AddRoleToContext(context, "User", SeededRoleAliases.User, "Regular application registered users that can perform actions regarding documents based on the set feature tier");
 }
Ejemplo n.º 30
0
 public UserRepository()
 {
     _dsContext = (DsContext)ObjectFactory.GetInstance <DbContext>();
 }