コード例 #1
0
 public long?AddAssignedRoles(SavedAssignedRoles savedAssignedRoles)
 {
     try
     {
         using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DatabaseConnection"].ConnectionString))
         {
             con.Open();
             SqlTransaction transaction = con.BeginTransaction();
             var            param       = new DynamicParameters();
             param.Add("@RoleId", savedAssignedRoles.RoleId);
             param.Add("@Status", savedAssignedRoles.Status);
             param.Add("@UserId", savedAssignedRoles.UserId);
             var result = con.Execute("Usp_InsertSavedAssignedRoles", param, transaction, 0, CommandType.StoredProcedure);
             if (result > 0)
             {
                 transaction.Commit();
                 return(result);
             }
             else
             {
                 transaction.Rollback();
                 return(0);
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #2
0
        public ActionResult Create(CustomerViewModel customerViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var isCustomer = _iCustomer.CheckCustomernameExists(customerViewModel.CustomerEmail);
                    if (isCustomer)
                    {
                        ModelState.AddModelError("", "Customer already exists");
                    }

                    AesAlgorithm aesAlgorithm = new AesAlgorithm();

                    var customer = AutoMapper.Mapper.Map <Customers>(customerViewModel);
                    customer.Status     = true;
                    customer.CustomerID = 0;
                    customer.CreatedBy  = Convert.ToInt32(Session["UserID"]);

                    var customerId = _iCustomer.AddCustomer(customer);
                    if (customerId != -1)
                    {
                        var passwordMaster = new PasswordMaster
                        {
                            CreateDate = DateTime.Now,
                            UserId     = customerId,
                            PasswordId = 0,
                            Password   = aesAlgorithm.EncryptString(customerViewModel.Password),
                            UserEmail  = customerViewModel.CustomerEmail
                        };

                        var passwordId = _iPassword.SavePassword(passwordMaster);
                        if (passwordId != -1)
                        {
                            var savedAssignedRoles = new SavedAssignedRoles()
                            {
                                RoleId         = 3,
                                UserId         = customerId,
                                AssignedRoleId = 0,
                                Status         = true,
                                CreateDate     = DateTime.Now
                            };
                            _savedAssignedRoles.AddAssignedRoles(savedAssignedRoles);

                            TempData["MessageCreateUsers"] = "User Created Successfully";
                        }
                    }

                    return(RedirectToAction("Index", "Customer"));
                }
                else
                {
                    return(View("Create"));
                }
            }
            catch
            {
                throw;
            }
        }
コード例 #3
0
        public ActionResult Create(CreateUserViewModel createUserViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var isUser = _iUserMaster.CheckUsernameExists(createUserViewModel.UserName);
                    if (isUser)
                    {
                        ModelState.AddModelError("", "Username already exists");
                    }

                    AesAlgorithm aesAlgorithm = new AesAlgorithm();

                    var usermaster = AutoMapper.Mapper.Map <Usermaster>(createUserViewModel);
                    usermaster.Status     = true;
                    usermaster.CreateDate = DateTime.Now;
                    usermaster.UserId     = 0;
                    usermaster.CreatedBy  = Convert.ToInt32(Session["UserID"]);

                    var userId = _iUserMaster.AddUser(usermaster);
                    if (userId != -1)
                    {
                        var passwordMaster = new PasswordMaster
                        {
                            CreateDate = DateTime.Now,
                            UserId     = userId,
                            PasswordId = 0,
                            Password   = aesAlgorithm.EncryptString(createUserViewModel.Password)
                        };

                        var passwordId = _iPassword.SavePassword(passwordMaster);
                        if (passwordId != -1)
                        {
                            var savedAssignedRoles = new SavedAssignedRoles()
                            {
                                RoleId         = createUserViewModel.RoleId,
                                UserId         = userId,
                                AssignedRoleId = 0,
                                Status         = true,
                                CreateDate     = DateTime.Now
                            };
                            _savedAssignedRoles.AddAssignedRoles(savedAssignedRoles);

                            TempData["MessageCreateUsers"] = "User Created Successfully";
                        }
                    }

                    return(RedirectToAction("Create", "CreateUsers"));
                }
                else
                {
                    return(View("Create", createUserViewModel));
                }
            }
            catch
            {
                throw;
            }
        }
