コード例 #1
0
        public async Task <bool> RegisterUser(RegistrationModel registrationModel)
        {
            try
            {
                var user = Mapper.Map <RegistrationModel, Users>(registrationModel);

                user.Password    = _encryptionService.EncryptText(user.Password);
                user.UpdatedDate = DateTime.UtcNow;
                user.CreatedDate = DateTime.UtcNow;

                await _unitOfWork.UsersRepository.InsertAsync(user);

                await _unitOfWork.SaveAsync();

                var userRoleMapping = new UserRoleMapping
                {
                    RoleId = registrationModel.UserRoleId,
                    UserId = user.Id
                };

                await _unitOfWork.UserRoleMappingRepository.InsertAsync(userRoleMapping);

                await _unitOfWork.SaveAsync();

                return(true);
            }
            catch (Exception ex) { return(false); }
        }
コード例 #2
0
        public void CreateUser(CreateUserViewModel createUserViewModel, int userId)
        {
            createUserViewModel.User.CreatedDate = DateTime.Now;
            createUserViewModel.User.CreatedBy   = userId;
            createUserViewModel.User.IsVarified  = 0;
            createUserViewModel.User.IsActive    = 1;

            CapInnovativeIdiaDbContext.User.Add(createUserViewModel.User);
            CapInnovativeIdiaDbContext.SaveChanges();

            foreach (var role in createUserViewModel.RoleIds)
            {
                var assignRole = new UserRoleMapping
                {
                    RoleId      = role,
                    UserId      = createUserViewModel.User.Id,
                    CreatedBy   = userId,
                    CreatedDate = DateTime.Now,
                    IsActive    = 1
                };

                CapInnovativeIdiaDbContext.UserRoleMapping.Add(assignRole);
            }

            CapInnovativeIdiaDbContext.SaveChanges();
        }
コード例 #3
0
        public UserRole CreateNewUserRole()
        {
            StringInputDialog addPersonDialog = new StringInputDialog
            {
                Title   = "Creazione nuovo Ruolo Utente",
                Message = "Nome:"
            };

            if (addPersonDialog.ShowDialog() != true)
            {
                return(null);
            }

            UserRole newRole = new UserRole
            {
                Name        = addPersonDialog.InputString,
                Description = ""
            };

            _lInstData.Execute(new InsertEntityCommand <LInstContext>(newRole));

            foreach (User usr in _lInstData.RunQuery(new UsersQuery()))
            {
                UserRoleMapping newMap = new UserRoleMapping
                {
                    IsSelected = false,
                    UserRoleID = newRole.ID,
                    UserID     = usr.ID
                };

                _lInstData.Execute(new InsertEntityCommand <LInstContext>(newMap));
            }

            return(newRole);
        }
