コード例 #1
0
        async public Task <IActionResult> Register(RegisterForm register)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.Values.SelectMany(state => state.Errors)
                                  .Select(error => error.ErrorMessage).FirstOrDefault()));
            }

            var registerUser = new UserCustom();

            registerUser.UserName = register.UserName;
            registerUser.Email    = register.EmailAddress;

            var IsUserCreated = await userManager.CreateAsync(registerUser, register.Password);

            if (!IsUserCreated.Succeeded)
            {
                return(BadRequest(IsUserCreated.Errors.FirstOrDefault()));
            }
            var role = await userManager.AddToRoleAsync(registerUser, "Member");

            if (!role.Succeeded)
            {
                return(BadRequest(role.Errors.FirstOrDefault()));
            }
            var loginForm = new LoginForm {
                UserName = register.UserName, Password = register.Password
            };

            return(await Login(loginForm));
        }
コード例 #2
0
        public string GetVerifiedTrainerList(string param = "")
        {
            UserCustom usercustom = JsonConvert.DeserializeObject <UserCustom>(param);

            usercustom = _service.TrainerRepository.GetVerifiedTrainerList(usercustom);
            return(JsonConvert.SerializeObject(usercustom));
        }
コード例 #3
0
ファイル: UsersController.cs プロジェクト: khoannd/aspnetmvc
        public ActionResult Login(UserCustom userModelView)
        {
            if (ModelState.IsValid)
            {
                if (!string.IsNullOrEmpty(userModelView.UserName) &&
                    !string.IsNullOrEmpty(userModelView.Password))
                {
                    string password = EncMD5(userModelView.Password.Trim());
                    var    user     = db.Users.FirstOrDefault(u => u.UserName == userModelView.UserName.Trim() && u.Password == password && u.Active);

                    if (user != null)
                    {
                        Session["UserID"] = user.UserID;
                        Response.Cookies.Add(new HttpCookie("UserID", user.UserID.ToString()));
                        return(RedirectToAction("Index", "News"));
                    }
                    else
                    {
                        ViewBag.ErrorMessage = "User name or password is incorrect";
                    }
                }
                else
                {
                    ViewBag.ErrorMessage = "User name or password is empty";
                }
            }
            return(View(userModelView));
        }
コード例 #4
0
        public string GetNonVerifiedEmployeeList(string param = "")
        {
            UserCustom usercustom = JsonConvert.DeserializeObject <UserCustom>(param);

            usercustom = _service.EmployeeRepository.GetNonVerifiedEmployeeList(usercustom);
            return(JsonConvert.SerializeObject(usercustom));
        }
コード例 #5
0
        public ActionResult ChangePassword(string param = "")
        {
            UserCustom usermodel = JsonConvert.DeserializeObject <UserCustom>(param);
            long       result    = 0;

            result = _service.EmployeeRepository.ChangeEmployeePassword(usermodel);
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
コード例 #6
0
        /// <summary>
        /// convert user in data base to user public for api
        /// </summary>
        /// <param name="elem"></param>
        /// <returns>return new user as public</returns>
        private async Task <UserPublic> createUserPublic(UserCustom elem)
        {
            UserPublic node = new UserPublic();

            node.Id          = elem.Id;
            node.Name        = elem.UserName;
            node.Email       = elem.Email;
            node.PhoneNumber = elem.PhoneNumber;
            node.Role        = (await _userManager.GetRolesAsync(elem))[0];
            return(node);
        }
コード例 #7
0
        /// <summary>
        /// modify user information in database
        /// </summary>
        /// <param name="user"></param>
        private async Task SetUserInfoFromUserPublic(UserPublic user, UserCustom userData)
        {
            userData.UserName = user.Name;
            userData.Email    = user.Email;
            await _userManager.RemoveFromRoleAsync(userData, (await _userManager.GetRolesAsync(userData))[0]);

            await _userManager.AddToRoleAsync(userData, user.Role);

            await _userManager.UpdateAsync(userData);

            return;
        }
コード例 #8
0
ファイル: User_ViewModel.cs プロジェクト: minhhoangg2809/QLBX
        private void getLst()
        {
            List <Models.User> listUser = new List <User>(Models.DataProvider.Ins.DB.Users);

            List = new ObservableCollection <UserCustom>();
            for (int i = 0; i < listUser.Count(); i++)
            {
                UserCustom u = new UserCustom();
                u = UserCustom.MapUserCus(listUser[i]);
                List.Add(u);
            }
        }
コード例 #9
0
        public async Task <IActionResult> OnPostAsync(IFormFile file, string returnUrl = null)
        {
            returnUrl      = returnUrl ?? Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                var user = new UserCustom {
                    UserName = Input.Email, Email = Input.Email, Firstname = Input.FirstName,
                    LastName = Input.LastName, PhoneNumber = Input.PhoneNumber, DisplayName = Input.DisplayName
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    if (file != null)
                    {
                        _unitOfWork.UploadImage(file, user.Id);
                        user.ImagePath = file.FileName;
                    }
                    else
                    {
                        user.ImagePath = "defaultProfilePhoto.jpg";
                    }
                    await _userManager.UpdateAsync(user);

                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));

                    if (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl }));
                    }
                    else
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
コード例 #10
0
ファイル: CMSService.cs プロジェクト: SubhoM/ReportApp
        public static List <IdentifiedUser> GetIdentifiedUsers(string siteIDs, string programIDs, string coPIDs, string tagIDs)
        {
            var identifiedUserList = new List <IdentifiedUser>();

            identifiedUserList = UserCustom.GetIdentifiedUsers(siteIDs, programIDs, coPIDs, tagIDs);

            identifiedUserList.Insert(0, new IdentifiedUser
            {
                UserID   = -1,
                FullName = "All"
            });

            return(identifiedUserList);
        }
