Exemplo n.º 1
0
        private static void ConvertXml()
        {
            foreach (var filepath in Directory.EnumerateFiles(ConfigurationManager.AppSettings["ConversionFolder"]))
            {
                UserCategories  cats    = null;
                UserCategories2 newcats = null;

                Console.WriteLine($"Reading File: {filepath}");
                using (var reader = File.Open(filepath, FileMode.Open, FileAccess.Read))
                {
                    var dsrlzr = new XmlSerializer(typeof(UserCategories));
                    cats = dsrlzr.Deserialize(reader) as UserCategories;
                }

                newcats = new UserCategories2
                {
                    UserId       = cats.UserId,
                    UserName     = cats.UserName,
                    SiteFavsList = cats.SiteCategoriesList
                                   .Select(x => new SiteCategories
                    {
                        SiteId     = x.SiteId,
                        SiteName   = x.SiteName,
                        Categories = x.Categories
                                     .Select(y => new Category2
                        {
                            Name                = y.Name,
                            IncludeAllFavs      = y.IncludeAllFavs,
                            IncludeAllWorkbooks = y.IncludeAllWorkbooks,
                            Workbooks           = y.Workbooks.Select(z => new Workbook2
                            {
                                ContentUrl  = z.ContentUrl,
                                CreatedAt   = z.CreatedAt,
                                Id          = z.Id,
                                IsFavourite = z.IsFavourite,
                                Name        = z.Name,
                                Owner       = z.Owner,
                                Project     = z.Project,
                                ShowTabs    = z.ShowTabs,
                                Size        = z.Size,
                                Tags        = z.Tags,
                                UpdatedAt   = z.UpdatedAt
                            }).ToList()
                        }).ToList()
                    }
                                           ).ToList()
                };

                var convertedFilepath = ConfigurationManager.AppSettings["ConvertedFiles"] + "\\" + filepath.Split('\\').Last();
                Console.WriteLine($"Writing to file: {convertedFilepath}");
                using (var writer = File.Open(convertedFilepath, FileMode.OpenOrCreate, FileAccess.Write))
                {
                    var srlzr = new XmlSerializer(typeof(UserCategories2));
                    srlzr.Serialize(writer, newcats);
                }
            }
        }
