Esempio n. 1
0
        public string AddAppUser(AppUserModel u)
        {
            string uid = "0";
            string msg = "用户添加失败!";

            if (HasAppUserNo(u.PHONE, u.FID))
            {
                uid = "-2";
                msg = "手机号码已存在。";
            }
            else
            {
                uid = AppUserDal.Instance.Insert(u);
                if (uid != "")
                {
                    msg = "添加APP用户成功!";
                    LogBll <AppUserModel> log = new LogBll <AppUserModel>();
                    u.FID = uid;
                    log.AddLog(u);
                }
            }
            return(new JsonMessage {
                Data = uid.ToString(), Message = msg, Success = uid != ""
            }.ToString());
        }
Esempio n. 2
0
        public async Task <ActionResult <AppUserModel> > Update(
            [FromRoute] long id,
            [FromBody] AppUserModel model
            )
        {
            try {
                var user = await userMgr.FindByIdAsync(id.ToString());

                if (user == null)
                {
                    return(NotFound());
                }
                var claims = user.UpdateFromUserModel(mapper, model);
                await AddOrReplaceClaims(user, claims);

                var result = await userMgr.UpdateAsync(user);

                if (result.Succeeded)
                {
                    mapper.Map(user, model);
                    return(model);
                }
                return(BadRequest(result.GetErrorsString()));
            }
            catch (Exception ex) {
                logger.LogError(ex, $"Can not update user by id {id} with {model.ToJson()}");
                return(this.InternalServerError(ex));
            }
        }
        public JsonResult Login(AppUserLoginModel appUserLoginModel)
        {
            Response response = new Response();

            tokenProvider = new TokenProvider();
            try
            {
                appUserProvider = new AppUserProvider();

                AppUserModel appuserModel = appUserProvider.GetLoginUser(appUserLoginModel).ResultModel;

                if (appuserModel != null)
                {
                    SessionExtension.Set <AppUserModel>(HttpContext.Session, "Login", appuserModel);

                    response = new Response()
                    {
                        Message     = "success",
                        Status      = true,
                        RedirectUrl = Url.Action("Index", "Home")
                    };
                }
            }
            catch (Exception ex)
            {
                response = new Response()
                {
                    Message = "Fail",
                    Status  = false,
                };
            }
            return(Json(response));
        }
Esempio n. 4
0
        public AppUserModel GetAppUser(Guid UserId)
        {
            AppUserEntity aspnetAppUser = appUserRepository.GetAppUser(UserId);
            AppUserModel  appUserModel  = mapper.Map <AppUserModel>(aspnetAppUser);

            return(appUserModel);
        }
        // GET: AdminController/Edit/5
        public async Task <ActionResult> Edit(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var user = await userManager.FindByIdAsync(id);

            if (user == null)
            {
                return(NotFound());
            }
            AppUserModel app = new AppUserModel
            {
                Id = user.Id,
                AccessFailedCount  = user.AccessFailedCount,
                DateOfBirth        = user.DateOfBirth,
                Email              = user.Email,
                EmailConfirmed     = user.EmailConfirmed,
                FirstName          = user.FirstName,
                LastName           = user.LastName,
                LockoutEnd         = user.LockoutEnd,
                PhoneNumber        = user.PhoneNumber,
                ProfilePicture     = user.ProfilePicture,
                ProfilePicturePath = user.ProfilePicturePath,
                UserName           = user.UserName,
            };

            return(View(app));
        }
        public JsonResult UpdateAppUserInformation(AppUserInformationModel appUserInformationModel)
        {
            Response <bool> response = new Response <bool>();

            appUserProvider = new AppUserProvider();

            AppUserModel appUserModel = SessionExtension.GetSessionUser(HttpContext.Session);

            if (appUserModel != null)
            {
                AppUserModel appUserTokenModel = SessionExtension.GetSessionUser(HttpContext.Session);

                appUserInformationModel.TokenKey = appUserModel.TokenKey;

                appUserInformationModel.AppUserId = appUserModel.AppUser.AppUserId;

                InfrastructureModel <bool> infrastructureModel = appUserProvider.Update(appUserInformationModel);

                response = new Response <bool>
                {
                    Data    = infrastructureModel.ResultStatus,
                    Message = "success",
                    Status  = infrastructureModel.ResultStatus,
                };
            }
            return(Json(response));
        }