コード例 #11
0
        public ActionResult Details(int id)
        {
            CheckConnection();
            var dream = _db.Dreams.Find(id);

            var user = new UserCustom()
            {
                UserName = dream.User.UserName,
                Id       = dream.UserID
            };

            ViewBag.user = user;
            return(View(_db.Dreams.Find(id)));
        }
コード例 #12
0
        private async Task LoadAsync(UserCustom user)
        {
            var userName = await _userManager.GetUserNameAsync(user);

            var phoneNumber = await _userManager.GetPhoneNumberAsync(user);

            Username  = userName;
            ImagePath = user.ImagePath;
            FullPath  = "/uploads/users/" + user.Id + "/avatars/" + ImagePath;

            Input = new InputModel
            {
                PhoneNumber = phoneNumber
            };
        }
コード例 #13
0
ファイル: CMSService.cs プロジェクト: SubhoM/ReportApp
        public static List <Tag> GetTagsByProgramIDAndCoPID(string ProgramIDs, string CoPIDs)
        {
            var taglist = new List <Tag>();

            if (CoPIDs != "-1")
            {
                taglist = UserCustom.GetTagsByProgramIDAndCoPID(ProgramIDs, CoPIDs);
            }

            taglist.Insert(0, new Tag
            {
                TagID   = -1,
                TagCode = "All"
            });

            return(taglist);
        }
コード例 #14
0
ファイル: CMSService.cs プロジェクト: SubhoM/ReportApp
        public static List <CoP> GetCoPsByProgramID(string ProgramIDs)
        {
            var coplist = new List <CoP>();

            if (ProgramIDs != "-1")
            {
                coplist = UserCustom.GetCoPsByProgramID(ProgramIDs);
            }

            coplist.Insert(0, new CoP
            {
                CopID   = -1,
                CopName = "All"
            });

            return(coplist);
        }
コード例 #15
0
        public async Task <IActionResult> PutAsync(string id, string username, [FromBody] UserCustom model)
        {
            var response = new UserResponse();

            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByIdAsync(id);

                if (user == null || user.UserName != username)
                {
                    return(BadRequest());
                }

                user.Email = model.Email;

                if (!String.IsNullOrEmpty(model.PhoneNumber))
                {
                    user.PhoneNumber = model.PhoneNumber;
                }

                response.Result = await _userManager.UpdateAsync(user);

                response.Succeeded = response.Result.Succeeded;

                return(Ok(response));
            }
            else
            {
                var errors = new List <string>();

                foreach (var modelErrors in ModelState)
                {
                    string propertyName = modelErrors.Key;
                    errors.Add($"Not valid {propertyName}.");
                }
                response.Errors = errors;

                return(BadRequest(response));
            }
        }