Exemplo n.º 2
0
 private void UpdateUserCategoriesCollection()
 {
     UserCategories.Clear();
     foreach (Category category in _catService.GetCategories())
     {
         if (category.UserGuid == CurrentInformation.User.Guid)
         {
             UserCategories.Add(category);
         }
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Deletes the selected category
 /// </summary>
 private void Delete()
 {
     if (windowService.UserQuestion("Biztosan törölni szeretné a kijelölt kategóriát?", "Kategória törlése"))
     {
         using (var db = new DataModel())
         {
             var deletedUserCategory = db.UserCategory.Find(SelectedCategory.UserID, SelectedCategory.CategoryID);
             db.UserCategory.Remove(deletedUserCategory);
             db.SaveChanges();
             UserCategories.Remove(SelectedCategory);
             SelectedCategory = null;
         }
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Creating category from user input.
        /// </summary>
        /// <returns>Returns true, if the new category is saved to the database.</returns>
        public bool CreateInteractive()
        {
            var newCategory = new CategoryViewModel(MainViewModel, InteractionMode.Create);

            windowService.OpenCategoryWindow(newCategory);
            using (var db = new DataModel())
            {
                var chkCategory = db.Categories.Find(newCategory.SelectedCategory.CategoryID);
                if (chkCategory != null)
                {
                    UserCategories.Add(newCategory.SelectedCategory);
                    SelectedCategory = UserCategories.First(uc => uc.CategoryID == newCategory.SelectedCategory.CategoryID);
                    return(true);
                }
                return(false);
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Remove userCategories.
 /// </summary>
 /// <param name="category">Categories class
 public async Task Remove(UserCategories userCategories)
 {
     _context.UserCategories.Remove(userCategories);
     ///await _context.SaveChangesAsync();
 }
Exemplo n.º 6
0
 public async Task UpdateAsync(UserCategories userCategories)
 {
     _context.UserCategories.Update(userCategories);
     //await _context.SaveChangesAsync();
 }
Exemplo n.º 7
0
        public async Task AddAsync(UserCategories userCategories)
        {
            await _context.UserCategories.AddAsync(userCategories);

            //await _context.SaveChangesAsync();
        }
Exemplo n.º 8
0
        public Categories GetUserCategories(int?userId /*, int count,int skip*/)
        {
            try
            {
                db.Configuration.ProxyCreationEnabled = false;
                if (userId != null && userId != 0)
                {
                    var user = db.EndUsers.Include("UserCategories").SingleOrDefault(cent => cent.Id == userId);
                    List <UserCategories> Categories = new List <UserCategories>();
                    if (user != null)
                    {
                        foreach (var cat in user.UserCategories)
                        {
                            var            courseCount = db.Courses.Where(cou => cou.CategoryId == cat.CategoryId && cou.isStarted == true).Count();
                            Category       category    = db.Categories.SingleOrDefault(cate => cate.Id == cat.CategoryId);
                            UserCategories temp        = new UserCategories
                            {
                                Id      = category.Id,
                                Name    = category.Name,
                                Logo    = Convert.ToBase64String(category.Logo),
                                Image   = Convert.ToBase64String(category.Cover),
                                Courses = courseCount
                            };
                            Categories.Add(temp);
                        }
                        return(new Categories()
                        {
                            categories = Categories /*Count < count ? Categories : Categories.Skip(skip).Take(count).ToList()*/,
                            Message = Utilities.GetErrorMessages("200")
                        });
                    }
                    else
                    {
                        return(new Categories()
                        {
                            Message = Utilities.GetErrorMessages("402")
                        });
                    }
                }
                else
                {
                    var temps = db.Categories.ToList();
                    List <UserCategories> temps2 = new List <UserCategories>();
                    foreach (var temp in temps)
                    {
                        var courseCount = db.Courses.Where(cou => cou.CategoryId == temp.Id).Count();

                        UserCategories temp2 = new UserCategories
                        {
                            Id      = temp.Id,
                            Name    = temp.Name,
                            Logo    = Convert.ToBase64String(temp.Logo),
                            Courses = courseCount
                        };
                        temps2.Add(temp2);
                    }
                    return(new Categories()
                    {
                        categories = temps2 /*.Count < count ? temps2 : temps2.Skip(skip).Take(count).ToList()*/,
                        Message = Utilities.GetErrorMessages("200")
                    });
                }
            }
            catch (Exception)
            {
                return(new Categories()
                {
                    Message = Utilities.GetErrorMessages("500")
                });
            }
        }
Exemplo n.º 9
0
 public Categories GetCenterCategories(int centerId)
 {
     try
     {
         db.Configuration.ProxyCreationEnabled = false;
         if (centerId != 0)
         {
             var centerCats = db.TrainningCenterCategories.Where(ccat => ccat.CentersId == centerId).ToList();
             List <UserCategories> categories = new List <UserCategories>();
             Console.WriteLine(centerCats.Count);
             foreach (var category in centerCats)
             {
                 var smallCat    = db.Categories.SingleOrDefault(cat => cat.Id == category.CategoryId);
                 var courseCount = db.Courses.Where(cou => cou.CategoryId == category.CategoryId).Count();
                 Console.WriteLine(smallCat.Id);
                 categories.Add(new UserCategories
                 {
                     Id      = smallCat.Id,
                     Name    = smallCat.Name,
                     Logo    = Convert.ToBase64String(smallCat.Logo),
                     Image   = Convert.ToBase64String(smallCat.Cover),
                     Courses = courseCount
                 });
             }
             if (categories.Count != 0)
             {
                 return new Categories()
                        {
                            categories = categories,
                            Message    = Utilities.GetErrorMessages("200")
                        }
             }
             ;
         }
         var temps = db.Categories.ToList();
         List <UserCategories> temps2 = new List <UserCategories>();
         foreach (var temp in temps)
         {
             var            courseCount = db.Courses.Where(cou => cou.CategoryId == temp.Id).Count();
             UserCategories temp2       = new UserCategories
             {
                 Id      = temp.Id,
                 Name    = temp.Name,
                 Logo    = Convert.ToBase64String(temp.Logo),
                 Image   = Convert.ToBase64String(temp.Cover),
                 Courses = courseCount
             };
             temps2.Add(temp2);
         }
         return(new Categories()
         {
             categories = temps2,
             Message = Utilities.GetErrorMessages("200")
         });
     }
     catch (Exception ex)
     {
         return(new Categories()
         {
             Message = Utilities.GetErrorMessages("500")
         });
     }
 }
Exemplo n.º 10
0
        public IActionResult Index()
        {
            var userCategories = new UserCategories(roleManager, userManager);

            return(View(userCategories));
        }
Exemplo n.º 11
0
        public async Task <Category> Create(Category category)
        {
            string userId = category.CreateBy;

            // get user's category ids
            UserCategories userCategories = null;// = repository.GetItemsAsync<UserCategories>(p => p.Id == userId).Result.FirstOrDefault();

            if (userCategories == null)
            {
                // there is no category for the user
                userCategories = new UserCategories();
                userCategories.PrepareToCreate();
                userCategories.Id = userId;
                // setting default properties
                category.PrepareToCreate();

                // creating category
                category = await repository.CreateItemAsync <Category>(category);

                await repository.CreateItemAsync <UserCategories>(userCategories);

                return(category);
            }


            else
            {
                // get categories with ids
                //check if new category with the same title already exists or not
                IList <Category> oldCategories = await repository
                                                 .GetItemsAsync <Category>(p => userCategories.CategoryIds.Contains(p.Id) && p.Title == category.Title);

                // todo: remove this code and implement validation
                // there is no need to add the category
                if (oldCategories.Count == 0)
                {
                    category = oldCategories.FirstOrDefault();
                }

                return(category);
            }



            //// setting default properties
            //category.PrepareToCreate();


            //// creating category
            //category = await repository.CreateItemAsync<Category>(category);


            //// assigning category to the user's categories
            //userCategories.CategoryIds.Add(category.Id);
            //bool isUpdated = await repository.UpdateItemAsync<UserCategories>(userCategories.Id, userCategories);


            //// todo: implement exceptioin handling if category is not created

            //return category;
        }
Exemplo n.º 12
0
        public JsonResult SubmitBet(int questionId, int betAmt)
        {
            HttpResponseMessage res;
            int uid = (int)Session["currentUser"];

            new LogEvent("questionId | SubmitBet " + questionId).Raise();
            new LogEvent("betAmt | SubmitBet " + betAmt).Raise();
            new LogEvent("uid | SubmitBet " + uid).Raise();
            if (questionId != null && betAmt != null && uid != null)
            {
                new LogEvent("In If | SubmitBet ").Raise();
                UserProfile up = (from u in db.UserProfiles
                                  where u.UserId == uid
                                  select u).FirstOrDefault();
                //UserProfile up = db.UserProfiles.Find(uid);
                new LogEvent("up | SubmitBet " + up.UserName).Raise();
                //Check if the question is already in UserQuestion table
                UserQuestions uq = (from u in db.UserQuestions
                                    where u.UserId == uid && u.QuestionId == questionId
                                    select u).FirstOrDefault();
                new LogEvent("uq | SubmitBet " + uq).Raise();
                //If not, create the UserQuestion
                if (uq == null)
                {
                    new LogEvent("Creating uq | SubmitBet ").Raise();
                    uq = new UserQuestions {
                        UserId = uid, QuestionId = questionId, betAmount = betAmt
                    };
                    uq.answered            = 0;
                    uq.correct             = false;
                    uq.question            = db.Questions.Find(uq.QuestionId);
                    uq.question.CategoryId = uq.question.Category.CategoryId;
                    uq.user = up;
                    db.UserQuestions.Add(uq);
                    if (uq.question == null)
                    {
                        uq.question = db.Questions.Find(uq.QuestionId);
                    }
                    new LogEvent("Created uq | SubmitBet " + uq.QuestionId).Raise();
                }
                if (uq.question == null)
                {
                    uq.question = db.Questions.Find(uq.QuestionId);
                }

                //check if the User and Category combo is already in the table
                var query = from u in db.UserCategories
                            where u.UserId == uid && u.CategoryId == uq.question.CategoryId
                            select u;
                UserCategories uc = query.FirstOrDefault();
                //if not, add the user and category combo into the table
                if (uc == null)
                {
                    uc = new UserCategories {
                        UserId = uid, totalQuestionsAnswered = 0
                    };
                    uc.category               = uq.question.Category;
                    uc.CategoryId             = uq.question.CategoryId;
                    uc.user                   = up;
                    uc.totalQuestionsAnswered = 0;
                    db.UserCategories.Add(uc);
                    // db.SaveChanges();
                }

                //increment the answered questions in the in the user category combo
                uc.totalQuestionsAnswered += 1;

                //get the UserBet and subtract the betAmt for the user
                UserBet ub = db.UserBet.Find(uid);
                ub.BetAmt -= betAmt;

                db.SaveChanges();
                res            = new HttpResponseMessage();
                res.StatusCode = HttpStatusCode.Accepted;
                new LogEvent("Working | SubmitBet").Raise();
            }
            else
            {
                res            = new HttpResponseMessage();
                res.StatusCode = HttpStatusCode.ExpectationFailed;
                new LogEvent("Failure | SubmitBet").Raise();
            }
            //return RedirectToAction("ShowQuestion", "Game");
            new LogEvent("coming to an end | SubmitBet").Raise();
            return(Json(new { redirectToUrl = Url.Action("ShowQuestion", "Game") }));
            //return Json(new { redirectToUrl = "http://quiz-6.apphb.com/Game/ShowQuestion" });
        }