示例#1
0
        //Tested
        public UserInfo UpdateUserInfo(CustomUser user, UserInfoBindingModel newUserInfo)
        {
            var userInfo = this.context.UserInfos.FirstOrDefault(x => x.Id == user.UserInfoId);

            if (newUserInfo.FirstName != null)
            {
                userInfo.FirstName = newUserInfo.FirstName;
            }
            if (newUserInfo.LastName != null)
            {
                userInfo.LastName = newUserInfo.LastName;
            }
            if (newUserInfo.BirthDate != null)
            {
                userInfo.BirthDate = newUserInfo.BirthDate;
            }
            if (newUserInfo.AboutMe != null)
            {
                userInfo.AboutMe = newUserInfo.AboutMe;
            }
            if (newUserInfo.ProfilePictureUrl != null)
            {
                userInfo.ProfilePictureUrl = newUserInfo.ProfilePictureUrl;
            }
            if (newUserInfo.State != null)
            {
                userInfo.State = newUserInfo.State;
            }
            this.context.SaveChanges();

            return(userInfo);
        }
        public async Task <IHttpActionResult> UpdateUserInfo(UserInfoBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var userId = User.Identity.GetUserId();

            var user = db.Users.FirstOrDefault(u => u.Id == userId);

            user.Email     = model.Email;
            user.FirstName = model.FirstName;
            user.LastName  = model.LastName;

            var existingAddresses = db.Addresses.Where(a => a.PlaceId == model.PlaceId);

            if (existingAddresses.Any())
            {
                user.Address = existingAddresses.FirstOrDefault();
            }
            else
            {
                user.Address = new Address
                {
                    PlaceId = model.PlaceId
                }
            };

            await db.SaveChangesAsync();

            return(Ok());
        }
示例#3
0
        public IHttpActionResult UserMenu([FromBody] UserInfoBindingModel userInfoBindingModel)
        {
            try
            {
                // 织造产量录入APP
                var user = prdAppDb.peAppWvUsers.FirstOrDefault(a => a.code.Equals(userInfoBindingModel.code, StringComparison.CurrentCultureIgnoreCase) &&
                                                                a.password.Equals(userInfoBindingModel.password, StringComparison.CurrentCultureIgnoreCase));

                if (user != null)
                {
                    UserMenuViewModel model = GetUserMenuViewModelByCardNo(userInfoBindingModel.code);
                    if (model == null)
                    {
                        return(NotFound());
                    }
                    return(Json(model));
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        public async Task <ActionResult> PersonalInfo(UserInfoBindingModel model, HttpPostedFileBase fileUpload)
        {
            controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
            string strUrl = controllerName + ConstantDomain.UPDATE_USER;
            var    token  = _userSession.BearerToken;

            if (ModelState.IsValid)
            {
                try
                {
                    byte[]       image  = null;
                    MemoryStream target = new MemoryStream();
                    if (fileUpload != null)
                    {
                        fileUpload.InputStream.CopyTo(target);
                        image         = target.ToArray();
                        cacheUserData = cacheUserData == null?AccessCacheUserData() : cacheUserData;

                        cacheUserData.Image = FileManagement.ByteArrayToImageBase64(image);

                        model.Image = image;
                    }
                    var result = await APIProvider.Authorize_DynamicTransaction <UserInfoBindingModel, string>(model, token, strUrl, APIConstant.API_Resource_Authorize, ARS.IgnoredARS);

                    if (Response.StatusCode == 200)
                    {
                        TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.SUCCESS, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_UPDATE, ApplicationGenerator.TypeResult.SUCCESS));
                    }
                    else
                    {
                        TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.FAIL, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_UPDATE, ApplicationGenerator.TypeResult.FAIL));
                    }
                    return(RedirectToAction("Overview"));
                }
                catch (Exception ex)
                {
                    Logger.LogError(ex);
                    TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.ERROR, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_UPDATE, ApplicationGenerator.TypeResult.ERROR));
                    throw ex;
                }
            }
            else
            {
                StringBuilder errorBuilder = new StringBuilder();
                foreach (var modelError in ModelState)
                {
                    if (modelError.Value.Errors.Count > 0)
                    {
                        errorBuilder.AppendLine(modelError.Value.Errors[0].ErrorMessage.ToString());
                    }
                }

                TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.FAIL, errorBuilder.ToString());
                return(View(model));
            }
        }
示例#5
0
 public IActionResult ProfileSetUp(UserInfoBindingModel bindingModel)
 {
     if (ModelState.IsValid)
     {
         var user   = userManager.FindByNameAsync(User.Identity.Name).Result;
         var result = userService.UpdateUserInfo(user, bindingModel);
         userService.FinishSetUp(user.Id);
         return(RedirectToAction(Actions.Index, Paths.Home));
     }
     return(View(bindingModel));
 }
示例#6
0
        public IHttpActionResult FindUsers(
            [FromUri] UserInfoBindingModel searchUser,
            [FromUri(Name = "p")] int page)
        {
            var allUsers = UnitOfWork.UserRepository.FindUsers(searchUser, UsersPerPage, page);
            //use this method for efficient search and marking online users
            var users     = OnlineWorker.MarkIfOnline(allUsers);
            var pageCount = UnitOfWork.UserRepository.FindUsersPageCount(searchUser, UsersPerPage);
            Pair <UserReturnModel[], int> data = Pair.Make(users, pageCount);

            return(Ok(data));
        }