コード例 #16
0
ファイル: Startup.cs プロジェクト: Mediwatch/BlazyWatch
        private async Task CreateRoles(IServiceProvider serviceProvider)
        {
            //adding custom roles
            var RoleManager = serviceProvider.GetRequiredService <RoleManager <IdentityRole <Guid> > >();
            var UserManager = serviceProvider.GetRequiredService <UserManager <UserCustom> >();

            string[]       roleNames = { "Admin", "Tutor", "Member" };
            IdentityResult roleResult;

            foreach (var roleName in roleNames)
            {
                var roleExist = await RoleManager.RoleExistsAsync(roleName);

                if (!roleExist)
                {
                    roleResult = await RoleManager.CreateAsync(new IdentityRole <Guid>(roleName));
                }
            }
            //creating a super user who could maintain the web app
            var poweruser = new UserCustom
            {
                UserName = Configuration["SuperUser:Username"],
                Email    = Configuration["SuperUser:Email"]
            };

            string UserPassword = Configuration["SuperUser:Password"];
            var    _user        = await UserManager.FindByEmailAsync(Configuration["SuperUser:Email"]);

            if (_user == null)
            {
                var createPowerUser = await UserManager.CreateAsync(poweruser, UserPassword);

                if (createPowerUser.Succeeded)
                {
                    //here we tie the new user to the "Admin" role
                    await UserManager.AddToRoleAsync(poweruser, "Admin");
                }
            }
        }
コード例 #17
0
        public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
        {

            if (ModelState.IsValid)
            {
                bool signInSucess =  await SignInFrontAsync(model.UserName, model.Password);
                
                if (signInSucess)
                {
                    //var user = await UserManager.FindAsync(model.UserName, model.Password);
                    var user = new UserCustom { UserName = model.UserName, PasswordHash = model.Password };
                    if (user != null)
                    {
                        await SignInAsync(user, model.RememberMe);
                        using (customerDb = new VfsCustomerServiceEntities())
                        {
                            #region kiem tra khach hang VIP
                            var customer = await customerDb.Customers.FirstOrDefaultAsync(cs => cs.CustomerId == user.UserName);               
                            if (customer.VType == true)
                            {
                                Helper.SetCookieOfVIP();
                            }
                            #endregion

                            #region thong ke khach hang

                            var customerlog = await customerDb.CustomerLogs.FirstOrDefaultAsync(cl => cl.CustomerId == user.UserName);
                            if (customerlog == null)
                            {
                                // insert log
                                customerlog = new CustomerLog();
                                customerlog.CreateDate = DateTime.Now;
                                customerlog.CustomerId = user.UserName;
                                customerlog.Total_Download = 0;
                                customerlog.Total_Login = 1;
                                customerDb.CustomerLogs.Add(customerlog);                                
                            }
                            else
                            {
                                //update log                                
                                customerlog.Total_Download +=1;
                                customerlog.Total_Login +=1;
                                customerDb.Entry(customerlog).State = EntityState.Modified;

                            }
                            await customerDb.SaveChangesAsync(); // save database
                            #endregion
                        }
                        return RedirectToLocal(returnUrl);
                    }
                }
                
                else
                {
                    ModelState.AddModelError("", "Invalid username or password.");
                }
            }
            ViewBag.ReturnUrl = returnUrl;
            // If we got this far, something failed, redisplay form
            return View(model);
        }
コード例 #18
0
 private async Task SignInAsync(UserCustom user, bool isPersistent)
 {
     AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
     var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
     AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity);
 }
コード例 #19
0
        public async Task <IActionResult> LoginExtCallback(string returnUrl, string remoteError = null)
        {
            if (remoteError != null)
            {
                return(BadRequest(remoteError));
            }

            var info = await signInManager.GetExternalLoginInfoAsync();

            if (info == null)
            {
                return(RedirectToPage("Can't find external login"));
            }

            var signIn = await signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, false, true);

            if (signIn.Succeeded)
            {
                return(Redirect("~/"));
            }

            var userEmail = info.Principal.FindFirstValue(ClaimTypes.Email);
            var userName  = info.Principal.FindFirstValue(ClaimTypes.Name);

            if (string.IsNullOrEmpty(userEmail))
            {
                return(BadRequest($"{info.ProviderDisplayName} has no email"));
            }
            if (string.IsNullOrEmpty(userName))
            {
                return(BadRequest($"{info.ProviderDisplayName} has no username"));
            }

            var user = new UserCustom {
                Id = System.Guid.NewGuid(), UserName = userName, Email = userEmail
            };
            var dbUser = await userManager.CreateAsync(user);

            if (!dbUser.Succeeded)
            {
                return(BadRequest(dbUser.Errors.FirstOrDefault()));
            }

            var role = await userManager.AddToRoleAsync(user, "Member");

            if (!role.Succeeded)
            {
                return(BadRequest(role.Errors.FirstOrDefault()));
            }

            await userManager.AddClaimAsync(user, new Claim("Creation", System.DateTime.Now.ToString()));

            dbUser = await userManager.AddLoginAsync(user, info);

            if (!dbUser.Succeeded)
            {
                return(BadRequest(dbUser.Errors.FirstOrDefault()));
            }
            await signInManager.SignInAsync(user, true);

            return(LocalRedirect("~/"));
        }