コード例 #4
0
        public ActionResult Assign(AssignViewUserRoleModel assignViewUserRoleModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    assignViewUserRoleModel = new AssignViewUserRoleModel()
                    {
                        ListRole  = _role.GetAllActiveRoles(),
                        ListUsers = _userMaster.GetAllUsersActiveList(),
                        RoleId    = assignViewUserRoleModel.RoleId,
                        UserId    = assignViewUserRoleModel.UserId
                    };
                    return(View(assignViewUserRoleModel));
                }

                if (_savedAssignedRoles.CheckAssignedRoles(assignViewUserRoleModel.UserId))
                {
                    assignViewUserRoleModel = new AssignViewUserRoleModel()
                    {
                        ListRole  = _role.GetAllActiveRoles(),
                        ListUsers = _userMaster.GetAllUsersActiveList(),
                        RoleId    = assignViewUserRoleModel.RoleId,
                        UserId    = assignViewUserRoleModel.UserId
                    };

                    TempData["AssignedErrorMessage"] = "Role is Already Assigned to User";
                    return(View(assignViewUserRoleModel));
                }
                else
                {
                    SavedAssignedRoles savedAssignedRoles = new SavedAssignedRoles()
                    {
                        RoleId         = assignViewUserRoleModel.RoleId,
                        UserId         = assignViewUserRoleModel.UserId,
                        Status         = true,
                        CreateDate     = DateTime.Now,
                        AssignedRoleId = 0
                    };
                    _savedAssignedRoles.AddAssignedRoles(savedAssignedRoles);
                    TempData["AssignedMessage"] = "Role Assigned to User Successfully";
                    return(RedirectToAction("Assign", "AssignRoletoUser"));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #5
0
        public ActionResult Create(CustomerViewModel customerViewModel)
        {
            if (ModelState.IsValid)
            {
                Customer customerObject = db.Customer.Where(x => x.CustomerEmail == customerViewModel.CustomerEmail).FirstOrDefault();
                if (customerObject == null)
                {
                    ModelState.AddModelError("", "Customer already exists");
                }
                AesAlgorithm aesAlgorithm = new AesAlgorithm();

                var customer = AutoMapper.Mapper.Map <Customer>(customerViewModel);
                customer.Status     = true;
                customer.CustomerId = 0;
                customer.CreatedBy  = Convert.ToInt32(Session["UserID"]);
                db.Customer.Add(customer);
                db.SaveChanges();
                int customerId     = customer.CustomerId;
                var passwordMaster = new PasswordMaster
                {
                    CreateDate = DateTime.Now,
                    UserId     = customerId,
                    PasswordId = 0,
                    Password   = aesAlgorithm.EncryptString(customerViewModel.Password),
                    UserEmail  = customerViewModel.CustomerEmail
                };

                var passwordId = _iPassword.SavePassword(passwordMaster);
                if (passwordId != -1)
                {
                    var savedAssignedRoles = new SavedAssignedRoles()
                    {
                        RoleId         = 3,
                        UserId         = customerId,
                        AssignedRoleId = 0,
                        Status         = true,
                        CreateDate     = DateTime.Now,
                    };
                    _savedAssignedRoles.AddAssignedRoles(savedAssignedRoles);

                    TempData["MessageCreateUsers"] = "User Created Successfully";
                }
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View("Create"));
            }
        }
コード例 #6
0
 public long?AddAssignedRoles(SavedAssignedRoles savedAssignedRoles)
 {
     try
     {
         int result = -1;
         if (savedAssignedRoles != null)
         {
             _context.SavedAssignedRoles.Add(savedAssignedRoles);
             _context.SaveChanges();
             result = savedAssignedRoles.AssignedRoleId;
         }
         return(result);
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #7
0
        public ActionResult Create(CreateAgentViewModel createAgentViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var isUser = _iUserMaster.CheckUsernameExists(createAgentViewModel.UserName);

                    if (createAgentViewModel.CategoryId == null)
                    {
                        ModelState.AddModelError("", "Select Category");
                    }
                    else if (isUser)
                    {
                        ModelState.AddModelError("", "Username already exists");
                    }
                    else
                    {
                        var usermaster = AutoMapper.Mapper.Map <Usermaster>(createAgentViewModel);
                        usermaster.Status       = true;
                        usermaster.CreateDate   = DateTime.Now;
                        usermaster.UserId       = 0;
                        usermaster.CreatedBy    = Convert.ToInt32(_sessionHandler.UserId);
                        usermaster.IsFirstLogin = true;

                        var salt           = GenerateRandomNumbers.RandomNumbers(20);
                        var saltedpassword = GenerateHashSha512.Sha512(createAgentViewModel.Password, salt);

                        var savedAssignedRoles = new SavedAssignedRoles()
                        {
                            RoleId         = Convert.ToInt16(StatusMain.Roles.Agent),
                            AssignedRoleId = 0,
                            Status         = true,
                            CreateDate     = DateTime.Now
                        };

                        var result = _iUserMaster.AddAgent(usermaster, saltedpassword, savedAssignedRoles, createAgentViewModel.CategoryId, salt);

                        if (result > 0)
                        {
                            TempData["MessageCreateUsers"] = "Agent Created Successfully";
                            return(RedirectToAction("Create", "CreateAgent"));
                        }
                        else
                        {
                            return(View(createAgentViewModel));
                        }
                    }

                    createAgentViewModel.ListofCategory = _category.GetAllActiveSelectListItemCategory();
                    return(View("Create", createAgentViewModel));
                }
                else
                {
                    createAgentViewModel.ListofCategory = _category.GetAllActiveSelectListItemCategory();
                    return(View("Create", createAgentViewModel));
                }
            }
            catch
            {
                throw;
            }
        }
