コード例 #1
0
        public bool UpdateUser(User user)
        {
            var userDto = new UserDto();

            userDto = convert.ToUserDto(user);
            var model = new bool();

            using (var client = new UserService.UserServiceClient())
            {
                try
                {
                    client.Open();
                    model = client.UpdateUser(userDto);
                    client.Close();
                }

                catch (FaultException <CustomException> customEx)
                {
                    log.Error(customEx.Message);
                    return(false);
                }
                catch (CommunicationException commEx)
                {
                    log.Error(commEx.Message);
                    return(false);
                }
            }
            return(model);
        }
コード例 #2
0
        public bool DeleteUser(int userId)
        {
            var model = new bool();

            using (var client = new UserService.UserServiceClient())
            {
                try
                {
                    client.Open();
                    model = client.DeleteUser(userId);
                    client.Close();
                }

                catch (FaultException <CustomException> customEx)
                {
                    log.Error(customEx.Message);
                    return(false);
                }
                catch (CommunicationException commEx)
                {
                    log.Error(commEx.Message);
                    return(false);
                }
            }
            return(model);
        }
コード例 #3
0
        protected void DeleteStudent_Click(object sender, EventArgs e)
        {
            UserService.IUserService client = new UserService.UserServiceClient();

            client.DeleteUser(Convert.ToInt32(TextBox8.Text));
            Label1.Text = "Student deleted successfully";
        }
コード例 #4
0
 public ActionResult UpdateUser(UserViewModel model, HttpPostedFileBase file)
 {
     if (ModelState.IsValid)
     {
         if (file != null && file.ContentLength > 0)
         {
             CommonController common = new CommonController();
             model.User.photo = Path.GetFileName(file.FileName);
             string filePath = Path.Combine(Server.MapPath(ConfigurationManager.AppSettings["FilePath"].ToString()), Path.GetFileName(file.FileName));
             string message  = common.UploadFile(file, filePath);
             ModelState.AddModelError("User.Photo", message);
         }
         UserService.UserServiceClient Client = new UserService.UserServiceClient();
         model.User.IsActive = true;
         Client.updateUser(model.User);
         Client.UpdateUserGroupMember(model.User.UserId);
         Client.insertUserGroupmember(model.User.UserId, model.UserGroupID);
         Client.UpdateUserRole(model.User.UserId);
         Client.insertUserRole(model.User.UserId, model.RoleID);
         return(View("ListofUsers"));
     }
     else
     {
         ModelState.AddModelError("", ConfigurationManager.AppSettings["Requried"]);
     }
     return(View("ListofUsers"));
 }
コード例 #5
0
        //
        public ActionResult ListofUsers()
        {
            UserService.UserServiceClient client = new UserService.UserServiceClient();
            string  xmldata = client.getAllUser(Convert.ToInt32(Session["GroupCompanyId"]));
            DataSet ds      = new DataSet();

            ds.ReadXml(new StringReader(xmldata));
            List <User> userlist = new List <User>();

            if (ds.Tables.Count > 0)
            {
                foreach (System.Data.DataRow row in ds.Tables[0].Rows)
                {
                    userlist.Add(new User {
                        UserId        = Convert.ToInt32(row["User_ID"]),
                        FirstName     = Convert.ToString(row["First_Name"]),
                        MiddleName    = Convert.ToString(row["Middle_Name"]),
                        Gender        = Convert.ToString(row["Gender"]),
                        ContactNumber = Convert.ToString(row["Contact_Number"]),
                        LastLogin     = Convert.ToDateTime(row["Last_Login"]),
                        IsActive      = Convert.ToBoolean(Convert.ToInt32(row["Is_Active"])),
                        LastName      = Convert.ToString(row["Last_Name"]),
                        EmailId       = Convert.ToString(row["Email_ID"]),
                        photo         = Convert.ToString(row["Photo"])
                    });
                }
            }
            return(View("_ListofUsers", userlist));
        }