コード例 #20
0
        public static void SetUpSession(bool fromportal = false, Models.Authentication objAuthenticationUser = null)
        {
            try {
                var    ProductParamDictionary = new StringDictionary();
                var    objUser                = new Models.Authentication();
                var    menuService            = new Services.MenuService();
                bool   LOCALDEBUG             = false;
                string fromProduct            = null;
                string decryptedProductParams = null;

                LOCALDEBUG = Convert.ToBoolean(ConfigurationManager.AppSettings["LOCALDEBUG"]);

                if (LOCALDEBUG == false)
                {
                    if (HttpContext.Current.Request.QueryString["FromPortal"] != null)
                    {
                        fromProduct = HttpContext.Current.Request.QueryString["FromPortal"];
                    }

                    if (HttpContext.Current.Request.QueryString["FromProduct"] != null)
                    {
                        fromProduct = HttpContext.Current.Request.QueryString["FromProduct"];
                    }

                    if (fromProduct == null)
                    {
                        return;
                    }

                    // When decrypted, the decryptProductParams variable looks like this:
                    // UserID|100106|Token|479bb3e7-079a-4a97-950f-41da256c6928|PageID|14|currentUTCtime|09/25/2017 19:56:41
                    decryptedProductParams = CryptHelpers.Decrypt(fromProduct, WebConstants.ENCRYPT_KEY);

                    using (IEnumerator <string> enumerator = decryptedProductParams.Split('|').AsEnumerable().GetEnumerator()) {
                        while (enumerator.MoveNext())
                        {
                            string first = enumerator.Current;
                            if (!enumerator.MoveNext())
                            {
                                break;
                            }
                            ProductParamDictionary.Add(first, enumerator.Current);
                        }
                    }

                    objUser.UserID      = Convert.ToInt32(ProductParamDictionary["UserID"]);
                    objUser.AuthToken   = ProductParamDictionary["Token"];
                    objUser.PageID      = Convert.ToInt32(ProductParamDictionary["PageID"]);
                    objUser.AdminUserID = Convert.ToInt32(ProductParamDictionary["AdminUserID"]);

                    #region Process currentUTCtime from Querystring. If currentUTCtime not found, log exception & redirect request to login.

                    if (ProductParamDictionary[ProductQueryStringKey.currentUTCtime.ToString()] != null)
                    {
                        var ProductUtCtime = Convert.ToDateTime(ProductParamDictionary[ProductQueryStringKey.currentUTCtime.ToString()]);
                        var currentUtCtime = DateTime.UtcNow.ToString(CultureInfo.InvariantCulture);

                        // 5 minute check between servers
                        if ((DateTime.Parse(currentUtCtime.ToString(CultureInfo.InvariantCulture)))
                            .Subtract(DateTime.Parse(ProductUtCtime.ToString(CultureInfo.InvariantCulture)))
                            .Seconds > 300)
                        {
                            if (Convert.ToBoolean(ConfigurationManager.AppSettings["PortalRedirect"]))
                            {
                                HttpContext.Current.Response.Redirect(string.Format("Transfer.aspx?qs={0}", (int)QueryStringValue.TimeOut), false);
                                HttpContext.Current.Response.End();
                            }
                        }
                    }
                    else
                    {
                        // =================================================================================================
                        // If currentUTCtime KVP not found, log error in ExceptionLog and reroute user to login screen.
                        // =================================================================================================
                        ExceptionService exceptionService = new ExceptionService();
                        ExceptionLog     exLog            = new ExceptionLog();
                        exLog.ExceptionText = "KVP currentUTCtime missing from ecrypted querystring.";
                        exLog.PageName      = "JCR.Reports.Common.Security.cs";
                        exLog.MethodName    = "SetUpSession";
                        exLog.UserID        = objUser.UserID;
                        exLog.SiteId        = 0;
                        exLog.TransSQL      = string.Format("Unencrypted Querystring: {0}", decryptedProductParams);
                        exLog.HttpReferrer  = null;
                        exceptionService.LogException(exLog);
                        HttpContext.Current.Response.Redirect("~/Transfer/LogoutRedirect");
                    }

                    #endregion

                    // Mark Orlando 10/18/2017. When AMP is called from AdminTool, UserOriginalRoleID KVP will contain 5 aka Global Admin.
                    // If UserOriginalRoleID is 5, then AdminTool will pass AMP the GA's User ID in UserOriginalRoleID KVP.
                    // Default values of 0 indicate the real user is not GA, but rather a customer.
                    // When GAdmin logged-in as customer and went from AMP to Reports here's what Querystring looked like:
                    // UserID|100106|Token|28D07930-AF85-42CE-A80D-17CF51DDAF13|PageID|48|AdminUserID|123316|UserOriginalRoleID|5|currentUTCtime|11/27/2017 20:41:25
                    if (ProductParamDictionary["UserOriginalRoleID"] != null)
                    {
                        objUser.UserOriginalRoleID = Convert.ToInt32(ProductParamDictionary["UserOriginalRoleID"]);
                        objUser.AdminUserID        = Convert.ToInt32(ProductParamDictionary["AdminUserID"]);
                    }
                }
                else
                {
                    // Susan Easter has access to 10 sites, each of which has access to AMP & Tracers...except site 4758
                    // For this site, she has access to AMP, but not Tracers: Michael E. DeBakey VA MC Opioid Treatment Program


                    //objUser.UserLogonID = "*****@*****.**";
                    //objUser.UserLogonID = "*****@*****.**";
                    //objUser.UserLogonID = "*****@*****.**";
                    //objUser.UserLogonID = "*****@*****.**";
                    //objUser.UserLogonID = "*****@*****.**";
                    //objUser.UserLogonID = "*****@*****.**";
                    //objUser.UserLogonID = "*****@*****.**";
                    //objUser.UserLogonID = "*****@*****.**";
                    // objUser.UserLogonID = "*****@*****.**";
                    //objUser.UserLogonID = "*****@*****.**";
                    //objUser.UserLogonID = "*****@*****.**";
                    //objUser.UserLogonID = "*****@*****.**";
                    //objUser.UserLogonID = "*****@*****.**";
                    // objUser.UserLogonID = "*****@*****.**";
                    // objUser.UserLogonID = "*****@*****.**";  // Staff Member
                    // objUser.UserLogonID = "*****@*****.**";      // Site Manager
                    // objUser.UserLogonID = "*****@*****.**";
                    // objUser.UserLogonID = "*****@*****.**";
                    objUser.UserLogonID = "*****@*****.**";

                    //objUser.PageID = 14;      // PageID 14 is 'Reports Menu|Compliance'  aka AMP
                    objUser.PageID = 48;      // PageID 48 is 'Reports Menu|Tracers'
                    //objUser.PageID = 49;      // PageID 49 is 'Reports Menu|ER Tracers'
                }

                if (objAuthenticationUser != null)
                {
                    objUser = objAuthenticationUser;
                }

                menuService.Authenticate(objUser);

                if (objUser.InError)
                {
                    HttpContext ctx = HttpContext.Current;
                    ctx.Response.Redirect("~/Transfer/Error");
                }
                else
                {
                    if (LOCALDEBUG)
                    {
                        menuService.CreateStateWhenLocalDebugIsTrue(objUser.UserID);
                    }
                    AppSession.CreateSession();
                    AppSession.UserID             = objUser.UserID;
                    AppSession.AuthToken          = objUser.AuthToken;
                    AppSession.PageID             = objUser.PageID;
                    AppSession.AdminUserID        = objUser.AdminUserID;
                    AppSession.UserOriginalRoleID = objUser.UserOriginalRoleID;
                    AppSession.WebApiUrl          = ConfigurationManager.AppSettings["JCRAPI"].ToString();

                    var menuState = menuService.GetState(AppSession.UserID.GetValueOrDefault(), AppSession.AuthToken);

                    AppSession.EmailAddress                = menuState.UserLogonID;
                    AppSession.FirstName                   = menuState.FirstName;
                    AppSession.LastName                    = menuState.LastName;
                    AppSession.FullName                    = String.Format("{0} {1}", menuState.FirstName, menuState.LastName);
                    AppSession.RoleID                      = menuState.UserRoleID;
                    AppSession.SelectedSiteId              = menuState.SiteID;
                    AppSession.SelectedSiteName            = menuState.SiteName;
                    AppSession.SelectedProgramId           = menuState.ProgramID;
                    AppSession.SelectedProgramName         = menuState.ProgramName;
                    AppSession.CycleID                     = menuState.CycleID;
                    AppSession.IsCorporateSite             = menuState.AccessToMockSurvey;
                    AppSession.ProgramGroupTypeID          = menuState.ProgramGroupTypeID;
                    AppSession.IsCMSProgram                = menuState.AccessToCMS;
                    AppSession.HasTracersAccess            = menuState.AccessToTracers;
                    AppSession.SelectedCertificationItemID = menuState.CertificationItemID;

                    if (AppSession.SelectedCertificationItemID > 0)
                    {
                        var lstPrograms = UserCustom.GetProgramBySites(AppSession.SelectedSiteId);
                        if (lstPrograms != null && lstPrograms.Count > 0)
                        {
                            var queryBaseProgramID = lstPrograms.Where(prg => prg.ProgramID == AppSession.SelectedProgramId && prg.AdvCertListTypeID == AppSession.SelectedCertificationItemID).FirstOrDefault();

                            if (queryBaseProgramID != null)
                            {
                                AppSession.SelectedProgramId = (int)queryBaseProgramID.BaseProgramID;
                            }
                        }
                    }

                    switch (AppSession.PageID)
                    {
                    case 50:           // PageID 50 is My Saved Reports ● Tracers
                    case 15:           // PageID 15 is is My Saved Reports ● Compliance
                    case 51:           // PageID 51 is is My Saved Reports ● ER Tracers
                        AppSession.DirectView = "MyReports";
                        break;

                    case 52:           // PageID 52 is My Site's Saved Reports ● Tracers
                    case 16:           // PageID 16 is My Site's Saved Reports ● Compliance
                    case 53:           // PageID 53 is My Site's Saved Reports ● ER Tracers
                        AppSession.DirectView = "SearchReports";
                        break;
                    }

                    var commonService = new CommonService();

                    SearchInputService searchInputService = new SearchInputService();

                    AppSession.CycleID = commonService.GetLatestCycleByProgram(AppSession.SelectedProgramId).CycleID;

                    //if (AppSession.LinkType != 11) {
                    //    AppSession.Sites = searchInputService.SelectTracerSitesByUser(Convert.ToInt32(AppSession.UserID));
                    //    AppSession.CycleID = commonService.GetLatestCycleByProgram(AppSession.SelectedProgramId).CycleID;
                    //} else {
                    //   var SiteList = CorporateFinding.GetSitesByUser(Convert.ToInt32(AppSession.UserID)).Select(x => new UserSite() { SiteID = x.SiteID, SiteName = x.SiteName, RoleID = x.RoleID, SiteFullName = x.SiteFullName, IsCorporateAccess = x.IsCorporateAccess }).ToList();
                    //    AppSession.Sites = SiteList;
                    //}

                    //if (AppSession.Sites.Count == 0) {
                    //    AppSession.Sites = searchInputService.SelectTracerSitesByUser(Convert.ToInt32(AppSession.UserID));
                    //}

                    AppSession.Sites = SearchInputService.GetSitesByUser(AppSession.UserID);

                    foreach (var site in AppSession.Sites.ToList())
                    {
                        //site.Programs = new List<ProgramVM>();
                        //site.Programs.AddRange(new SearchInputService().SelectAllTracerProgramsBySiteAndUser(Convert.ToInt32(AppSession.UserID), site.SiteID, Convert.ToInt32(AppSession.CycleID)));

                        site.Programs = UserCustom.GetProgramBySites(site.SiteID);
                    }

                    commonService.GetHelpLink();
                    UpdateAppLogin();
                }
            }
            catch (Exception ex) {
                throw ex;
            }
        }