Esempio n. 7
0
        public static AppUserModel GetSessionUser(this ISession session)
        {
            AppUserModel userModel = new AppUserModel();

            userModel = SessionExtension.Get <AppUserModel>(session, "Login");
            return(userModel);
        }
        public IViewComponentResult Invoke()
        {
            AppUserModel userModel = new AppUserModel();

            userModel = SessionExtension.Get <AppUserModel>(HttpContext.Session, "Login");
            return(View(userModel));
        }
Esempio n. 9
0
        public async Task <IActionResult> Settings()
        {
            HttpResponseMessage response = await ControllerHelperMethods.CallApi(HttpMethod.Get, "https://restcountries.eu/rest/v2/all", _httpClientFactory);

            if (response.IsSuccessStatusCode)
            {
                //Getting countrie from API and storing them in ViewBag to display them as select list in AppUserModel
                Country[] countries = await response.Content.ReadFromJsonAsync <Country[]>();

                ViewBag.Countries = new SelectList(countries, "Name", "Name", "Name");
            }
            else
            {
                //In case API call fails, notify the user
                ModelState.AddModelError("Country", "Problem with loading countries, please try again later.");
            }

            //Gets currently logged in user as AppUserModel type
            AppUserModel currentUser = await _appUserManager.GetUserAsync(User)
                                       .ContinueWith(u => u.Result.ToAppUserModelBaseInfo());

            //To pass necessary data for view
            ViewBag.CurrentUser = currentUser.ToAppUserEntity();
            return(View(currentUser));
        }
Esempio n. 10
0
        // service that returns an Appuser and the password quesiton if the password matches
        public IDictionary <string, object> GetAppMembership(string username, string password)
        {
            var member = membershipRepository.GetMembershipEntity(username);

            string storedPassword     = member.password;
            string storedPasswordSalt = member.passwordSalt;


            AppUserEntity appUserEntity = member.appuser;
            AppUserModel  appUserModel  = mapper.Map <AppUserModel>(appUserEntity);

            // if the user is found
            if (appUserEntity != null)
            {
                // hash the incoming password
                string inputPasswordHashed = Hashpassword(password, storedPasswordSalt);

                if (inputPasswordHashed.Equals(storedPassword.Trim()))
                {
                    Dictionary <string, Object> resultdict = new Dictionary <string, object>();
                    resultdict.Add("appUserModel", appUserModel);
                    resultdict.Add("passwordQuestion", member.passwordQuestion);
                    return(resultdict);
                }
            }
            return(null);
        }
 public IActionResult EstimationLogs([FromBody] AppUserModel model)
 {
     try
     {
         _log.LogInformation("{0} method of {1} started in Api at :\t{2}", "EstimationLogs", "EstimationLogsController", DateTime.UtcNow);
         var result = _service.Insert(model);
         if (result != null)
         {
             _log.LogInformation("{0} method of {1} is Successfull in Api at :\t{2}", "EstimationLogs", "EstimationLogsController", DateTime.UtcNow);
             return(Ok(result));
         }
         else
         {
             _log.LogInformation("{0} method of {1} is Un-Successfull in Api at :\t{2}", "EstimationLogs", "EstimationLogsController", DateTime.UtcNow);
             return(NotFound());
         }
     }
     catch (Exception e)
     {
         _log.LogError("{0} occurred in {1} method of {2} in Api at :\t{3}", e, "EstimationLogs", "EstimationLogsController", DateTime.UtcNow);
         throw e;
     }
     finally
     {
         _log.LogInformation("{0} method of {1} ended in Api at :\t{2}", "EstimationLogs", "EstimationLogsController", DateTime.UtcNow);
     }
 }
Esempio n. 12
0
        public async Task <IViewComponentResult> InvokeAsync(string id)
        {
            int          userId = Convert.ToInt32(id);
            AppUserModel user   = _context.AppUsers.Find(userId);

            return(View(user));
        }