コード例 #6
0
        public async Task <UserDto> CreateAsync(CreateUserDto dto)
        {
            AppContext.SetSwitch(
                "System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
            using var channel = GrpcChannel.ForAddress(_configuration["UserGrpc"]);
            var client = new UserService.UserServiceClient(channel);
            var user   = await client.CreateAsync(new UserCreateRequest
            {
                Email        = "",
                Username     = dto.NationalCode,
                FirstName    = dto.Firstname,
                LastName     = dto.LastName,
                NationalCode = dto.NationalCode,
                PhoneNumber  = ""
            });

            if (!user.Success)
            {
                throw new BadRequestException($"Error occured while creating user: {user.ErrorDescription}");
            }
            return(new UserDto
            {
                Id = user.Id,
                Firstname = user.FirstName,
                LastName = user.LastName,
                NationalCode = user.NationalCode
            });
        }
コード例 #7
0
        public UserDto ExistsUser(string login, string password)
        {
            var model = new UserDto();

            using (var client = new UserService.UserServiceClient())
            {
                try
                {
                    client.Open();
                    model = client.ExistsUser(login, password);
                    client.Close();
                    if (model == null)
                    {
                        throw new NullReferenceException();
                    }
                }

                catch (FaultException <CustomException> customEx)
                {
                    log.Error(customEx.Message);
                    return(null);
                }
                catch (CommunicationException commEx)
                {
                    log.Error(commEx.Message);
                    return(null);
                }
                catch (NullReferenceException nullEx)
                {
                    log.Error(nullEx.Message);
                    return(null);
                }
            }
            return(model);
        }
コード例 #8
0
        public async Task <UserDto> UpdateAsync(string id, CreateUserDto dto)
        {
            AppContext.SetSwitch(
                "System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
            using var channel = GrpcChannel.ForAddress(_configuration["UserGrpc"]);
            var client = new UserService.UserServiceClient(channel);

            var result = await client.UpdateAsync(new UserUpdateRequest
            {
                Id           = id,
                FirstName    = dto.Firstname,
                LastName     = dto.LastName,
                NationalCode = dto.NationalCode
            });

            if (!result.Success)
            {
                throw new BadRequestException($"Error occured while updating user: {result.ErrorDescription}");
            }

            return(new UserDto
            {
                Firstname = result.FirstName,
                Id = result.Id,
                LastName = result.LastName,
                NationalCode = result.NationalCode
            });
        }
コード例 #9
0
        public ActionResult Updateusergroup(int groupid)
        {
            UserService.UserServiceClient Client = new UserService.UserServiceClient();
            UserGroupViewModel            model  = new UserGroupViewModel();
            DataSet ds      = new DataSet();
            string  xmldata = Client.GetUserGroup(groupid);

            ds.ReadXml(new StringReader(xmldata));
            model.Group = new UserGroup();
            model.Group.UserGroupName        = Convert.ToString(ds.Tables[0].Rows[0]["User_Group_Name"]);
            model.Group.UserGroupDescription = Convert.ToString(ds.Tables[0].Rows[0]["User_Group_Description"]);
            model.Group.UserRoleId           = Convert.ToInt32(ds.Tables[0].Rows[0]["Role_ID"]);
            xmldata = Client.GetRoles(1);
            DataSet dsrole = new DataSet();

            dsrole.ReadXml(new StringReader(xmldata));
            model.Roles = new List <SelectListItem>();
            if (dsrole.Tables.Count > 0)
            {
                foreach (System.Data.DataRow row in ds.Tables[0].Rows)
                {
                    model.Roles.Add(new SelectListItem {
                        Text = row["Role_Name"].ToString(), Value = row["Role_ID"].ToString()
                    });
                }
            }
            return(View("_AddUserGroup", model));
        }
コード例 #10
0
        public ActionResult MenuItems()
        {
            List <Menus> menues = new List <Menus>();

            //menues.Add(new Menus { MenuName = "Manage Company", PathUrl = "/Home/Contact", icon = "about_icon.png",ParentMenuId=0,Id=2 });
            //menues.Add(new Menus { MenuName = "Acts & Rules", PathUrl = "", icon = "product_icon.png",ParentMenuId=0,Id=3 });
            //menues.Add(new Menus { MenuName = "Auditing", PathUrl = "", icon = "settings_icon.png",ParentMenuId=0,Id=4 });


            UserService.UserServiceClient client = new UserService.UserServiceClient();
            DataSet ds      = new DataSet();
            string  xmlmenu = client.getmenulist(Convert.ToInt32(Session["UserId"]), 0);

            ds.ReadXml(new StringReader(xmlmenu));
            if (ds.Tables.Count > 0)
            {
                foreach (System.Data.DataRow row in ds.Tables[0].Rows)
                {
                    menues.Add(new Menus {
                        Id = Convert.ToInt32(row["Menu_ID"]), MenuName = Convert.ToString(row["Menu_Name"]), PathUrl = Convert.ToString(row["Page_URL"]), icon = Convert.ToString(row["icon"]), ParentMenuId = Convert.ToInt32(row["Parent_MenuID"])
                    });
                }
            }
            return(PartialView("~/Views/Shared/_Menu.cshtml", menues));
        }
コード例 #11
0
        public UsersController(IConfiguration configuration)
        {
            var address = configuration["UsersHost"];
            var channel = new Channel(address, ChannelCredentials.Insecure);

            _client = new UserService.UserServiceClient(channel);
        }
コード例 #12
0
ファイル: Program.cs プロジェクト: bks1000/gRPCTest
        static void Main(string[] args)
        {
            var channel = GrpcChannel.ForAddress("https://localhost:5001");

            //mysql
            var client = new UserService.UserServiceClient(channel);
            var reply  = client.GetAllUser(new ReqsNull {
            });

            Console.WriteLine(reply.Users.Count);
            Console.WriteLine(reply.Users[reply.Users.Count - 1].Name);

            //oracle
            var c2 = new XmkProjUnitService.XmkProjUnitServiceClient(channel);
            //oracle ado.net
            var r2 = c2.QueryProjUnit(new QueryProjUnitRequest {
                ProCode = "101-0401-YSN-BLFR"
            });

            Console.WriteLine(r2.ItemId);

            //oracle entity framework
            var r3 = c2.QueryProjUnitAll(new Nvl {
            });

            Console.WriteLine(r3.Data_);

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
コード例 #13
0
ファイル: Program.cs プロジェクト: BuiltCloud/Built
        public override Task <ProductGetResponse> Create(ProductCreateRequest request, ServerCallContext context)
        {
            if (store.ContainsKey(request.ProductId))
            {
                return(Task.FromResult(default(ProductGetResponse)));
            }

            Channel           channel     = new Channel("127.0.0.1:50051", ChannelCredentials.Insecure);
            ClientCallInvoker callInvoker = new ClientCallInvoker(channel);
            var userClient = new UserService.UserServiceClient(callInvoker);

            var product = store[request.UserId];

            product.ProductId   = request.ProductId;
            product.ProductName = request.ProductName;
            product.User        = userClient.Get(new UserGetRequest
            {
                UserId = request.UserId
            });
            userClient.Update(new UserGetResponse
            {
                UserId       = product.User.UserId,
                UserName     = product.User.UserName,
                ProductCount = product.User.ProductCount + 1
            });
            //关闭
            channel.ShutdownAsync().Wait();
            return(Task.FromResult(product));
        }
コード例 #14
0
 public UserController() :
     base("ServicesUrl\\UserService")
 {
     //BaseService.CheckChannelStatus(Channel);
     Client       = new UserService.UserServiceClient(Channel);
     FactorClient = new TwoFactorService.TwoFactorServiceClient(Channel);
     MsgService   = new TiantianMsg(Client);
 }
コード例 #15
0
        public TwoFactorController() :
            base("ServicesUrl\\UserService")
        {
            Client = new TwoFactorService.TwoFactorServiceClient(Channel);
            var userClient = new UserService.UserServiceClient(Channel);

            MsgService = new TiantianMsg(userClient);
        }
コード例 #16
0
        public UserController()
        {
            var host = AppSettingsHelper.Instance.GetValueFromKey(MessageConst.TestHostNameKey);
            var port = AppSettingsHelper.Instance.GetValueFromKey(MessageConst.TestPortKey);

            var channel = new Channel($"{host}:{port}", ChannelCredentials.Insecure);

            _serviceClient = new UserService.UserServiceClient(channel);
        }
コード例 #17
0
        // GET: Home
        public ActionResult Index()
        {
            var client = new UserService.UserServiceClient();
            var getuer = client.GetUser(new ParamForGetUser()
            {
                UserId = "2"
            });

            return(View());
        }
コード例 #18
0
ファイル: ServerConnector.cs プロジェクト: Kajti/BoardGames
        private UserService.UserServiceClient UserClientCreate()
        {
            if (this.userClient == null)
            {
                var channel = new Channel($"{this.Host}:{this.PortUser}", ChannelCredentials.Insecure);
                this.userClient = new UserService.UserServiceClient(channel);
            }

            return(this.userClient);
        }
コード例 #19
0
        public async Task <IActionResult> GetOrderInfo()
        {
            using var channel = GrpcChannel.ForAddress("https://localhost:5002");

            var client = new UserService.UserServiceClient(channel);

            var user = await client.GetUserInfoAsync(new GetUserInfoRequest { Id = 10 });

            return(Ok(user));
        }
コード例 #20
0
        /// <summary>
        /// Obtient le hearbeat.
        /// </summary>
        /// <returns>True si le heartbeat est valide.</returns>
        public bool GetHeartBeat()
        {
            if (UserToken == null)
                return false;

            using (UserService.UserServiceClient svcClient = new UserService.UserServiceClient())
            {
                return svcClient.Heartbeat(UserToken.Value);
            }
        }
コード例 #21
0
        /// <summary>
        /// Obtient le hearbeat.
        /// </summary>
        /// <returns>True si le heartbeat est valide.</returns>
        public bool GetHeartBeat()
        {
            if (UserToken == null)
            {
                return(false);
            }

            using (UserService.UserServiceClient svcClient = new UserService.UserServiceClient())
            {
                return(svcClient.Heartbeat(UserToken.Value));
            }
        }
コード例 #22
0
        public ActionResult AddUser(UserViewModel model, HttpPostedFileBase file)
        {
            UserService.UserServiceClient Client = new UserService.UserServiceClient();
            model.User.Company_Id = Convert.ToInt32(Session["GroupCompanyId"]);
            if (ModelState.IsValid)
            {
                if (file != null && file.ContentLength > 0)
                {
                    CommonController common = new CommonController();
                    model.User.photo = Path.GetFileName(file.FileName);
                    string filePath = Path.Combine(Server.MapPath(ConfigurationManager.AppSettings["FilePath"].ToString()), Path.GetFileName(file.FileName));
                    string message  = common.UploadFile(file, filePath);
                    //ModelState.AddModelError("User.Photo", message);
                }
                string res = Client.insertUser(model.User);
                if (res != "EXISTS")
                {
                    model.User.UserId = Convert.ToInt32(res);
                    Client.insertUserGroupmember(model.User.UserId, model.UserGroupID);
                    //Client.insertUserRole(model.User.UserId, model.RoleID);
                    TempData["Message"] = "Successfully created" + model.User.FirstName;
                    return(RedirectToAction("ListofUsers"));
                }
                else
                {
                    ModelState.AddModelError("User.EmailId", "UserName is already Exists");
                }
            }
            else
            {
                ModelState.AddModelError("", ConfigurationManager.AppSettings["Requried"]);
            }
            model.User.UserId   = 0;
            model.UserGroupList = (List <SelectListItem>)TempData["UserGroup"];
            //string xmlGroups = Client.GetUserGroup(0);
            //DataSet Groups = new DataSet();
            //Groups.ReadXml(new StringReader(xmlGroups));
            //model.UserGroupList = new List<SelectListItem>();
            //foreach (System.Data.DataRow row in Groups.Tables[0].Rows)
            //{
            //    model.UserGroupList.Add(new SelectListItem { Text = row["User_Group_Name"].ToString(), Value = row["User_Group_ID"].ToString() });
            //}
            //string xmlRoles = Client.GetRoles(0);
            //DataSet dsRoles = new DataSet();
            //dsRoles.ReadXml(new StringReader(xmlRoles));
            //model.RolesList = new List<SelectListItem>();
            //foreach (System.Data.DataRow row in dsRoles.Tables[0].Rows)
            //{
            //    model.RolesList.Add(new SelectListItem { Text = row["Role_Name"].ToString(), Value = row["Role_ID"].ToString() });
            //}

            return(View("_AddUser", model));
        }
コード例 #23
0
        public UserController()
        {
            var tracer = GlobalTracer.Instance;
            ClientTracingInterceptor tracingInterceptor = new ClientTracingInterceptor(tracer);

            var host = AppSettingsHelper.Instance.GetValueFromKey(HostNameConst.TestKey);
            var port = AppSettingsHelper.Instance.GetValueFromKey(PortConst.TestKey);

            var channel = new Channel($"{host}:{port}", ChannelCredentials.Insecure);

            _serviceClient = new UserService.UserServiceClient(channel.Intercept(tracingInterceptor));
        }
コード例 #24
0
        private static async void GetUsers(List <Guid> userIds)
        {
            var client  = new UserService.UserServiceClient(channel);
            var request = new GetUsersRequest()
            {
                UserIds = userIds
            };

            var response = await client.GetUsersAsync(request);

            var result = response.Payload.Deserialize();
        }
コード例 #25
0
        public Need4Service()
        {
            string serverAddress = "https://localhost:50051";

            channel          = GrpcChannel.ForAddress(serverAddress);
            itemClient       = new ItemRepository.ItemRepositoryClient(channel);
            tradeClient      = new TradeService.TradeServiceClient(channel);
            saleClient       = new SaleService.SaleServiceClient(channel);
            userClient       = new UserService.UserServiceClient(channel);
            permissionClient = new PermissionService.PermissionServiceClient(channel);
            activityClient   = new ActivityService.ActivityServiceClient(channel);
            communityClient  = new CommunityService.CommunityServiceClient(channel);
        }
コード例 #26
0
        protected void Page_Load(object sender, EventArgs e)
        {
            UserService.UserServiceClient userServiceClient = new UserService.UserServiceClient();
            string login = string.Empty;

            login = userServiceClient.Login("admin", "admin");
            Response.Write(login);
            if (login.Contains("false"))
            {
                return;
            }

            List<String> ls=new List<string>();
            ls.Add("h");
            ls.Add("y");

            List<JsonTest> list = new List<JsonTest>();
            list.Add(new JsonTest() { Name = "hy", Valuse = ls });
            list.Add(new JsonTest() { Name = "hy", Valuse = ls });
            list.Add(new JsonTest() { Name = "hy", Valuse = ls });

            //UserView loginUser = null;
            //try
            //{
            //    loginUser = JsonHelper.DeserializeObject<UserView>(login);
            //}
            //catch (Exception ex)
            //{ }

            //if (loginUser == null)
            //{
            //    Response.Write("jsonConvert error!");
            //    return;
            //}

            //string roles = userServiceClient.GetRoles();
            //Response.Write(JsonHelper.DeserializeObject<List<RoleView>>(roles).ToString());

            //string register = userServiceClient.Register(JsonConvert.SerializeObject(loginUser), JsonConvert.SerializeObject(
            //    new UserView() {
            //        Id="000",
            //        Duty="技术员",
            //        RoleId = "RegisterUser",
            //        Email="*****@*****.**",
            //        Password="******",
            //        Name="hy",
            //        RoleName="注册用户"
            //    }
            //    ));
            //Response.Write(JsonConvert.DeserializeObject(register));
        }
コード例 #27
0
 public ActionResult Updateusergroup(UserGroupViewModel model)
 {
     if (ModelState.IsValid)
     {
         UserService.UserServiceClient Client = new UserService.UserServiceClient();
         Client.updateGroups(model.Group);
         return(View("ListofUsergroup"));
     }
     else
     {
         ModelState.AddModelError("", ConfigurationManager.AppSettings["Requried"]);
     }
     return(View("_AddUserGroup", model));
 }
コード例 #28
0
        public ActionResult DeleteUser(int UserId)
        {
            UserService.UserServiceClient client = new UserService.UserServiceClient();
            bool res = client.DeleteUser(UserId);

            if (res)
            {
                return(View("CreateUser"));
            }
            else
            {
                return(RedirectToAction("ListofUsers"));
            }
        }
コード例 #29
0
        protected void Button4_Click(object sender, EventArgs e)
        {
            UserService.IUserService client = new UserService.UserServiceClient();
            UserService.UserInfo     user   = new UserService.UserInfo();
            user.Type   = UserService.UserType.Student;
            user.Std    = Convert.ToInt32(Std.Text);
            user.ID     = Convert.ToInt32(Id.Text);
            user.Name   = Name.Text;
            user.Gender = Gender.Text;
            user.DOB    = Convert.ToDateTime(DOB.Text);

            client.SaveUser(user);
            Label1.Text = "Students saved successfully!!";
        }
コード例 #30
0
        public async Task <UserDto> GetAsync(string id)
        {
            AppContext.SetSwitch(
                "System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
            using var channel = GrpcChannel.ForAddress(_configuration["UserGrpc"]);
            var client = new UserService.UserServiceClient(channel);
            var user   = await client.GetAsync(new UserInformationRequest { UserId = id });

            return(new UserDto
            {
                Firstname = user.FirstName,
                LastName = user.LastName,
                NationalCode = user.NationalCode
            });
        }
コード例 #31
0
 public ActionResult updateRoles(RolesViewModel model)
 {
     if (ModelState.IsValid)
     {
         UserService.UserServiceClient client = new UserService.UserServiceClient();
         client.updateRoles(model.roles);
         client.DeleteRolePrivilege(model.roles.RoleId);
         client.insertRolePrivilege(model.roles.RoleId, model.PrivilegeId);
         return(View("_AddRole", model));
     }
     else
     {
         ModelState.AddModelError("", ConfigurationManager.AppSettings["Requried"]);
     }
     return(View("_AddRole", model));
 }
コード例 #32
0
 public ActionResult AddRoles(RolesViewModel rolesView)
 {
     if (ModelState.IsValid)
     {
         UserService.UserServiceClient client = new UserService.UserServiceClient();
         int roleid = client.insertRoles(rolesView.roles);
         client.insertRolePrivilege(roleid, rolesView.PrivilegeId);
         TempData["Message"] = "Created " + rolesView.roles.RoleName + " Succesfully.";
         return(RedirectToAction("AddRoles"));
     }
     else
     {
         ModelState.AddModelError("", ConfigurationManager.AppSettings["Requried"]);
     }
     return(View("_AddRole", rolesView));
 }
コード例 #33
0
 public void TestMethod1()
 {
     UserService.IUserService userServiceClient = new UserService.UserServiceClient();
     //var user = new UserService.UserDto()
     //{
     //    UserName = "******",
     //    NickName = "坏坏男孩",
     //    RealName = "吴丹",
     //    PhoneNo = "18916765826",
     //    Email = "*****@*****.**",
     //    PassWord = "******",
     //    RegisterTime = DateTime.Now,
     //    LastLogonTime = DateTime.Now
     //};
     //var result = userServiceClient.CreateUser(user);
     var users = userServiceClient.QueryAll();
 }