コード例 #4
0
        public async Task <IActionResult> Edit(int id, [Bind("RoleId,UserId,Id,Modified")] UserRoleMapping userRoleMapping)
        {
            if (id != userRoleMapping.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(userRoleMapping);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserRoleMappingExists(userRoleMapping.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(userRoleMapping));
        }
コード例 #5
0
        public LInst.User CreateNewUser(Person personInstance,
                                        string userName,
                                        string password)
        {
            LInst.User output = new LInst.User();
            output.FullName       = "";
            output.UserName       = userName;
            output.HashedPassword = CalculateHash(password, userName);
            using (LInstContext context = _contextFactory.CreateDbContext(new string[] { }))
            {
                output.Person = context.People.First(per => per.ID == personInstance.ID);
                foreach (UserRole role in context.UserRoles)
                {
                    UserRoleMapping tempMapping = new UserRoleMapping();
                    tempMapping.UserRole   = role;
                    tempMapping.IsSelected = false;

                    output.RoleMappings.Add(tempMapping);
                }
                context.Users.Add(output);
                context.SaveChanges();
            }

            return(output);
        }
        // GET: VehicleInformations/Create
        public IActionResult Create()
        {
            var u            = new UserRoleMapping();
            var joinRoleUser = (from user in _context.ApplicationUsers
                                join role in _context.UserRoles on user.Id equals role.UserId
                                join us in _context.Roles on role.RoleId equals us.Id
                                where us.Name == "Driver"
                                select new SelectListItem()
            {
                Value = user.Id,
                Text = user.UserName
            }).ToList();

            //var join = _context.Roles.Where(a => a.Name == "Driver").ToList();
            ViewData["RouteId"]       = new SelectList(_context.Routes, "RouteId", "RouteId");
            ViewData["VehicleTypeId"] = new SelectList(_context.VehicleTypes, "VehicleTypeId", "VehicleTypeId");
            //ViewBag.UserId = new SelectList(_context.Roles.Where(a => a.Name == "Driver"), "Id", "Name");
            joinRoleUser.Insert(0, new SelectListItem()
            {
                Text  = "----Select----",
                Value = string.Empty
            });
            ViewBag.UserId = joinRoleUser;
            // ViewBag.UserId = new SelectList(joinroleuser, Value, Text);
            return(View());
        }
コード例 #7
0
        public void UpdateUser(CreateUserViewModel createUserViewModel, int userId)
        {
            var user = CapInnovativeIdiaDbContext.User.Where(x => x.Id == createUserViewModel.User.Id).SingleOrDefault();

            if (user != null)
            {
                user.FirstName    = createUserViewModel.User.FirstName;
                user.LastName     = createUserViewModel.User.LastName;
                user.Email        = createUserViewModel.User.Email;
                user.Gender       = createUserViewModel.User.Gender;
                user.ModifiedBy   = userId;
                user.ModifiedDate = DateTime.Now;

                CapInnovativeIdiaDbContext.User.Update(user);
                CapInnovativeIdiaDbContext.SaveChanges();

                foreach (var role in createUserViewModel.RoleIds)
                {
                    var currentRole = CapInnovativeIdiaDbContext.UserRoleMapping.Where(x => x.RoleId == role && x.UserId == createUserViewModel.User.Id).SingleOrDefault();
                    if (currentRole != null)
                    {
                        if (currentRole.IsActive == 1)
                        {
                            continue;
                        }

                        else
                        {
                            currentRole.IsActive     = 1;
                            currentRole.ModifiedBy   = userId;
                            currentRole.ModifiedDate = DateTime.Now;

                            CapInnovativeIdiaDbContext.UserRoleMapping.Update(currentRole);
                            CapInnovativeIdiaDbContext.SaveChanges();
                        }
                    }

                    var newRole = new UserRoleMapping
                    {
                        RoleId      = role,
                        UserId      = createUserViewModel.User.Id,
                        CreatedBy   = userId,
                        CreatedDate = DateTime.Now,
                        IsActive    = 1
                    };

                    CapInnovativeIdiaDbContext.UserRoleMapping.Add(newRole);
                    CapInnovativeIdiaDbContext.SaveChanges();
                }

                var removeRoles = CapInnovativeIdiaDbContext.UserRoleMapping.Where(x => x.UserId == createUserViewModel.User.Id && !createUserViewModel.RoleIds.Contains(x.RoleId)).ToList();

                if (removeRoles != null)
                {
                    removeRoles.ForEach(x => x.IsActive = 0);
                    CapInnovativeIdiaDbContext.SaveChanges();
                }
            }
        }
コード例 #8
0
        public ActionResult DeleteConfirmed(int id)
        {
            UserRoleMapping userRoleMapping = db.UserRoleMappings.Find(id);

            db.UserRoleMappings.Remove(userRoleMapping);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #9
0
 public UserRoleMappingToDb(UserRoleMapping userRoleMapping)
     : base(s_metadata)
 {
     SetSqlInt64(0, userRoleMapping.ID);
     SetSqlInt64(1, userRoleMapping.UserID);
     SetSqlInt64(2, userRoleMapping.RoleID);
     SetSqlDateTime(3, userRoleMapping.CreateDate);
     SetSqlBoolean(4, userRoleMapping.State);
 }
コード例 #10
0
        public ActionResult UserRoleMapping(Guid[] RoleId, Guid UserId, Guid[] UnMap)
        {
            UserRoleMappings userRoleMappings = new UserRoleMappings();

            try
            {
                var userRoleMapp = userRoleMappingService.GetAll().Where(x => x.UserMasterId == UserId && x.IsActive == true).ToList();

                if (RoleId != null)
                {
                    foreach (var item in RoleId)
                    {
                        if (userRoleMapp.Select(x => x.RoleMasterId).Contains(item) == false)
                        {
                            UserRoleMapping userRoleMapping = new UserRoleMapping();
                            userRoleMapping.UserMasterId = UserId;
                            userRoleMapping.RoleMasterId = item;
                            userRoleMapping.CreatedBy    = User.Identity.Name;
                            userRoleMapping.CreatedDate  = DateTime.Now;

                            userRoleMappingService.Add(userRoleMapping);
                            userRoleMappingService.Save();
                        }
                    }
                }

                if (UnMap != null)
                {
                    foreach (var item in UnMap)
                    {
                        if (userRoleMapp.Select(x => x.RoleMasterId).Contains(item))
                        {
                            UserRoleMapping userRoleMapping = userRoleMapp.Where(x => x.RoleMasterId == item && x.UserMasterId == UserId).FirstOrDefault();
                            userRoleMapping.IsActive    = false;
                            userRoleMapping.DeletedBy   = User.Identity.Name;
                            userRoleMapping.DeletedDate = DateTime.Now;

                            userRoleMappingService.Delete(userRoleMapping);
                            userRoleMappingService.Save();
                        }
                    }
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                UserMaster userMaster = userMasterService.FindBy(x => x.UniqueId == UserId).FirstOrDefault();

                userRoleMappings.UserId   = userMaster.UniqueId;
                userRoleMappings.UserName = userMaster.Username;

                userRoleMappings.Role = roleMasterService.GetAll().ToList();
            }

            return(View(userRoleMappings));
        }
コード例 #11
0
 public void Update(UserRoleMapping entity)
 {
     using (WorldMapDBContext context = new WorldMapDBContext())
     {
         DbSet table = context.UserRoleMapping;
         table.Attach(entity);
         context.Entry(entity).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
コード例 #12
0
        public async Task <IActionResult> Create([Bind("RoleId,UserId,Id,Modified")] UserRoleMapping userRoleMapping)
        {
            if (ModelState.IsValid)
            {
                _context.Add(userRoleMapping);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(userRoleMapping));
        }
コード例 #13
0
        public async Task <IActionResult> Delete(string id, UserRoleMapping urm)
        {
            urm.Id = new Guid(id);
            var result = await urmrRepository.Delete(urm);

            if (result == 1)
            {
                return(Ok());
            }
            return(NoContent());
        }
コード例 #14
0
 public ActionResult Edit([Bind(Include = "UserId,RoleId")] UserRoleMapping userRoleMapping)
 {
     if (ModelState.IsValid)
     {
         db.Entry(userRoleMapping).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.RoleId = new SelectList(db.Roles, "RoleId", "RoleName", userRoleMapping.RoleId);
     ViewBag.UserId = new SelectList(db.Users, "UserId", "UserName", userRoleMapping.UserId);
     return(View(userRoleMapping));
 }
コード例 #15
0
        public ActionResult Create([Bind(Include = "UserId,RoleId")] UserRoleMapping userRoleMapping)
        {
            if (ModelState.IsValid)
            {
                db.UserRoleMappings.Add(userRoleMapping);
                db.SaveChanges();
                return(RedirectToAction("Login", "Login"));
            }

            ViewBag.RoleId = new SelectList(db.Roles, "RoleId", "RoleName", userRoleMapping.RoleId);
            ViewBag.UserId = new SelectList(db.Users, "UserId", "UserName", userRoleMapping.UserId);
            return(View(userRoleMapping));
        }
コード例 #16
0
        // GET: Mappings/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserRoleMapping userRoleMapping = db.UserRoleMappings.Find(id);

            if (userRoleMapping == null)
            {
                return(HttpNotFound());
            }
            return(View(userRoleMapping));
        }
コード例 #17
0
ファイル: UserRepo.cs プロジェクト: BhedaInfoTech/MLMBiowill
        private List <SqlParameter> Set_Values_In_UserRoleMapping(UserRoleMapping _userInfo)
        {
            List <SqlParameter> sqlParams = new List <SqlParameter>();

            sqlParams.Add(new SqlParameter("@Id", _userInfo.UserRoleMappingId));
            sqlParams.Add(new SqlParameter("@UserId", _userInfo.UserId));
            sqlParams.Add(new SqlParameter("@RoleId", _userInfo.RoleId));
            if (_userInfo.UserRoleMappingId == 0)
            {
                sqlParams.Add(new SqlParameter("@CreatedBy", _userInfo.CreatedBy));
            }
            sqlParams.Add(new SqlParameter("@UpdatedBy", _userInfo.UpdatedBy));
            sqlParams.Add(new SqlParameter("@Active", _userInfo.Active));
            return(sqlParams);
        }
コード例 #18
0
        public void Edit(UserRoleMapping entity)
        {
            entity.IsActive = false;
            userRoleMappingRepository.Edit(entity);

            UserRoleMapping am = new UserRoleMapping();

            am.UniqueId     = Guid.NewGuid();
            am.Id           = entity.UniqueId;
            am.UserMasterId = entity.UserMasterId;
            am.RoleMasterId = entity.RoleMasterId;
            am.CreatedBy    = entity.CreatedBy;
            am.CreatedDate  = DateTime.Now;
            this.userRoleMappingRepository.Add(am);
        }
コード例 #19
0
        protected override void Seed(Common.WMSContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data.
            if (context.UserMaster.Where(x => x.Username == "Admin123" && x.IsActive == true).Count() == 0)
            {
                UserMaster user = new UserMaster();
                user.UniqueId    = Guid.NewGuid();
                user.Username    = "******";
                user.FirstName   = "Admin";
                user.MiddleName  = "12";
                user.LastName    = "3";
                user.Password    = "******";
                user.IsActive    = true;
                user.CreatedDate = DateTime.Now;
                user.CreatedBy   = "System";

                context.UserMaster.Add(user);

                RoleMaster role = new RoleMaster
                {
                    UniqueId    = Guid.NewGuid(),
                    Name        = "Admin",
                    IsActive    = true,
                    CreatedDate = DateTime.Now,
                    CreatedBy   = "System"
                };

                context.RoleMaster.Add(role);

                UserRoleMapping userRoleMapping = new UserRoleMapping
                {
                    UniqueId     = Guid.NewGuid(),
                    UserMasterId = user.UniqueId,
                    RoleMasterId = role.UniqueId,
                    IsActive     = true,
                    CreatedDate  = DateTime.Now,
                    CreatedBy    = "System"
                };

                context.UserRoleMapping.Add(userRoleMapping);

                context.SaveChanges();
                base.Seed(context);
            }
        }
コード例 #20
0
        // GET: Mappings/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserRoleMapping userRoleMapping = db.UserRoleMappings.Find(id);

            if (userRoleMapping == null)
            {
                return(HttpNotFound());
            }
            ViewBag.RoleId = new SelectList(db.Roles, "RoleId", "RoleName", userRoleMapping.RoleId);
            ViewBag.UserId = new SelectList(db.Users, "UserId", "UserName", userRoleMapping.UserId);
            return(View(userRoleMapping));
        }
コード例 #21
0
        public async Task <IActionResult> Update(string id, UserRoleMapping urm)
        {
            if (urm == null)
            {
                return(BadRequest());
            }

            urm.Id = new Guid(id);
            var result = await urmrRepository.Update(urm);

            if (result == 1)
            {
                return(Ok());
            }
            return(NoContent());
        }
コード例 #22
0
ファイル: UserService.cs プロジェクト: soravs/WorkChop
        /// <summary>
        /// Method to save user with role
        /// </summary>
        /// <param name="userVM"></param>
        /// <returns></returns>
        public UserResponseModel Insert(User userVM)
        {
            var isUserExists = GetByQuery(userVM.Email);
            var userData     = new UserResponseModel();

            if (isUserExists != null)
            {
                userData.HasError     = true;
                userData.ErrorMessage = "Email Already registered";
                return(userData);
            }

            userVM.UserID    = new Guid();
            userVM.CreatedOn = DateTime.UtcNow;
            userVM.UpdatedOn = DateTime.UtcNow;

            string saltKey = Security.CreateSalt();

            userVM.PasswordSalt = saltKey;
            userVM.Password     = Security.Encrypt(userVM.Password, saltKey);

            _unitOfwork.UserRepository.Add(userVM);

            var userRoleMapping = new UserRoleMapping()
            {
                UserRoleMappingId = new Guid(),
                Fk_UserId         = userVM.UserID,
                CreatedOn         = DateTime.UtcNow,
                Fk_RoleId         = (int)UserRoleEnum.Teacher
            };

            _unitOfwork.UserRoleRelationRepository.Add(userRoleMapping);



            AutoMapper.Mapper.CreateMap <User, UserResponseModel>();
            userData.HasError     = false;
            userData.ErrorMessage = string.Empty;

            return(userData);
        }
コード例 #23
0
        public LabDbContext.User CreateNewUser(Person personInstance,
                                               string userName,
                                               string password)
        {
            LabDbContext.User output = new LabDbContext.User();
            output.FullName       = "";
            output.UserName       = userName;
            output.HashedPassword = CalculateHash(password, userName);
            output.Person         = _entities.People.First(per => per.ID == personInstance.ID);

            foreach (UserRole role in _entities.UserRoles)
            {
                UserRoleMapping tempMapping = new UserRoleMapping();
                tempMapping.UserRole   = role;
                tempMapping.IsSelected = false;

                output.RoleMappings.Add(tempMapping);
            }
            _entities.Users.Add(output);
            _entities.SaveChanges();

            return(output);
        }
コード例 #24
0
        protected UserRoleMapping GetObject(DataRow dr)
        {
            UserRoleMapping objUserRoleMapping = new UserRoleMapping();
            objUserRoleMapping.Id = (dr["Id"] == DBNull.Value) ? 0 : (Int64)dr["Id"];
            objUserRoleMapping.UserId = (dr["UserId"] == DBNull.Value) ? 0 : (Int32)dr["UserId"];
            objUserRoleMapping.RoleId = (dr["RoleId"] == DBNull.Value) ? 0 : (Int32)dr["RoleId"];
            objUserRoleMapping.CompanyId = (dr["CompanyId"] == DBNull.Value) ? 0 : (Int32)dr["CompanyId"];

            return objUserRoleMapping;
        }
コード例 #25
0
        public bool IsInRole(string role)
        {
            UserRoleMapping tempURM = _identity.User.RoleMappings.First(urm => urm.UserRole.Name == role);

            return(tempURM.IsSelected);
        }
コード例 #26
0
ファイル: UserRepo.cs プロジェクト: BhedaInfoTech/MLMBiowill
 public void Update_UserRoleMapping(UserRoleMapping _userInfo)
 {
     _sqlRepo.ExecuteNonQuery(Set_Values_In_UserRoleMapping(_userInfo), StoredProcedureEnum.sp_Update_UserMaster.ToString(), CommandType.StoredProcedure);
 }
コード例 #27
0
ファイル: UserRepo.cs プロジェクト: BhedaInfoTech/MLMBiowill
 public int Insert_UserRoleMapping(UserRoleMapping _userInfo)
 {
     return(Convert.ToInt32(_sqlRepo.ExecuteScalerObj(Set_Values_In_UserRoleMapping(_userInfo), StoredProcedureEnum.sp_Insert_UserMaster.ToString(), CommandType.StoredProcedure)));
 }
コード例 #28
0
        protected override void Seed(CollegeDbContext context)
        {
            var courses = new List <Course>
            {
                new Course {
                    CourseId = 1, Name = "Aerospace Engineering"
                },
                new Course {
                    CourseId = 2, Name = "Computer Science Engineering"
                },
                new Course {
                    CourseId = 3, Name = "Electrical Engineering"
                },
                new Course {
                    CourseId = 4, Name = "Civil Engineering"
                },
                new Course {
                    CourseId = 5, Name = "Electronics and Communication Engineering"
                },
            };

            var subjects = new List <Subject>
            {
                new Subject {
                    Name = "Aerodynamics", RelatedCourseId = 1, CreditPoints = 4
                },
                new Subject {
                    Name = "Aerospace Propulsion", RelatedCourseId = 1, CreditPoints = 3
                },
                new Subject {
                    Name = "Data Structures", RelatedCourseId = 2, CreditPoints = 4
                },
                new Subject {
                    Name = "Distributed Systems", RelatedCourseId = 2, CreditPoints = 4
                },
                new Subject {
                    Name = "Power Control", RelatedCourseId = 3, CreditPoints = 4
                },
                new Subject {
                    Name = "Digital Signal Processing", RelatedCourseId = 3, CreditPoints = 3
                },
                new Subject {
                    Name = "Fluid Mechanics", RelatedCourseId = 4, CreditPoints = 4
                },
                new Subject {
                    Name = "Reinforced Concrete Structures", RelatedCourseId = 4, CreditPoints = 4
                },
                new Subject {
                    Name = "Digital Communication", RelatedCourseId = 5, CreditPoints = 4
                },
                new Subject {
                    Name = "Mixed Mode VSLI Design", RelatedCourseId = 5, CreditPoints = 3
                }
            };

            context.Courses.AddRange(courses);

            context.Subjects.AddRange(subjects);

            var user = new User {
                UserId = 1, FirstName = "Breme", LastName = "Vinoth", Email = "*****@*****.**", Password = "******", PhoneNumber = 8050683885, IsActive = true
            };

            var roles = new List <UserRole>
            {
                new UserRole {
                    RoleId = 1, Role = "Admin", Previleges = $"{Operations.Admin},{Operations.Courses},{Operations.Staffs},{Operations.Students}"
                },
                new UserRole {
                    RoleId = 2, Role = "IT", Previleges = $"{Operations.Admin},{Operations.Staffs},{Operations.Students}"
                },
                new UserRole {
                    RoleId = 3, Role = "Helpdesk", Previleges = $"{Operations.Staffs}"
                },
                new UserRole {
                    RoleId = 4, Role = "Student", Previleges = $"{Operations.Students}"
                }
            };

            var mapping = new UserRoleMapping {
                MappingId = 1, RoleId = 1, UserId = 1
            };

            context.Users.Add(user);

            context.UserRoles.AddRange(roles);

            context.UserRoleMapping.Add(mapping);

            base.Seed(context);
        }
コード例 #29
0
        public async Task <IActionResult> Add(UserRoleMapping urm)
        {
            await urmrRepository.Create(urm);

            return(Ok());
        }
コード例 #30
0
        public void SaveUsersData(UsersDTO userDTO)
        {
            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <UsersDTO, UserMaster>();
                cfg.CreateMap <UserRoleMappingDTO, UserRoleMapping>();
                cfg.CreateMap <WorkFlowMasterDTO, WorkFlowMaster>();
                cfg.CreateMap <WorkFlowDetailsDTO, WorkFlowDetail>();
                cfg.CreateMap <UserAccessRightsDTO, UserAccessRight>();
            });
            IMapper mapper = config.CreateMapper();

            var SaveUserDetails = mapper.Map <UsersDTO, UserMaster>(userDTO);

            var workFlowMasterDetails = mapper.Map <List <WorkFlowMasterDTO>, List <WorkFlowMaster> >(userDTO.WorkFlowMasterMappings);

            using (var context = new BIPortalEntities())
            {
                var saveUserMaster = new UserMaster
                {
                    Salutation   = SaveUserDetails.Salutation,
                    FirstName    = SaveUserDetails.FirstName,
                    LastName     = SaveUserDetails.LastName,
                    EmailID      = SaveUserDetails.EmailID,
                    PermissionID = SaveUserDetails.PermissionID,
                    CreatedDate  = DateTime.Now,
                    CreatedBy    = SaveUserDetails.CreatedBy,
                    ModifiedDate = DateTime.Now,
                    Active       = SaveUserDetails.Active,
                    BIObjectType = SaveUserDetails.BIObjectType
                };

                // Insert UserRoleMapping
                foreach (var d in userDTO.SelectedRolesValues)
                {
                    var userrolemapping = new UserRoleMapping
                    {
                        //RoleID = 1, //should come from UI
                        RoleID      = d,
                        CreatedDate = DateTime.Now,
                        CreatedBy   = SaveUserDetails.CreatedBy,
                        Active      = true
                    };
                    saveUserMaster.UserRoleMappings.Add(userrolemapping);
                }


                // Insert UserAcessRights
                foreach (var e in userDTO.UserAccessRightsMappings)
                {
                    var userRightsAccessMapping = new UserAccessRight
                    {
                        UserID        = SaveUserDetails.UserID,
                        WorkspaceID   = e.WorkspaceID,
                        WorkspaceName = e.WorkspaceName,
                        ReportID      = e.ReportID,
                        ReportName    = e.ReportName,
                        //CreatedDate = e.CreatedDate,
                        CreatedDate = DateTime.Now,
                        CreatedBy   = e.CreatedBy,
                        Active      = e.Active
                    };
                    saveUserMaster.UserAccessRights.Add(userRightsAccessMapping);
                }
                context.UserMasters.Add(saveUserMaster);
                context.SaveChanges();

                context.WorkFlowMasters.AddRange(workFlowMasterDetails);
                context.SaveChanges();
            }
        }
コード例 #31
0
        public void UpdateUsersData(UsersDTO userDTO)
        {
            try
            {
                var config = new MapperConfiguration(cfg =>
                {
                    cfg.CreateMap <UsersDTO, UserMaster>();
                    cfg.CreateMap <UserRoleMappingDTO, UserRoleMapping>();
                    cfg.CreateMap <WorkFlowMasterDTO, WorkFlowMaster>();
                    cfg.CreateMap <WorkFlowDetailsDTO, WorkFlowDetail>();
                    cfg.CreateMap <UserAccessRightsDTO, UserAccessRight>();
                });
                IMapper mapper = config.CreateMapper();

                var updateUserDetails = mapper.Map <UsersDTO, UserMaster>(userDTO);

                var workFlowMasterDetails = mapper.Map <List <WorkFlowMasterDTO>, List <WorkFlowMaster> >(userDTO.WorkFlowMasterMappings);

                using (var context = new BIPortalEntities())
                {
                    var EditUserData = context.UserMasters.Where(x => x.UserID == updateUserDetails.UserID).FirstOrDefault();

                    if (EditUserData != null)
                    {
                        EditUserData.EmailID      = updateUserDetails.EmailID;
                        EditUserData.FirstName    = updateUserDetails.FirstName;
                        EditUserData.LastName     = updateUserDetails.LastName;
                        EditUserData.PermissionID = updateUserDetails.PermissionID;
                        EditUserData.Salutation   = updateUserDetails.Salutation;
                        EditUserData.CreatedDate  = DateTime.Now;
                        EditUserData.ModifiedBy   = updateUserDetails.ModifiedBy;
                        EditUserData.ModifiedDate = DateTime.Now;
                        EditUserData.Active       = updateUserDetails.Active;
                        EditUserData.BIObjectType = updateUserDetails.BIObjectType;
                        context.SaveChanges();
                    }


                    // remove existing UserRoleMapping for userid
                    var userRoleMappingRoleExists = context.UserRoleMappings.Where(x => x.UserID == updateUserDetails.UserID);
                    if (userRoleMappingRoleExists != null)
                    {
                        context.UserRoleMappings.RemoveRange(userRoleMappingRoleExists);
                        context.SaveChanges();
                    }

                    // Insert UserRoleMapping
                    foreach (var d in userDTO.SelectedRolesValues)
                    {
                        var userrolemapping = new UserRoleMapping
                        {
                            //RoleID = 1, //should come from UI
                            RoleID      = d,
                            CreatedDate = DateTime.Now,
                            //CreatedBy = "Selva",
                            CreatedBy = updateUserDetails.CreatedBy,
                            Active    = true
                        };
                        EditUserData.UserRoleMappings.Add(userrolemapping);
                    }
                    context.SaveChanges();

                    // remove existing UserAccessRights for userid
                    var userUserAccessRightsMappingUserExists = context.UserAccessRights.Where(x => x.UserID == updateUserDetails.UserID);
                    if (userUserAccessRightsMappingUserExists != null)
                    {
                        context.UserAccessRights.RemoveRange(userUserAccessRightsMappingUserExists);
                        context.SaveChanges();
                    }

                    //Insert UserAccessRights
                    foreach (var e in userDTO.UserAccessRightsMappings)
                    {
                        var userRightsAccessMapping = new UserAccessRight
                        {
                            UserID        = updateUserDetails.UserID,
                            WorkspaceID   = e.WorkspaceID,
                            WorkspaceName = e.WorkspaceName,
                            ReportID      = e.ReportID,
                            ReportName    = e.ReportName,
                            CreatedDate   = DateTime.Now,
                            CreatedBy     = e.CreatedBy,
                            ModifiedDate  = DateTime.Now,
                            ModifiedBy    = e.ModifiedBy,
                            Active        = e.Active
                        };
                        EditUserData.UserAccessRights.Add(userRightsAccessMapping);
                    }
                    context.SaveChanges();

                    // save only active users
                    if (userDTO.Active)
                    {
                        context.WorkFlowMasters.AddRange(workFlowMasterDetails);
                        context.SaveChanges();
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }
        }