示例#7
0
        public IHttpActionResult UpdateProfile(UserInfoBindingModel userInfo)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = _userService.GetById(User.Identity.GetUserId());

            Mapper.Map <UserInfoBindingModel, User>(userInfo, user);

            _userService.UpdateUser(user);

            return(Ok());
        }
示例#8
0
        public async Task <IHttpActionResult> UpdateUserInfo(UserInfoBindingModel model)
        {
            if (ModelState.IsValid)
            {
                var userId = User.Identity.GetUserId <int>();
                var user   = DbContext.Users.Find(userId);
                Mapper.Map(model, user);

                await DbContext.SaveChangesAsync();

                return(Ok());
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
        public async Task <ActionResult> Overview()
        {
            var model    = new InternalProfileBindingModel();
            var userInfo = new UserInfoBindingModel();

            try
            {
                var token = _userSession.BearerToken;

                //UserInfo
                controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
                var userId = _userSession.UserId;

                string strUrl = controllerName + "/GetInfoEdit?userId=" + userId;
                userInfo = await APIProvider.Authorize_Get <UserInfoBindingModel>(token, strUrl, APIConstant.API_Resource_Authorize, ARS.IgnoredARS);

                userInfo.Id = userId;

                //Doctor Profile
                var departmentController = "Department";
                strUrl = "Doctor/" + userId;
                var doctorProfile = await APIProvider.Authorize_Get <DoctorProfileViewModel>(_userSession.BearerToken, strUrl, APIConstant.API_Resource_CORE, ARS.Get);

                var departmentName = string.Empty;

                if (doctorProfile.DepartmentId > 0)
                {
                    var Department = await APIProvider.Authorize_Get <DepartmentViewModel>(_userSession.BearerToken, departmentController + "/" + doctorProfile.DepartmentId, APIConstant.API_Resource_CORE, ARS.IgnoredARS);

                    departmentName = Department.Name;
                }
                ViewBag.DepartmentName = departmentName;

                model.DoctorInfo = doctorProfile;
                model.UserInfo   = userInfo;

                return(View(model));
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
                throw ex;
            }
        }
        public async Task <ActionResult> Edit(Guid id)
        {
            var model = new UserInfoBindingModel();

            try
            {
                var token = _userSession.BearerToken;
                controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();

                var listRole = await APIProvider.Authorize_Get <List <RoleViewModel> >(token, ConstantDomain.GET_ROLE, APIConstant.API_Resource_Authorize, ARS.IgnoredARS);

                if (listRole != null)
                {
                    ViewBag.Role = listRole;
                }
                else
                {
                    ViewBag.Role = new List <RoleViewModel>();
                }

                //Call API Provider
                string strUrl = controllerName + "/GetInfoEdit?userId=" + id;
                model = await APIProvider.Authorize_Get <UserInfoBindingModel>(token, strUrl, APIConstant.API_Resource_Authorize, ARS.Edit);

                if (model != null)
                {
                    ViewBag.ListRole = model.RoleName;
                    return(View(model));
                }
                else
                {
                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
                throw ex;
            }
        }
        public async Task <ActionResult> PersonalInfo()
        {
            var model = new UserInfoBindingModel();

            try
            {
                var token  = _userSession.BearerToken;
                var userId = _userSession.UserId;

                string strUrl = controllerName + "/GetInfoEdit?userId=" + userId;
                model = await APIProvider.Authorize_Get <UserInfoBindingModel>(token, strUrl, APIConstant.API_Resource_Authorize, ARS.Edit);

                model.Id = userId;

                return(View(model));
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
                throw ex;
            }
        }
示例#12
0
        public async Task <ActionResult> PersonalInfo()
        {
            var model = new UserInfoBindingModel();

            try
            {
                var token = _userSession.BearerToken;
                controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
                var id = _userSession.UserId;

                string strUrl = controllerName + "/GetInfoEdit?userId=" + id;
                model = await APIProvider.Authorize_Get <UserInfoBindingModel>(token, strUrl, APIConstant.API_Resource_Authorize, ARS.IgnoredARS);

                model.Id = id;

                return(View(model));
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
                throw ex;
            }
        }
        public async Task <IHttpActionResult> Update(UserInfoBindingModel model)
        {
            if (!User.IsInRole("Admin") && !(User.Identity.GetUserName() == model.Email))
            {
                return(StatusCode(HttpStatusCode.Forbidden));
            }

            IdentityResult result = new IdentityResult();

            var userManager = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>();
            var user        = await userManager.FindByEmailAsync(model.Email);

            if (user == null)
            {
                return(NotFound());
            }

            try
            {
                var mapedUser = _mapper.Map(model, user);
                result = await userManager.UpdateAsync(mapedUser);
            }
            catch (Exception e)
            {
                _logger.Error(e);
                return(InternalServerError());
            }

            if (!result.Succeeded)
            {
                return(InternalServerError());
            }
            else
            {
                return(Ok(model));
            }
        }
示例#14
0
 public IHttpActionResult EditUserInfo(UserInfoBindingModel model)
 {
     _userService.ApdateInfoAboutUser(model.Id, model.FirstName, model.LastName, model.Email, model.Password, model.IsActivated, model.Phone, model.Sex, model.Country, model.City, model.Street, model.Apartment);
     return(Ok());
 }