コード例 #21
0
ファイル: CMSService.cs プロジェクト: SubhoM/ReportApp
 public static List <CMSProgram> GetCMSProgramsBySiteID(int SiteID, int subscriptionTypeID)
 {
     return(UserCustom.GetCMSProgramsBySiteID(SiteID, subscriptionTypeID));
 }
コード例 #22
0
ファイル: CMSService.cs プロジェクト: SubhoM/ReportApp
 public static List <CMSSite> GetCMSSitesByProgramID(int ProgramID, int subscriptionTypeID)
 {
     return(UserCustom.GetCMSSitesByProgramID(ProgramID, subscriptionTypeID));
 }
コード例 #23
0
ファイル: CMSService.cs プロジェクト: SubhoM/ReportApp
        public static void UpdateCMSSessionValue()
        {
            var subscriptionTypeID = GetSubscriptionTypeIDForCMS((WebConstants.LinkType)AppSession.LinkType);

            AppSession.IsCMSProgram = UserCustom.GetLicenseDetailsForCMS(AppSession.SelectedSiteId, AppSession.SelectedProgramId, subscriptionTypeID);
        }
コード例 #24
0
ファイル: UserCustom.cs プロジェクト: gladiopeace/SN-Stock
 public static bool Add(UserCustom user)
 {
     DummyUsersList.Add(user);
     return(true);
 }
