예제 #1
0
        private bool Get_CheckUserRoles(string userID)
        {
            using (CYBInfrastrctureContext context = new CYBInfrastrctureContext())

            {
                var data = (from WR in context.UsersInRole

                            join R in context.Roles on WR.RoleId equals R.RoleId

                            where WR.Role.RoleName == userID

                            orderby R.RoleId

                            select new

                {
                    WR.UserID
                }).Count();



                if (data > 0)

                {
                    return(true);
                }

                else

                {
                    return(false);
                }
            }
        }
예제 #2
0
        public ActionResult ResetPassword(ResetPasswordModel model)
        {
            var message = "";

            if (ModelState.IsValid)
            {
                using (CYBInfrastrctureContext db = new CYBInfrastrctureContext())
                {
                    var user = db.UserAccounts.Where(a => a.ResetPasswordCode == model.ResetCode).FirstOrDefault();
                    if (user != null)
                    {
                        //user.Password = Crypto.Hash(model.NewPassword);
                        user.Password          = model.NewPassword;
                        user.ResetPasswordCode = "";
                        db.Configuration.ValidateOnSaveEnabled = false;
                        db.SaveChanges();
                        message = "New password updated successfully";
                    }
                }
            }
            else
            {
                message = "Something invalid";
            }

            ViewBag.Message = message;
            return(View(model));
        }
예제 #3
0
 // GET: Account
 public ActionResult Index(UserAccountListViewModel userAccount)
 {
     using (CYBInfrastrctureContext db = new CYBInfrastrctureContext())
     {
         return(View(userAccount));
     }
 }
예제 #4
0
        public ActionResult ForgotPassword(string Email)
        {
            //Verify Email ID
            //Generate Reset password link
            //send Email
            string message = "";

            //bool status = false;


            using (CYBInfrastrctureContext db = new CYBInfrastrctureContext())
            {
                var account = db.UserAccounts.Where(a => a.Email == Email).FirstOrDefault();
                if (account != null)
                {
                    //send email for reset password
                    string resetCode = Guid.NewGuid().ToString();
                    SendVerificationLinkEmail(account.Email, resetCode, "ResetPassword");
                    account.ResetPasswordCode = resetCode;
                    //this line i have added here to avoid confirm password not match issue, as

                    db.Configuration.ValidateOnSaveEnabled = false;
                    db.SaveChanges();
                    message = "password link has been sent to your email Id";
                }
                else
                {
                    message = "Account not found";
                }
            }

            ViewBag.Message = message;

            return(View());
        }
예제 #5
0
        //[Filter.AuthorizeUserRoles]

        public List <SelectListItem> GetAll_Users()

        {
            List <SelectListItem> listuser = new List <SelectListItem>();

            listuser.Add(new SelectListItem {
                Text = "Select", Value = "0"
            });



            using (CYBInfrastrctureContext db = new CYBInfrastrctureContext())

            {
                foreach (var item in db.UserAccounts)

                {
                    listuser.Add(new SelectListItem {
                        Text = item.StaffID, Value = item.StaffID
                    });
                }
            }

            return(listuser);
        }
        public ActionResult Create([Bind(Include = "id,ServerName,HostName,Date,PrimaryIP,SecondaryIP,Description,VLAN,Gateway,LocationId,UnitId,HostId,Environment,")] InventoryViewModel ivm)
        {
            CYBInfrastrctureContext db = new CYBInfrastrctureContext();

            bool Create = db.Inventories.Any(x => x.ServerName == ivm.ServerName && x.Id != ivm.Id);

            if (Create == true)
            {
                //TempData["Success"] = "Server already exists, Try another one";

                //ViewBag.message= "Server already exists, Try another one";
                ModelState.AddModelError("SeverName", "Server already exists, Try another one");
            }


            if (ModelState.IsValid)

            {
                var invent = new Inventory
                {
                    Id          = ivm.Id,
                    ServerName  = ivm.ServerName,
                    HostName    = ivm.HostName,
                    PrimaryIP   = ivm.PrimaryIP,
                    SecondaryIP = ivm.SecondaryIP,
                    Description = ivm.Description,
                    VLAN        = ivm.VLAN,
                    Gateway     = ivm.Gateway,
                    LocationId  = ivm.LocationId,
                    UnitId      = ivm.UnitId,
                    HostId      = ivm.HostId,
                    Environment = ivm.Environments,
                    Date        = ivm.Date

                                  //ServerType=ivm.ServerTypes,
                };
                _InventoryManager.Add(invent);
                _InventoryManager.SaveChanges();
                TempData["Success"] = "Added Successfully!";

                return(RedirectToAction("Index"));
            }
            //var location = _locationManager.GetAll().ToList();
            //var unit = _unitManager.GetAll().ToList();
            //InventoryViewModel inventorymodel = new InventoryViewModel
            //{
            //    Locations = location,
            //    Units = unit

            //};
            return(View(ivm));
        }
예제 #7
0
        public ActionResult DisplayAllRoles()

        {
            IEnumerable <CYBInfracstructure.DataStructure.Entities.Role> ListRoles;

            using (CYBInfrastrctureContext db = new CYBInfrastrctureContext())

            {
                ListRoles = db.Roles.ToList();
            }

            return(View(ListRoles));
        }
예제 #8
0
        //public bool Get_CheckUserRoles(int UserId)

        //{

        //    using (CYBInfrastrctureContext context = new CYBInfrastrctureContext())

        //    {

        //        var data = (from WR in context.UsersInRole

        //                    join R in context.Roles on WR.RoleId equals R.RoleId

        //                    where WR.UserId == UserId

        //                    orderby R.RoleId

        //                    select new

        //                    {

        //                        WR.UserId

        //                    }).Count();



        //        if (data > 0)

        //        {

        //            return true;

        //        }

        //        else

        //        {

        //            return false;

        //        }

        //    }



        //}


        public string GetUserName_BY_UserID(string UserName)

        {
            using (CYBInfrastrctureContext context = new CYBInfrastrctureContext())

            {
                var result = (from UP in context.UserAccounts

                              where UP.StaffID == UserName

                              select UP.StaffID).SingleOrDefault();

                return(result);
            }
        }
