Click here to Skip to main content
15,942,934 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have the following classes:

C#
public partial class Category
{
    public Category()
    {
        this.CategoryUsers = new HashSet<CategoryUser>();
        this.Entries = new HashSet<Entry>();
    }

    public int CategoryID { get; set; }
    public string CatagoryName { get; set; }

    public virtual ICollection<CategoryUser> CategoryUsers { get; set; }
    public virtual ICollection<Entry> Entries { get; set; }
}

public partial class User
{
    public User()
    {
        this.CategoryUsers = new HashSet<CategoryUser>();
        this.Entries = new HashSet<Entry>();
    }

    public int UserID { get; set; }

    [Required(ErrorMessage = "Please provide full name", AllowEmptyStrings = false)]
    public string FullName { get; set; }

    [Required(ErrorMessage = "Please provide username", AllowEmptyStrings = false)]
    public string Username { get; set; }

    [DataType(System.ComponentModel.DataAnnotations.DataType.Password)]
    [StringLength(50, MinimumLength = 6, ErrorMessage = "Password must be minimum 6 char long.")]
    [Required]
    public string Password { get; set; }

    [Compare("Password", ErrorMessage = "Confirm password dose not match.")]
    [DataType(System.ComponentModel.DataAnnotations.DataType.Password)]
    [Required]
    public string ConfirmPassword { get; set; }

    public virtual ICollection<CategoryUser> CategoryUsers { get; set; }
    public virtual ICollection<Entry> Entries { get; set; }
}

public partial class CategoryUser
{
    public int Category_User_ID { get; set; }
    public int Fk_Category { get; set; }
    public int Fk_User { get; set; }

    public virtual Category Category { get; set; }
    public virtual User User { get; set; }
}

public partial class Entry
{
    public int EntryID { get; set; }
    public string Title { get; set; }
    public string Username { get; set; }
    public string Password { get; set; }
    public string Url { get; set; }
    public string Description { get; set; }
    public int Fk_Category { get; set; }
    public int Fk_User { get; set; }

    public virtual Category Category { get; set; }
    public virtual User User { get; set; }
}


The user controller:

C#
public class UserController : Controller
   {
       [HttpGet]
       public ActionResult Index()
       {
           return View();
       }

       [HttpGet]
       public ActionResult Register()
       {
           return View();
       }

       [HttpPost]
       [ValidateAntiForgeryToken]
       public ActionResult Register(User user)
       {
           if (ModelState.IsValid)
           {
               using (PasswordCloudEntities _db = new PasswordCloudEntities())
               {

                   var count = _db.Users.Count(u => u.Username == user.Username);

                   if (count == 0)
                   {
                       _db.Users.Add(user);

                       _db.SaveChanges();

                       ModelState.Clear();

                       user = null;

                       ViewBag.Message = "Successfully Registration Done";
                   }
                   else
                   {
                       ViewBag.Message = "Registration failed. Username already exists.";
                   }
               }
           }

           return PartialView(user);
       }

       [HttpGet]
       public ActionResult LogIn()
       {
           return View();
       }

       [HttpPost]
       [ValidateAntiForgeryToken]
       public ActionResult LogIn(User user)
       {
           if (IsValid(user.Username, user.Password))
           {
               FormsAuthentication.SetAuthCookie(user.Username, false);
               return RedirectToAction("Index", "Home");
           }
           else
           {
               ModelState.AddModelError("", "Login details are wrong.");
           }

           return PartialView(user);
       }

       public ActionResult LogOut()
       {
           FormsAuthentication.SignOut();
           return RedirectToAction("Index", "Home");
       }

       private bool IsValid(string username, string password)
       {
           bool IsValid = false;

           using (var db = new PasswordCloudEntities())
           {
               var user = db.Users.FirstOrDefault(u => u.Username == username);
               if (user != null)
               {
                   if (user.Password == password)
                   {
                       IsValid = true;
                   }
               }
           }
           return IsValid;
       }
   }


So i am beginner in MVC, i've made user to register and log in, now i need depending of the logged user to display categories, and then from the selected category to display the entry that user entered. Can someone guide and help me with the next steps.
Posted
Updated 24-Sep-14 0:48am
v2
Comments
[no name] 24-Sep-14 6:15am    
you ought to add the controller action where you have started writing the code for this.
Thanks

1 solution

Give the details of the screen you want to display along with the table structure from where data is fetched.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900