コード例 #25
0
ファイル: User_ViewModel.cs プロジェクト: minhhoangg2809/QLBX
        public User_ViewModel()
        {
            Load_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                getLst();
                UserName     = String.Empty;
                Account      = String.Empty;
                Phone        = String.Empty;
                SelectedItem = null;
                IsActive     = false;
                IsAdd        = false;
                IsUpdate     = false;
                IsDelete     = false;

                ListRole = new ObservableCollection <string>();
                ListRole.Add("Quản trị");
                ListRole.Add("Nhân viên");

                SelectedRole = String.Empty;
            });

            CloseAlert_Command = new RelayCommand <object>(x =>
            {
                return(true);
            }, x =>
            {
                IsActive = false;
            });

            CloseDlg_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                IsAdd    = false;
                IsUpdate = false;
                IsDelete = false;
            });

            Search_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                getLst();
                if (!String.IsNullOrEmpty(UserName))
                {
                    List = new ObservableCollection <UserCustom>(List.Where(x => x.name.ToUpper().Contains(UserName.ToUpper())));
                }
                if (!String.IsNullOrEmpty(Account))
                {
                    List = new ObservableCollection <UserCustom>(List.Where(x => x.acc.ToUpper().Contains(Account.ToUpper())));
                }
                if (!String.IsNullOrEmpty(Phone))
                {
                    List = new ObservableCollection <UserCustom>(List.Where(x => x.phone.ToUpper().Contains(Phone.ToUpper())));
                }
            });

            PassChanged_Command = new RelayCommand <PasswordBox>(p =>
            {
                if (String.IsNullOrEmpty(p.Password))
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                SelectedItem.pass = MyStaticMethods.MD5Hash(p.Password);
            });

            #region sort

            SortbyName_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                ObservableCollection <UserCustom> chkList = new ObservableCollection <UserCustom>(List.OrderByDescending(x => x.name));

                if (List[0] == chkList[0])
                {
                    List = new ObservableCollection <UserCustom>(List.OrderBy(x => x.name));
                }
                else
                {
                    List = chkList;
                }
            });

            SortbyBorn_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                ObservableCollection <UserCustom> chkList = new ObservableCollection <UserCustom>(List.OrderByDescending(x => x.born));

                if (List[0] == chkList[0])
                {
                    List = new ObservableCollection <UserCustom>(List.OrderBy(x => x.born));
                }
                else
                {
                    List = chkList;
                }
            });

            SortbyAddress_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                ObservableCollection <UserCustom> chkList = new ObservableCollection <UserCustom>(List.OrderByDescending(x => x.user_address));

                if (List[0] == chkList[0])
                {
                    List = new ObservableCollection <UserCustom>(List.OrderBy(x => x.user_address));
                }
                else
                {
                    List = chkList;
                }
            });

            SortbyPhone_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                ObservableCollection <UserCustom> chkList = new ObservableCollection <UserCustom>(List.OrderByDescending(x => x.phone));

                if (List[0] == chkList[0])
                {
                    List = new ObservableCollection <UserCustom>(List.OrderBy(x => x.phone));
                }
                else
                {
                    List = chkList;
                }
            });

            SortbyAcc_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                ObservableCollection <UserCustom> chkList = new ObservableCollection <UserCustom>(List.OrderByDescending(x => x.acc));

                if (List[0] == chkList[0])
                {
                    List = new ObservableCollection <UserCustom>(List.OrderBy(x => x.acc));
                }
                else
                {
                    List = chkList;
                }
            });

            SortbyRole_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                ObservableCollection <UserCustom> chkList = new ObservableCollection <UserCustom>(List.OrderByDescending(x => x.user_role));

                if (List[0] == chkList[0])
                {
                    List = new ObservableCollection <UserCustom>(List.OrderBy(x => x.user_role));
                }
                else
                {
                    List = chkList;
                }
            });

            #endregion

            #region add

            OpenformAdd_Command = new RelayCommand <object>(p =>
            {
                if (IsUpdate == true || IsAdd == true || IsDelete == true)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                SelectedItem = new UserCustom();
                SelectedRole = "Nhân viên";
                IsAdd        = true;
            });

            Add_Command = new RelayCommand <object>(p =>
            {
                if (SelectedItem == null)
                {
                    return(false);
                }

                if (String.IsNullOrEmpty(SelectedItem.name))
                {
                    return(false);
                }

                if (String.IsNullOrEmpty(SelectedItem.user_address))
                {
                    return(false);
                }

                if (String.IsNullOrEmpty(SelectedItem.phone))
                {
                    return(false);
                }

                if (String.IsNullOrEmpty(SelectedItem.Born))
                {
                    return(false);
                }

                if (String.IsNullOrEmpty(SelectedItem.acc))
                {
                    return(false);
                }

                if (String.IsNullOrEmpty(SelectedRole))
                {
                    return(false);
                }

                if (String.IsNullOrEmpty(SelectedItem.pass))
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                var countAcc = List.Where(x => x.acc == SelectedItem.acc).Count();
                if (countAcc == 0)
                {
                    User user      = new User();
                    user           = UserCustom.MapUser(SelectedItem);
                    user.user_role = SelectedRole == "Quản trị" ? 1 : 0;

                    Models.DataProvider.Ins.DB.Users.Add(user);
                    Models.DataProvider.Ins.DB.SaveChanges();

                    IsAdd = false;
                    getLst();

                    successAlert();
                }
                else
                {
                    IsAdd = false;
                    getLst();

                    IsActive = true;
                    Message  = "Tên đăng nhập bị trùng";
                }
            });

            #endregion

            #region update

            OpenformUpdate_Command = new RelayCommand <Button>(p =>
            {
                if (IsUpdate == true || IsAdd == true || IsDelete == true)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                SelectedItem = new UserCustom();
                SelectedItem = List.Where(x => x.users_id == Convert.ToInt32(p.Uid)).SingleOrDefault();
                SelectedRole = SelectedItem.user_role == 1 ? "Quản trị" : "Nhân viên";
                IsUpdate     = true;
            });

            Update_Command = new RelayCommand <object>(p =>
            {
                if (SelectedItem == null)
                {
                    return(false);
                }

                if (String.IsNullOrEmpty(SelectedItem.name))
                {
                    return(false);
                }

                if (String.IsNullOrEmpty(SelectedItem.user_address))
                {
                    return(false);
                }

                if (String.IsNullOrEmpty(SelectedItem.phone))
                {
                    return(false);
                }

                if (String.IsNullOrEmpty(SelectedItem.Born))
                {
                    return(false);
                }

                if (String.IsNullOrEmpty(SelectedItem.Role))
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                User user         = Models.DataProvider.Ins.DB.Users.Where(x => x.users_id == SelectedItem.users_id).SingleOrDefault();
                user.name         = SelectedItem.name;
                user.user_address = SelectedItem.user_address;
                user.born         = Convert.ToDateTime(SelectedItem.Born);
                user.phone        = SelectedItem.phone;
                user.user_role    = SelectedRole == "Quản trị" ? 1 : 0;
                Models.DataProvider.Ins.DB.SaveChanges();

                IsUpdate = false;
                getLst();

                successAlert();
            });

            #endregion

            #region delete

            OpenformDelete_Command = new RelayCommand <Button>(p =>
            {
                if (IsUpdate == true || IsAdd == true || IsDelete == true)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                SelectedItem = new UserCustom();
                SelectedItem = List.Where(x => x.users_id == Convert.ToInt32(p.Uid)).SingleOrDefault();
                IsDelete     = true;
            });

            Delete_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                User user = Models.DataProvider.Ins.DB.Users.Where(x => x.users_id == SelectedItem.users_id).SingleOrDefault();
                Models.DataProvider.Ins.DB.Users.Remove(user);
                Models.DataProvider.Ins.DB.SaveChanges();

                IsDelete = false;
                getLst();

                successAlert();
            });

            #endregion
        }