Ejemplo n.º 1
0
        public AddMemberResponse Post(AddMemberRequest request)
        {
            /* 宣告指令的輸出結果 */
            var response = new AddMemberResponse();

            /* Step1 連接MongoDB伺服器 */
            MongoClient client = new MongoClient("mongodb://localhost:27017");

            /* Step2 取得MongoDB資料庫(Database)和集合(Collection) */
            /*   Step2-1 取得ntut資料庫(Database) */
            MongoDatabaseBase db = client.GetDatabase("ntut") as MongoDatabaseBase;
            /*   Step2-2 取得members集合(Collection) */
            var membersCollection = db.GetCollection <MembersCollection>("members");

            /* Step3 新增ㄧ筆會員資訊 */
            /*   Step3-1 設定查詢式 */
            var query = Builders <MembersCollection> .Filter.Eq(e => e.uid, request.uid);

            /*   Step3-2 進行查詢的操作,並取得會員資訊 */
            var doc = membersCollection.Find(query).ToListAsync().Result.FirstOrDefault();

            if (doc == null)
            {
                /* Step3-3-1 當資料庫中沒有該會員時,進行新增會員資訊的操作 */
                membersCollection.InsertOne(new MembersCollection()
                {
                    _id   = ObjectId.GenerateNewId(),
                    uid   = request.uid,
                    name  = request.name,
                    phone = request.phone
                });
            }
            else
            {
                /* Step3-3-2 當資料庫中存在該會員時,設定Response的ok欄位與errMsg欄位 */
                response.ok     = false;
                response.errMsg = "編號為" + request.uid + "的會員已存在,請重新輸入別組會員編號。";
            }

            return(response);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 新增會員
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public AddMemberResponse Post(AddMemberRequest request)
        {
            //輸出結果
            var response = new AddMemberResponse();
            // 連接MongoDB伺服器
            MongoClient client = new MongoClient("mongodb://localhost:27017");
            //取得資料庫(Database)和集合(collection)
            MongoDatabaseBase db = (MongoDatabaseBase)client.GetDatabase("ntut");
            //取得members集合(collection)
            var membersCollection = db.GetCollection <MembersCollection>("members");

            //查詢是否已存在資料
            var query = Builders <MembersCollection> .Filter.Eq(e => e.uid, request.uid);

            var doc = membersCollection.Find(query).ToListAsync().Result.FirstOrDefault();

            if (doc == null)
            {
                //新增資料
                membersCollection.InsertOne(
                    new MembersCollection()
                {
                    _id   = ObjectId.GenerateNewId(),
                    uid   = request.uid,
                    name  = request.name,
                    phone = request.phone
                });
            }
            else
            {
                response.ok     = false;
                response.errMsg = "編號:" + request.uid + "的會員已存在。";
            }


            return(response);
        }
Ejemplo n.º 3
0
 public ActionResult RemoveMember(AddMemberRequest request)
 {
     database.RemoveMember(request.Name);
     return(Ok());
 }
Ejemplo n.º 4
0
 public ActionResult AddMember(AddMemberRequest request)
 {
     database.AddMember(request);
     return(Ok());
 }
Ejemplo n.º 5
0
        public async Task <IActionResult> AddMember(AddMemberRequest request)
        {
            IEnumerable <MessageViewModel> data = await conversationService.AddMember(request);

            return(Ok(new ApiOkResponse(data)));
        }
Ejemplo n.º 6
0
        public AddMemberResponse Post(AddMemberRequest request)
        {
            var               response          = new AddMemberResponse();
            MongoClient       client            = new MongoClient("mongodb://localhost:27017");
            MongoDatabaseBase db                = client.GetDatabase("ntut") as MongoDatabaseBase;
            var               merberscontroller = db.GetCollection <MembersCollection>("members");
            var               uids              = request.members.Select(e => e.uid).ToList();
            var               query             = Builders <MembersCollection> .Filter.In(e => e.Uid, uids);

            var doc = merberscontroller.Find(query).ToList();

            #region 移除存在在資料庫的會員
            if (doc.Count > 0)
            {
                var existUIDList = doc.Select(e => e.Uid).ToList();
                request.members.RemoveAll(e => existUIDList.Contains(e.uid));
                response.ok = false;
                var existUid = string.Join(",", existUIDList);
                response.errMsg = "編號為" + existUid + "的會員存在,請重新輸入別組會員編號。";
                if (request.members.Count() > 0)
                {
                    var memebers = new List <MembersCollection>();
                    for (var i = 1; i < 100000; i++)
                    {
                        var memDoc = new MembersCollection()
                        {
                            _id = new ObjectId(),
                            Uid = i.ToString()
                        };
                        memebers.Add(memDoc);
                    }
                    merberscontroller.InsertMany(memebers);

                    var membersDocs = request.members.Select(e =>
                    {
                        return(new MembersCollection()
                        {
                            _id = new ObjectId(),
                            Uid = e.uid,
                            Phone = e.phone,
                            Name = e.name
                        });
                    }).ToList();
                    merberscontroller.InsertMany(membersDocs);
                }
            }
            #endregion
            else
            {
                var membersDocs = request.members.Select(e =>
                {
                    return(new MembersCollection()
                    {
                        _id = new ObjectId(),
                        Uid = e.uid,
                        Phone = e.phone,
                        Name = e.name
                    });
                }).ToList();
                merberscontroller.InsertMany(membersDocs);
            }

            return(response);
        }
Ejemplo n.º 7
0
        public async Task <BaseResponseDto <MemberDto> > AddMemberAsync([FromBody] AddMemberRequest addMemberRequest)
        {
            BaseResponseDto <MemberDto> response = await _mediator.Send(addMemberRequest);

            return(response);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Adapts an AddMemberRequest into a CommunityMember
 /// </summary>
 /// <param name="memberRequest">The AddMemberRequest to be adapted</param>
 /// <returns>CommunityMember</returns>
 public CommunityMember Adapt(AddMemberRequest memberRequest)
 {
     return(new CommunityMember(memberRequest.User, memberRequest.Group, memberRequest.Email, memberRequest.Company));
 }
Ejemplo n.º 9
0
 public override void AddMember(IRpcController controller, AddMemberRequest request, Action <NoData> done)
 {
     ProtoOutputBuffer.Write(request.GetType(), request.ToString());
 }
Ejemplo n.º 10
0
 public override void AddMember(IRpcController controller, AddMemberRequest request, Action<NoData> done)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 11
0
 public override void AddMember(IRpcController controller, AddMemberRequest request, Action <NoData> done)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 12
0
        public JsonResult AddMember(AddMemberRequest req)
        {
            var member = StaticSessionsDao.AddMember(req.ShortId, req.Name);

            return(Json(member));
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> Post([FromBody] AddMemberRequest request)
        {
            var result = await mediator.Send(request);

            return(CreatedAtAction("Get", new { id = result.Id }, result));
        }
Ejemplo n.º 14
0
        public async Task <ResponseBase> AddMemberToTeam(List <Employee> newEmployees, string teamId)


        {
            // Resnpose Data object intiialise
            var responseData = new ResponseData <IEnumerable <Team> >()
            {
                HasBeenSuccessful = false
            };

            // Create a new Add Member Request
            var addMemberReq = new AddMemberRequest();

            addMemberReq.NewMembers = newEmployees;
            addMemberReq.TeamId     = teamId;
            // Call the wrapper with the newly created add member request body
            var result = await this.apiWrapper.AddMemberToTeam(addMemberReq);

            // Content - the response we get from the back end
            string content = await result.Content.ReadAsStringAsync();

            // Compare the satus code we receive with the constant OK (201)
            if (result.StatusCode == HttpStatusCode.OK)
            {
                try
                {
                    // If OK, deserialise the content using the JSON Library to a Team Object
                    var deserializedContent = JsonConvert.DeserializeObject <ResponseData <IEnumerable <Team> > >(content);

                    // If deserialisation failed or it produced no content
                    if (!deserializedContent.HasBeenSuccessful || !deserializedContent.Content.Any())
                    {
                        // Create the Reponse Data with failed, no content, Error message
                        responseData.HasBeenSuccessful = false;

                        responseData.Error = "Internal Server Error";
                        return(responseData);
                    }
                    // If deserialisation succeeded, create reseonse dat with succeded, content received, no Error message
                    responseData.HasBeenSuccessful = true;

                    responseData.Error = null;
                    return(responseData);
                }
                catch (Exception e)
                {
                    // Catch a internal problem and print it
                    Console.WriteLine(e.StackTrace);
                    // Create the Reponse Data with failed, no content, Error message
                    responseData.HasBeenSuccessful = false;

                    responseData.Error = "Deserialization Error";
                    return(responseData);
                }
            }
            // If anything else goes wrong - Create the Reponse Data with failed, no content, Error message
            responseData.HasBeenSuccessful = false;

            responseData.Error = "Internal server Error";
            return(responseData);
        }
Ejemplo n.º 15
0
 public override void AddMember(Google.ProtocolBuffers.IRpcController controller, AddMemberRequest request, Action <bnet.protocol.NoData> done)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 16
0
 public override void AddMember(IRpcController controller, AddMemberRequest request, Action<NoData> done)
 {
     ProtoOutputBuffer.Write(request.GetType(), request.ToString());
 }
Ejemplo n.º 17
0
        public async Task <IActionResult> AddNewMember([FromBody] AddMemberRequest request)
        {
            await _memberService.Add(request, User.Identity.Name);

            return(Ok());
        }
Ejemplo n.º 18
0
		public override void AddMember(Google.ProtocolBuffers.IRpcController controller, AddMemberRequest request, Action<bnet.protocol.NoData> done) {
			throw new NotImplementedException();
		}