Esempio n. 13
0
        //private RequestParamModel<MessageModel> GetRpm(FormCollection context)
        //{
        //    var json = context["json"];
        //    var rpm = new RequestParamModel<MessageModel>(context) { CurrentContext = context, Action = Request["action"] };
        //    if (!string.IsNullOrEmpty(json))
        //    {
        //        rpm = JSONhelper.ConvertToObject<RequestParamModel<MessageModel>>(json);
        //        rpm.CurrentContext = context;
        //    }

        //    return rpm;
        //}

        //public ActionResult Send()
        //{
        //    ViewBag.ToolBar = BuildToolbar();
        //    return View();
        //}

        //[HttpPost]
        //[ValidateInput(false)]
        //public string Send(FormCollection context)
        //{
        //    try
        //    {
        //        var ids = Request["ids"];
        //        var title = Request["title"];
        //        var content = Request["content"];
        //        if (string.IsNullOrEmpty(ids))
        //        {
        //            try
        //            {
        //                List<AppUserModel> list = AppUserDal.Instance.GetWhereStr(" and MASTER_ID IS NOT NULL").ToList();
        //                foreach (AppUserModel userModel in list)
        //                {
        //                    MessageModel messageModel = new MessageModel();
        //                    messageModel.RECEIVE_ID = 0;// PublicMethod.GetDecimal(id);
        //                                                // model.CONTENT = content;
        //                    messageModel.HTML_CONTENT = content;
        //                    messageModel.IS_RREAD = 0;
        //                    messageModel.SEND_TIME = DateTime.Now;
        //                    messageModel.TITLE = title;
        //                    messageModel.USER_ID = userModel.FID;
        //                    MessageDal.Instance.Insert(messageModel);
        //                }

        //                JPushClient client = new JPushClient(SysVisitor.Instance.PushAppKey, SysVisitor.Instance.PushMasterSecret);

        //                PushPayload pushPayload = new PushPayload();
        //                pushPayload.platform = Platform.all();
        //                pushPayload.audience = Audience.all();
        //                pushPayload.notification = new Notification().setAlert(title);

        //                client.SendPush(pushPayload);
        //            }
        //            catch (Exception ex)
        //            {
        //                LogHelper.WriteLog(string.Format("Error: appKey={0},masterSecret={1},phone={2},title={3},msg={4}", SysVisitor.Instance.PushAppKey, SysVisitor.Instance.PushMasterSecret, "全体", title, ex.Message));
        //            }
        //        }
        //        else
        //        {

        //            string[] array = ids.Split(',');
        //            foreach (string id in array)
        //            {
        //                MessageModel model = new MessageModel();
        //                model.RECEIVE_ID = 0;// PublicMethod.GetDecimal(id);
        //                                     // model.CONTENT = content;
        //                model.HTML_CONTENT = content;
        //                model.IS_RREAD = 0;
        //                model.SEND_TIME = DateTime.Now;
        //                model.TITLE = title;
        //                model.USER_ID = id;
        //                if (MessageDal.Instance.Insert(model) != "")
        //                {
        //                    OnPushMessage(id, title);
        //                }
        //            }
        //        }



        //        return JSONhelper.ToJson("发送成功!");
        //    }
        //    catch (Exception ex)
        //    {
        //        return JSONhelper.ToJson(ex.Message);
        //    }

        //}

        private void OnPushMessage(string id, string title)
        {
            //DriverModel model = DriverDal.Instance.GetByID(id);
            AppUserModel model = AppUserDal.Instance.Get(id);


            if (model != null)
            {
                try
                {
                    JPushClient client = new JPushClient(SysVisitor.Instance.PushAppKey, SysVisitor.Instance.PushMasterSecret);

                    PushPayload pushPayload = new PushPayload();
                    pushPayload.platform     = Platform.all();
                    pushPayload.audience     = Audience.s_alias(model.PHONE);
                    pushPayload.notification = new Notification().setAlert(title);

                    client.SendPush(pushPayload);
                }
                catch (Exception ex)
                {
                    LogHelper.WriteLog(string.Format("Error: appKey={0},masterSecret={1},phone={2},title={3},msg={4}", SysVisitor.Instance.PushAppKey, SysVisitor.Instance.PushMasterSecret, model.PHONE, title, ex.Message));
                }
            }
        }
Esempio n. 14
0
        public AppUserModel Insert(AppUserModel user)
        {
            try
            {
                var newUser = new AppUser();

                newUser.UserName = user.UserName;

                newUser.FirstName = user.FirstName;

                newUser.LastName = user.LastName;

                newUser.Email = user.Email;

                _userManager.CreateAsync(newUser, user.Password).Wait();

                foreach (var item in user.Claims)
                {
                    _userManager.AddClaimAsync(newUser, new Claim(item.ClaimName, item.ClaimValue)).Wait();
                }

                return(user);
            }
            catch
            {
                throw;
            }
        }
