Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hey can someone help me please. I wanna two different roles for my project to login.One Manager and other user.Like i wanna something like Manager should have authority to see everything but he should not have authority to delete and add new user.Whereas user should have authority to add and delete new user.Can someone help me please.


Here is my Code My login Controller Code

C#
using MvcApplication1.Models;
using MvcApplication1.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

    namespace MvcApplication1.Controllers
{
              public class LoginController : Controller
{
//
// GET: /Login/
                  [HttpGet]

             public ActionResult Index()
         {
         return View();
          }
    public ActionResult Login()
        {
            return View();
        }
[HttpPost]
    public ActionResult Login(Customer d)
     {
          using (CustomerDataEntities oe = new CustomerDataEntities())
             {
          var user = oe.Customers.FirstOrDefault(a => a.Email.Equals(d.Email) && a.Password.Equals(d.Password));
           if (user == null)
                     {
                          TempData["ErrorMessage"] = "Invalid user name or password.";
                         return RedirectToAction("Login", "Login");
                      }
          else
              {
                   return RedirectToAction("Index", "Home");
                 }
                  }
                }
            }
             }



What to do ?? Please help me out
Posted
Comments
Krunal Rohit 25-Dec-15 6:56am    
This is just a Login code. What have you tried to achieve "Manager should have authority to see everything but he should not have authority to delete and add new user.Whereas user should have authority to add and delete new user" ?

-KR
Member 11897361 26-Dec-15 1:08am    
here is my home controller code where you can get an idea

using MvcApplication1.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcApplication1.Controllers
{
public class HomeController : Controller
{
CustomerDataEntities cd = new CustomerDataEntities();
//
// GET: /Home/

public ActionResult Index()
{
return View(cd.Customers.ToList());
}

[HttpGet]
public ActionResult AddEditRecord(int? id)
{
if (Request.IsAjaxRequest())
{
if (id != null)
{
ViewBag.IsUpdate = true;
Customer Customer = cd.Customers.Where(m => m.CustomerID == id).FirstOrDefault();
return PartialView("_CustomerData", Customer);
}
ViewBag.IsUpdate = false;
return PartialView("_CustomerData");
}
else
{
if (id != null)
{
ViewBag.IsUpdate = true;
Customer Customer = cd.Customers.Where(m => m.CustomerID == id).FirstOrDefault();
return PartialView("CustomerData", Customer);
}
ViewBag.IsUpdate = false;
return View("CustomerData");
}
}
[HttpPost]
public ActionResult AddEditRecord(Customer Customer, string cmd)
{
if (ModelState.IsValid)
{
if (cmd == "Save")
{
try
{
cd.Customers.Add(Customer);
cd.SaveChanges();
return RedirectToAction("Index");
}
catch { }
}
else
{
try
{
Customer cus = cd.Customers.Where(m => m.CustomerID == Customer.CustomerID).FirstOrDefault();
if (cus != null)
{

cus.FirstName = Customer.FirstName;
cus.LastName = Customer.LastName;
cus.Email = Customer.Email;
cus.Password = Customer.Password;
cus.ContactNo = Customer.ContactNo;

cd.SaveChanges();
}
return RedirectToAction("Index");
}
catch { }
}
}

if (Request.IsAjaxRequest())
{
return PartialView("_CustomerData", Customer);
}
else
{
return View("CustomerData", Customer);
}
}
public ActionResult Delete(int id)
{
Customer Customer = cd.Customers.Where(m => m.CustomerID == id).FirstOrDefault();
if (Customer != null)
{
try
{
cd.Customers.Remove(Customer);
cd.SaveChanges();
}
catch { }
}
return RedirectToAction("Index");
}
public ActionResult ViewEmployeeDetail(int id)
{
Customer customer = cd.Customers.Where(m => m.CustomerID == id).FirstOrDefault();
if (customer != null)
{
if (Request.IsAjaxRequest())
{
return PartialView("_CustomerDetail", customer);
}
else
{
return View("CustomerDetails", customer);
}
}
return View("Index");
}
}
}

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