Пример #1
0
        public void SetUserSuggestions(List <Genre> newgenres)                                   // Store the Movie Genres suggestions for User
        {
            int  connecteduserid = int.Parse(HttpContext.Session.GetString("UserId"));           // Get from session the user id that connected
            User tempUser        = _context.User.Where(u => u.Id == connecteduserid).FirstOrDefault();
            var  usergenre       = _context.UserGenre.Where(ug => ug.UserId == connecteduserid); // Get the genres related to user

            foreach (Genre g in newgenres)                                                       // Loop to update/add the genres to user suggestions
            {
                if (usergenre.Any(us => us.Genre == g))                                          // If genre is exist
                {
                    usergenre.Where(us => us.Genre == g).First().Weight += 1;
                }
                else // genre doesn't exist
                {
                    UserGenre userGenre = new UserGenre();
                    userGenre.GenreId = g.Id;
                    userGenre.Genre   = g;
                    userGenre.UserId  = tempUser.Id;
                    userGenre.User    = tempUser;
                    userGenre.Weight  = 1;
                    if (g.UserGenre == null)
                    {
                        g.UserGenre = new List <UserGenre>();
                    }
                    g.UserGenre.Add(userGenre);
                    if (tempUser.UserGenre == null)
                    {
                        tempUser.UserGenre = new List <UserGenre>();
                    }
                    tempUser.UserGenre.Add(userGenre);
                    _context.Add(userGenre);
                }
            }
            _context.SaveChanges();
        }
Пример #2
0
        public async Task <IActionResult> Edit(int id, [Bind("UserId,GenreId,Weight")] UserGenre userGenre)
        {
            if (id != userGenre.UserId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(userGenre);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserGenreExists(userGenre.UserId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GenreId"] = new SelectList(_context.Genre, "Id", "Type", userGenre.GenreId);
            ViewData["UserId"]  = new SelectList(_context.User, "Id", "Address", userGenre.UserId);
            return(View(userGenre));
        }
 public object Remove(UserGenre userGenre)
 {
     try {
         _repo.Remove(userGenre);
         return(NoContent());
     } catch (Exception error) {
         throw error;
     }
 }
        public void DeleteUserGenre(UserGenre userGenre)
        {
            var toRemove = _context.UserGenre
                           .Where(x => x.GenreID == userGenre.GenreID &&
                                  x.UserUID == userGenre.UserUID)
                           .FirstOrDefault();

            _context.UserGenre.Remove(toRemove);
            _context.SaveChanges();
        }
Пример #5
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new User
                {
                    UserName  = model.Email,
                    FirstName = model.FirstName,
                    LastName  = model.LastName,
                    Email     = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    // add CUST role to new user
                    var UserManager    = new UserManager <User>(new UserStore <User>(_context));
                    var userRoleResult = await UserManager.AddToRoleAsync(user.Id, "CUST");

                    if (model.Genres != null)
                    {
                        foreach (Genres genre in model.Genres)
                        {
                            //    Debug.WriteLine((int)Enum.Parse(typeof(Genres), genre.ToString()));
                            UserGenre ug = new UserGenre
                            {
                                UserId = user.Id,
                                Genre  = (int)Enum.Parse(typeof(Genres), genre.ToString())
                            };

                            _context.UserGenres.Add(ug);
                        }
                        _context.SaveChanges();
                    }
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);



                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("index", "movies"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Пример #6
0
        public async Task <IActionResult> Create([Bind("UserId,GenreId,Weight")] UserGenre userGenre)
        {
            if (ModelState.IsValid)
            {
                _context.Add(userGenre);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GenreId"] = new SelectList(_context.Genre, "Id", "Type", userGenre.GenreId);
            ViewData["UserId"]  = new SelectList(_context.User, "Id", "Address", userGenre.UserId);
            return(View(userGenre));
        }
        public object Add(UserGenre userGenre)
        {
            try {
                userGenre.Id           = Guid.NewGuid().ToString();
                userGenre.CreationDate = DateTime.Now;

                _repo.Add(userGenre);

                var controllerAction = new ControllerActionDescriptor();

                string actionName = controllerAction.ActionName;

                return(CreatedAtAction(actionName, userGenre));
            } catch (Exception error) {
                throw error;
            }
        }
Пример #8
0
        public ActionResult Index(User u, object [] GenreList)
        {
            MultiSelectList l       = ViewBag.GenreList;
            List <string>   genres  = new List <string>();
            User            newUser = new User();

            if (ModelState.IsValid)
            {
                newUser.UserName         = u.UserName;
                newUser.Password         = u.Password;
                newUser.ConfirmPassword  = u.ConfirmPassword;
                newUser.CreditCardNumber = u.CreditCardNumber;
                newUser.Email            = u.Email;
                newUser.FirstName        = u.FirstName;
                newUser.LastName         = u.LastName;
                newUser.QuestionId       = u.QuestionId;
                newUser.Answer           = u.Answer;
                newUser.City             = u.City;
                newUser.Address          = u.Address;
                newUser.CountryId        = u.CountryId;
                newUser.Cellular         = u.Cellular;
                newUser.Phone            = u.Phone;
                db.Users.Add(newUser);
                //save the user
                db.SaveChanges();
                //save the question for the user.
                UserQuestion uq = new UserQuestion();
                uq.UserId     = newUser.UserId;
                uq.QuestionId = newUser.QuestionId;
                db.UserQuestions.Add(uq);
                db.SaveChanges();
                foreach (object o in GenreList)
                {
                    UserGenre ug = new UserGenre();
                    ug.GenreId = Convert.ToInt32(o);
                    ug.UserId  = newUser.UserId;
                    db.UserGenres.Add(ug);
                }
                db.SaveChanges();
                return(RedirectToAction("Index", "Login"));
            }
            return(View());
        }
 public ActionResult DislikeGenre(UserGenre genre)
 {
     _userRepository.DeleteUserGenre(genre);
     return(Ok());
 }
 public ActionResult LikeGenre(UserGenre userGenre)
 {
     _userRepository.AddUserGenre(userGenre);
     return(Ok());
 }
Пример #11
0
 public void Insert(UserGenre userGenre)
 {
     DbOperations.ExecuteCommand(_context.connectionString, "dbo.UsersGenres_Insert", userGenre.GenerateSqlParametersFromModel().ToArray());
 }
 public void AddUserGenre(UserGenre userGenre) // test to make sure works
 {
     _context.UserGenre.Add(userGenre);
     _context.SaveChanges();
 }