コード例 #8
0
        public ActionResult Create(CreateUserViewModel createUserViewModel, HttpPostedFileBase fileUpload)
        {
            try
            {
                if (createUserViewModel.UserId > 0)
                {
                    ModelState.Remove("UserName");
                    ModelState.Remove("Password");
                    ModelState.Remove("ConfirmPassword");
                    ModelState.Remove("RoleId");
                }
                if (ModelState.IsValid)
                {
                    if (createUserViewModel.UserId == 0)
                    {
                        var isUser = _iUserMaster.CheckUsernameExists(createUserViewModel.UserName);
                        if (isUser)
                        {
                            ModelState.AddModelError("", "Username already exists");
                        }

                        AesAlgorithm aesAlgorithm = new AesAlgorithm();


                        var    usermaster = AutoMapper.Mapper.Map <Usermaster>(createUserViewModel);
                        string path       = Server.MapPath("~/Content/UserImage/");
                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }
                        if (fileUpload != null && fileUpload.ContentLength > 0)
                        {
                            string extension   = Path.GetExtension(fileUpload.FileName);
                            string newFileName = "u_" + DateTime.Now.Ticks + extension;
                            usermaster.ImageName = newFileName;
                            fileUpload.SaveAs(path + newFileName);
                        }

                        usermaster.Status     = true;
                        usermaster.CreateDate = DateTime.Now;
                        usermaster.UserId     = 0;
                        usermaster.CreatedBy  = Convert.ToInt32(Session["UserID"]);

                        var userId = _iUserMaster.AddUser(usermaster);
                        if (userId != -1)
                        {
                            var passwordMaster = new PasswordMaster
                            {
                                CreateDate = DateTime.Now,
                                UserId     = userId,
                                PasswordId = 0,
                                Password   = aesAlgorithm.EncryptString(createUserViewModel.Password)
                            };

                            var passwordId = _iPassword.SavePassword(passwordMaster);
                            if (passwordId != -1)
                            {
                                var savedAssignedRoles = new SavedAssignedRoles()
                                {
                                    RoleId         = createUserViewModel.RoleId,
                                    UserId         = userId,
                                    AssignedRoleId = 0,
                                    Status         = true,
                                    CreateDate     = DateTime.Now
                                };
                                _savedAssignedRoles.AddAssignedRoles(savedAssignedRoles);

                                TempData["MessageCreateUsers"] = "User Created Successfully";
                            }
                        }
                    }
                    else
                    {
                        var    usermaster = AutoMapper.Mapper.Map <Usermaster>(createUserViewModel);
                        string path       = Server.MapPath("~/Content/UserImage/");
                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }
                        if (fileUpload != null && fileUpload.ContentLength > 0)
                        {
                            string extension   = Path.GetExtension(fileUpload.FileName);
                            string newFileName = "u_" + DateTime.Now.Ticks + extension;
                            usermaster.ImageName = newFileName;
                            fileUpload.SaveAs(path + newFileName);
                        }

                        usermaster.Status     = true;
                        usermaster.CreateDate = DateTime.Now;
                        usermaster.UserId     = createUserViewModel.UserId;
                        usermaster.CreatedBy  = Convert.ToInt32(Session["UserID"]);

                        var userId = _iUserMaster.UpdateUser(usermaster);
                    }
                    return(RedirectToAction("Create", "CreateUsers"));
                }
                else
                {
                    return(View("Create", createUserViewModel));
                }
            }
            catch
            {
                throw;
            }
        }