예제 #9
0
 public ActionResult ResetPassword(string id)
 {
     using (CYBInfrastrctureContext db = new CYBInfrastrctureContext())
     {
         var user = db.UserAccounts.Where(a => a.ResetPasswordCode == id).FirstOrDefault();
         if (user != null)
         {
             ResetPasswordModel model = new ResetPasswordModel();
             model.ResetCode = id;
             return(View(model));
         }
         else
         {
             return(HttpNotFound());
         }
     }
 }
예제 #10
0
        public List <AllroleandUser> Get_StaffID_And_Rolename()

        {
            using (CYBInfrastrctureContext db = new CYBInfrastrctureContext())

            {
                var Alldata = (from User in db.UserAccounts

                               join WU in db.UsersInRole on User.UserID equals WU.UserID

                               join WR in db.Roles on WU.RoleId equals WR.RoleId


                               select new AllroleandUser {
                    UserName = User.StaffID, RoleName = WR.RoleName, StaffName = User.StaffName
                }).ToList();



                return(Alldata);
            }
        }
예제 #11
0
        public List <SelectListItem> GetAll_Roles()

        {
            List <SelectListItem> listrole = new List <SelectListItem>();

            listrole.Add(new SelectListItem {
                Text = "select", Value = "0"
            });

            using (CYBInfrastrctureContext db = new CYBInfrastrctureContext())

            {
                foreach (var item in db.Roles)

                {
                    listrole.Add(new SelectListItem {
                        Text = item.RoleName, Value = item.RoleName
                    });
                }
            }

            return(listrole);
        }
 public UserAccountRepository(CYBInfrastrctureContext context)
 {
     this.context = context;
 }
 public UsersInRolesRepository(CYBInfrastrctureContext context)
 {
     this.context = context;
 }
예제 #14
0
 public LocationRepository(CYBInfrastrctureContext context)
 {
     this.context = context;
 }
예제 #15
0
 public HostRepository(CYBInfrastrctureContext context)
 {
     this.context = context;
 }
 public DepartmentRepository(CYBInfrastrctureContext context)
 {
     this.context = context;
 }
예제 #17
0
        public ActionResult Register([Bind(Include = "UserID,StaffID,StaffName,LastName,Email,Password,ConfirmPassword,ResetPassword,")]
                                     UserAccountModel user)
        {
            using (CYBInfrastrctureContext db = new CYBInfrastrctureContext())
            {
                var checkexistance = (from reg in db.UserAccounts where reg.StaffID == user.StaffID select reg);
                if (checkexistance.Count() > 0)
                {
                    ModelState.AddModelError("StaffID", "StaffID already exists, Try another one");
                    return(View());
                }

                var checkexistance1 = (from reg in db.UserAccounts where reg.Email == user.Email select reg);
                if (checkexistance1.Count() > 0)
                {
                    ModelState.AddModelError("Email", "Email already exists, Try another one");
                    return(View());
                }

                if (!string.IsNullOrEmpty(user.Email))
                {
                    string emailRegex = @"^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$";
                    Regex  re         = new Regex(emailRegex);
                    if (!re.IsMatch(user.Email))
                    {
                        ModelState.AddModelError("Email", "Please Enter Correct Email Address");
                        return(View());
                    }

                    else
                    {
                        var dpt = new UserAccount
                        {
                            UserID = user.UserID,

                            StaffID           = user.StaffID,
                            StaffName         = user.StaffName,
                            Email             = user.Email,
                            Password          = user.Password,
                            ConfirmPassword   = user.ConfirmPassword,
                            ResetPasswordCode = user.ResetPasswordCode,
                            //ActivationCode = user.ActivationCode
                        };

                        db.UserAccounts.Add(dpt);
                        db.SaveChanges();
                        TempData["Success"] = "Registered Successfully";

                        return(RedirectToAction("Index", "Admin", new { area = "Profile" }));
                    }
                }

                //bool Register = db.UserAccounts.Any(x => x.StaffID == user.StaffID && x.UserID == user.UserID);

                //if (Register == true)
                //{
                //    ModelState.AddModelError("StaffID", "StaffID already exists, Try another one");
                //    return View();
                //}
                //bool Register3 = db.UserAccounts.Any(x => x.Email == user.Email && x.UserID == user.UserID);

                //if (Register3 == true)
                //{
                //    ModelState.AddModelError("Email", "Email already exists, Try another one");
                //    return View();
                //}

                else
                {
                    var dpt = new UserAccount
                    {
                        UserID = user.UserID,

                        StaffID           = user.StaffID,
                        StaffName         = user.StaffName,
                        Email             = user.Email,
                        Password          = user.Password,
                        ConfirmPassword   = user.ConfirmPassword,
                        ResetPasswordCode = user.ResetPasswordCode,
                        //ActivationCode = user.ActivationCode
                    };

                    db.UserAccounts.Add(dpt);
                    db.SaveChanges();
                    TempData["Success"] = "Registered Successfully";

                    return(RedirectToAction("Login", "Account", new { area = "Profile" }));
                }
            }



            return(View(user));
        }
 public InventoryRepository(CYBInfrastrctureContext context)
 {
     this.context = context;
 }
 public ServiceRepository(CYBInfrastrctureContext context)
 {
     this.context = context;
 }