Esempio n. 15
0
        public IHttpActionResult PutAppUserModel(int id, AppUserModel appUserModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != appUserModel.ID)
            {
                return(BadRequest());
            }

            db.Entry(appUserModel).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AppUserModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 16
0
        public ActionResult UpdEngineer(string id, string assets)
        {
            string[]   s = assets.Split(new char[] { ';' });
            AssetModel asset;

            foreach (string ss in s)
            {
                asset = _context.BMEDAssets.Find(ss);
                if (asset != null)
                {
                    AppUserModel u = _context.AppUsers.Find(Convert.ToInt32(id));
                    if (u != null)
                    {
                        asset.AssetEngId            = u.Id;
                        asset.AssetEngName          = u.FullName;
                        _context.Entry(asset).State = EntityState.Modified;
                        _context.SaveChanges();
                    }
                }
            }
            return(new JsonResult(id)
            {
                Value = new { success = true, error = "" }
            });
        }
Esempio n. 17
0
        public List <AppUserModel> GetCropImage(List <AppUser> users, string userId)
        {
            List <AppUserModel> UserCropArray = new List <AppUserModel>();

            foreach (var item in users)//get crop for users
            {
                var temp = new AppUserModel();
                var crop = redisController.getItem(item.Id);
                if (crop != null && item.Id != userId)
                {
                    temp.Id       = item.Id;
                    temp.Image    = crop;
                    temp.Name     = item.Name;
                    temp.count    = _db.questionAndAnswers.Where(e => e.UserId == item.Id).Count();
                    temp.UserName = item.UserName;
                    UserCropArray.Add(temp);
                }
                else if (item.Id != userId)
                {
                    temp.Id       = item.Id;
                    temp.Image    = ImageToByteArray(Image.FromFile(@"C:\Users\Никита Дубовский\source\repos\WebApplication2\WebApplication2\noimage.jpg"));
                    temp.Name     = item.Name;
                    temp.UserName = item.UserName;
                    temp.count    = _db.questionAndAnswers.Where(e => e.UserId == item.Id).Count();
                    UserCropArray.Add(temp);
                }
            }

            return(UserCropArray);
        }
 public IActionResult AuthenticateUser([FromBody] AppUserModel userParam)
 {
     try
     {
         _log.LogInformation("{0} method of {1} started in Api at :\t{2}", "AuthenticateUser", "AuthenticateUserController", DateTime.UtcNow);
         if (!ModelState.IsValid)
         {
             return(BadRequest());
         }
         var result = _service.GetByCustom(userParam.LoginName + "#$#" + userParam.Password);
         if (result == null)
         {
             return(Unauthorized());
         }
         else
         {
             var user = CreateToken(result);
             return(Ok(user));
         }
     }
     catch (Exception e)
     {
         _log.LogError("{0} occurred in {1} method of {2} in Api at :\t{3}", e, "AuthenticateUser", "AuthenticateUserController", DateTime.UtcNow);
         throw e;
     }
     finally
     {
         _log.LogInformation("{0} method of {1} ended in Api at :\t{2}", "AuthenticateUser", "AuthenticateUserController", DateTime.UtcNow);
     }
 }
Esempio n. 19
0
        //POST : /api/AppUsers/Register
        public async Task <object> PostAppUser(AppUserModel model)
        {
            model.Role = "user";

            var appUser = new AppUser()
            {
                UserName    = model.UserName,
                Email       = model.Email,
                PhoneNumber = model.PhoneNumber,
                FullName    = model.FullName
            };

            try
            {
                var result = await _userManager.CreateAsync(appUser, model.Password);

                await _userManager.AddToRoleAsync(appUser, model.Role);

                return(Ok(result));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 20
0
        public JsonResult ChangePassword(AppUserLoginModel appUserLoginModel)
        {
            Response <bool> response = new Response <bool>();

            appUserProvider = new AppUserProvider();

            AppUserModel appUserModel = SessionExtension.GetSessionUser(HttpContext.Session);

            if (appUserModel != null)
            {
                AppUserModel appUserTokenModel = SessionExtension.GetSessionUser(HttpContext.Session);

                appUserLoginModel.TokenKey  = appUserModel.TokenKey;
                appUserLoginModel.AppUserId = appUserModel.AppUser.AppUserId;

                InfrastructureModel <bool> infrastructureModel = appUserProvider.ChangePassword(appUserLoginModel);

                response = new Response <bool>()
                {
                    Data    = infrastructureModel.ResultModel,
                    Message = infrastructureModel.Message,
                    Status  = true,
                    Refresh = true
                };
            }
            return(Json(response));
        }
Esempio n. 21
0
        public InfrastructureModel <bool> ResetAllInformationAppUser(AppUserModel appUserModel)
        {
            InfrastructureModel <bool> infrastructureModel = new InfrastructureModel <bool>();

            using (HttpClient client = new HttpClient())
            {
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", appUserModel.TokenKey);
                client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json charset=utf-8");
                client.DefaultRequestHeaders.Accept.Clear();

                var serializePostModel = JsonConvert.SerializeObject(appUserModel);

                StringContent       contentPost         = new StringContent(serializePostModel, Encoding.UTF8, "application/json");
                HttpResponseMessage httpResponceMessage = client.PostAsync(ConnectionHelper.GetConnectionUrl() + "AppUser/ResetAllInformationAppUser/", contentPost).Result;

                httpResponceMessage.EnsureSuccessStatusCode();

                string stringResponce = httpResponceMessage.Content.ReadAsStringAsync().Result;

                infrastructureModel = JsonConvert.DeserializeObject <InfrastructureModel <bool> >(stringResponce);

                if (!infrastructureModel.ResultModel)
                {
                    infrastructureModel.ResultStatus = true;
                }
                return(infrastructureModel);
            }
        }
Esempio n. 22
0
        public JsonResult GetJsonPost()
        {
            informationContentProvider = new InformationContentProvider();
            tokenProvider = new TokenProvider();
            string token = string.Empty;
            InfrastructureModel <InformationContentSingleDataModel> infrastructureModel = new InfrastructureModel <InformationContentSingleDataModel>();

            if (SessionExtension.GetSessionUser(HttpContext.Session) == null)
            {
                token = tokenProvider.GetAnonimToken();
                SessionExtension.Set(HttpContext.Session, "FreeToken", token);
                infrastructureModel = informationContentProvider.GetInformationContentSingleData(new InformationContentPostModel()
                {
                    TokenKey = token
                });
            }
            else
            {
                AppUserModel appUserModel = SessionExtension.GetSessionUser(HttpContext.Session);
                if (appUserModel != null)
                {
                    token = appUserModel.TokenKey;

                    infrastructureModel = informationContentProvider.GetInformationContentSingleData(new InformationContentPostModel()
                    {
                        AppUserId = appUserModel.AppUser.AppUserId, TokenKey = token
                    });
                }
            }
            return(Json(infrastructureModel));
        }
        public async Task <IActionResult> Create([Bind("Id,UserName,FullName,Password,Email,Ext,Mobile,DptId,VendorId,DateCreated,LastActivityDate,Status")] AppUserModel appUserModel)
        {
            if (ModelState.IsValid)
            {
                /* Check userName. */
                var nameIsExist = _context.AppUsers.Where(u => u.UserName == appUserModel.UserName).FirstOrDefault();
                if (nameIsExist != null)
                {
                    ModelState.AddModelError("UserName", "此ID已被使用");
                    return(View(appUserModel));
                }

                /* Create user to appUser table. */
                appUserModel.DateCreated = DateTime.Now;
                _context.Add(appUserModel);
                /* Create same data to externalUsers table. */
                ExternalUserModel externalUserModel = new ExternalUserModel()
                {
                    Id       = appUserModel.Id,
                    Password = appUserModel.Password,
                    UserName = appUserModel.UserName
                };
                _context.Add(externalUserModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(appUserModel));
        }
Esempio n. 24
0
        public IActionResult Register([FromBody] AppUserModel appUserModel)
        {
            if (!ModelState.IsValid)
            {
                var errors = ModelState.Values
                             .SelectMany(x => x.Errors)
                             .Select(x => x.ErrorMessage);

                return(BadRequest(errors));
            }

            if (ServiceFactory.AppUserService.GetBy(new { appUserModel.Email }) != null)
            {
                return(BadRequest("User already exists."));
            }

            appUserModel.UserName = appUserModel.Email;

            ServiceFactory.AppUserService.Create <Guid, AppUser>(ServiceFactory.Mapper.Map <AppUser>(appUserModel));

            var identity = ServiceFactory.AccountService.GetIdentity(appUserModel.UserName, appUserModel.Password);
            var response = ServiceFactory.AccountService.GenerateToken(identity);

            return(Json(response));
        }
Esempio n. 25
0
        public async Task <AppUser> Update([FromBody] AppUserModel app)
        {
            var entity = _appUserRepo.FindAll(x => x.Id == app.id).FirstOrDefault();

            entity.UserName     = app.UserName;
            entity.PasswordHash = app.PasswordHash;
            entity.FullName     = app.FullName;
            entity.Email        = app.Email;
            entity.PhoneNumber  = app.PhoneNumber;
            entity.Avatar       = app.Avatar;
            entity.DateCreated  = DateTime.Now;
            //_appUserRepo.Update(entity);
            await _userManager.UpdateAsync(entity);

            //Delete previous roles
            var rolesInDb = _dbContext.UserRole.Where(x => x.UserId == app.id);

            _dbContext.UserRole.RemoveRange(rolesInDb);

            //Update new roles
            foreach (var roleId in app.RoleIds)
            {
                _dbContext.UserRole.Add(new UserRole {
                    UserId = (Guid)app.id, RoleId = roleId
                });
            }

            SaveChanges();
            return(entity);
        }
Esempio n. 26
0
        // GET: Keep/Edit
        public IActionResult Edit(string id, int page)
        {
            AppUserModel ur = _context.AppUsers.Where(u => u.UserName == this.User.Identity.Name).FirstOrDefault();

            ViewData["Page"] = page;
            if (!string.IsNullOrEmpty(id))
            {
                KeepModel keep = _context.Keeps.Find(id);
                if (keep == null)
                {
                    return(StatusCode(404));
                }
                if (userManager.IsInRole(User, "Admin") || userManager.IsInRole(User, "RepAdmin") ||
                    userManager.IsInRole(User, "RepMgr") || userManager.IsInRole(User, "CaPMgr") ||
                    userManager.IsInRole(User, "RepEngineer"))
                {
                    return(View(keep));
                }
                KeepFlowModel rf = _context.KeepFlows.Where(f => f.DocId == id && f.Status == "?").FirstOrDefault();
                if (rf != null)
                {
                    if (rf.UserId != ur.Id)
                    {
                        return(RedirectToAction("Index", "Home", new { Area = "" }));
                    }
                }
                return(View(keep));
            }
            return(StatusCode(404));
        }
Esempio n. 27
0
 public bool Save(AppUserModel model)
 {
     try
     {
         AppUser tbl = new AppUser();
         tbl.Address      = model.Address;
         tbl.Avatar       = model.Avatar;
         tbl.BrithDay     = model.BrithDay;
         tbl.Email        = model.Email;
         tbl.FullName     = model.FullName;
         tbl.Gender       = model.Gender;
         tbl.PasswordHash = model.PasswordHash;
         tbl.UserName     = model.UserName;
         tbl.Status       = true;
         tbl.Ma_BP        = model.Ma_BP;
         tbl.Ma_CV        = model.Ma_CV;
         tbl.Ma_TO        = model.Ma_TO;
         db.AppUsers.Add(tbl);
         db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Esempio n. 28
0
        public string EditAppUser(AppUserModel u)
        {
            int    k;
            string msg = "用户编辑失败。";

            if (HasAppUserNo(u.PHONE, u.FID))
            {
                k   = -2;
                msg = "手机号码已存在。";
            }
            else
            {
                var oldAppUser = AppUserDal.Instance.Get(u.FID);
                k = AppUserDal.Instance.Update(u);
                if (k > 0)
                {
                    msg = "编辑APP用户成功。";
                    LogBll <AppUserModel> log = new LogBll <AppUserModel>();
                    log.AddLog(u);
                }
            }
            return(new JsonMessage {
                Data = k.ToString(), Message = msg, Success = k > 0
            }.ToString());
        }
Esempio n. 29
0
        // GET: BMED/Asset/Create
        public ActionResult Create()
        {
            List <SelectListItem> listItem = new List <SelectListItem>();

            _context.Departments.ToList().ForEach(d =>
            {
                listItem.Add(new SelectListItem {
                    Text = d.Name_C, Value = d.DptId
                });
            });
            ViewData["DelivDpt"] = new SelectList(listItem, "Value", "Text", "");

            List <SelectListItem> listItem2 = new List <SelectListItem>();

            listItem2.Add(new SelectListItem {
                Text = "", Value = ""
            });
            ViewData["DelivUid"] = new SelectList(listItem2, "Value", "Text", "");

            ViewData["AccDpt"] = new SelectList(listItem, "Value", "Text", "");

            List <SelectListItem> listItem3 = new List <SelectListItem>();

            listItem3.Add(new SelectListItem {
                Text = "正常", Value = "正常"
            });
            listItem3.Add(new SelectListItem {
                Text = "報廢", Value = "報廢"
            });
            ViewData["DisposeKind"] = new SelectList(listItem3, "Value", "Text", "");
            //
            List <SelectListItem> listItem4 = new List <SelectListItem>();

            _context.BMEDDeviceClassCodes.ToList()
            .ForEach(d =>
            {
                listItem4.Add(new SelectListItem {
                    Text = d.M_name, Value = d.M_code
                });
            });
            ViewData["BmedNo"] = new SelectList(listItem4, "Value", "Text", "");
            //
            // Get MedEngineers to set dropdownlist.
            var s = roleManager.GetUsersInRole("MedEngineer").ToList();
            List <SelectListItem> listItem5 = new List <SelectListItem>();

            foreach (string l in s)
            {
                AppUserModel u = _context.AppUsers.Where(ur => ur.UserName == l).FirstOrDefault();
                if (u != null)
                {
                    listItem5.Add(new SelectListItem {
                        Text = u.FullName, Value = u.Id.ToString()
                    });
                }
            }
            ViewData["AssetEngId"] = new SelectList(listItem5, "Value", "Text", "");

            return(View());
        }
Esempio n. 30
0
        //
        // GET: /Delivery/Edit/5
        public IActionResult Edit(string id = null)
        {
            DeliveryModel delivery = _context.Deliveries.Find(id);

            if (delivery == null)
            {
                return(NotFound());
            }
            DepartmentModel c = _context.Departments.Find(delivery.AccDpt);

            if (c != null)
            {
                delivery.AccDptNam = c.Name_C;
            }
            VendorModel v = _context.BMEDVendors.Where(vv => vv.UniteNo == delivery.VendorId).FirstOrDefault();

            if (v != null)
            {
                delivery.VendorNam = v.VendorName;
            }
            AppUserModel u = _context.AppUsers.Find(Convert.ToInt32(delivery.DelivPson));

            if (u != null)
            {
                delivery.DelivPsonNam = u.FullName;
            }
            BuyEvaluateModel b = _context.BuyEvaluates.Find(delivery.PurchaseNo);

            if (b != null)
            {
                delivery.BudgetId = b.BudgetId;
            }
            return(View(delivery));
        }
Esempio n. 31
0
        public async Task<AppUser> RegisterUserAsync(AppUserModel userModel)
        {
            AppUser newUser = null;
            AppUser user = new AppUser
            {
                UserName = userModel.UserName.Trim(),
                FirstName = userModel.FirstName.Trim(),
                LastName = userModel.LastName.Trim(),
                Email = userModel.UserName.Trim(),
                CreatedOn = DateTime.UtcNow,
                UpdatedOn = DateTime.UtcNow,
                PhoneNumber = userModel.PhoneNumber,
                StatusId = AppUser.eStatus.PendingActivation,
                TermsAcceptedOn = DateTime.UtcNow
            };

            var result = await this._identityManager.CreateAsync(user, userModel.Password);

            //add user to default role
            if (result.Succeeded)
            {
                //newUser = await this.FindUser(user.UserName, userModel.Password);

                //result = await this.AssignUserToRole(newUser.Id, Social123.AuthService.Plumbing.Constants.CustomerRole);

                //account.CreatedBy = new Guid(newUser.Id);
                //account.UpdatedBy = new Guid(newUser.Id);
                //subscription.CreatedBy = new Guid(newUser.Id);
                //subscription.UpdatedBy = new Guid(newUser.Id);

                //await this._adminCtx.SaveChangesAsync();
            }

            return newUser;
        }