Ejemplo n.º 1
0
        public async Task GetBranch()
        {
            var options = TestHelper.GetDbContext("GetBranch");

            var user1 = TestHelper.InsertUserDetailed(options);

            //Given
            var orgId2  = Guid.NewGuid();
            var branch1 = new BranchEntity {
                Id = Guid.NewGuid(), OrganisationId = user1.Organisation.Id, Name = "Branch 1"
            };
            var branch2 = new BranchEntity {
                Id = Guid.NewGuid(), OrganisationId = orgId2, Name = "Branch 2"
            };

            using (var context = new DataContext(options))
            {
                context.Branch.Add(branch1);
                context.Branch.Add(branch2);

                context.SaveChanges();
            }

            using (var context = new DataContext(options))
            {
                var auditService = new AuditServiceMock();
                var service      = new BranchService(context, auditService);

                //When
                var scope  = TestHelper.GetScopeOptions(user1);
                var actual = await service.GetBranch(scope, branch1.Id);

                //Then
                Assert.Equal(branch1.Id, actual.Id);
                Assert.Equal(branch1.OrganisationId, actual.OrganisationId);
                Assert.Equal(branch1.Name, actual.Name);

                //Scope check
                scope  = TestHelper.GetScopeOptions(user1);
                actual = await service.GetBranch(scope, branch2.Id);

                //Then
                Assert.Null(actual);
            }
        }
Ejemplo n.º 2
0
        public IHttpActionResult GetBranch(int?branchID)
        {
            if (branchID == null || branchID == 0)
            {
                return(BadRequest("BranchID cannot be null"));
            }

            BranchDTO branch = branchSvc.GetBranch((int)branchID);

            return(Ok(branch));
        }
        public async Task <IActionResult> Get(Guid branchId)
        {
            var scope = AuthenticationService.GetScope(User, User.IsSuperAdmin());

            var model = await BranchService.GetBranch(scope, branchId);

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

            return(Ok(model));
        }
Ejemplo n.º 4
0
        public ResponseMessageNews GetResponseMessage(RequestMessageLocation requestMessage)
        {
            MpUser fromUser = MpUserService.GetByOpenID(requestMessage.FromUserName);

            if (fromUser != null)
            {
                fromUser.LocationX     = requestMessage.Location_X;
                fromUser.LocationY     = requestMessage.Location_Y;
                fromUser.LocationLabel = requestMessage.Label;
                fromUser.LastVisitDate = DateTime.Now;
                MpUserService.Update(fromUser);
            }

            double longitude = requestMessage.Location_Y;
            double latitude  = requestMessage.Location_X;

            //修正坐标
            DistanceHelper.ConvertCoordinate(ref longitude, ref latitude);
            IList <BranchDTO> listBranch = BranchService.GetBranch(longitude, latitude);
            var responseMessage          = ResponseMessageBase.CreateFromRequestMessage <ResponseMessageNews>(requestMessage);

            responseMessage.Articles.Add(new Article()
            {
                Title       = "石狮农商银行周边网点",
                Description = "",
                PicUrl      = GlobalConfig.GetConfig()["ResourceDomain"] + "/funongbaotop.jpg",
                Url         = "http://wx.ssrcb.com/Branch/BranchListMap?point=" + longitude + "," + latitude,
            });
            //responseMessage.Articles.Add(new Article()
            //{
            //    Title = "石狮农商银行周边网点",
            //    Description = "",
            //    PicUrl = GlobalConfig.GetConfig()["ResourceDomain"] + "/funongbaotop.jpg",
            //    Url = "http://wx.ssrcb.com/Branch/BranchList?point=" + longitude + "," + latitude,
            //});
            //foreach (var item in listBranch)
            //{
            //    responseMessage.Articles.Add(new Article()
            //    {
            //        Title = item.Name+"("+item.Distance+"千米)"+"\n"+item.Address,
            //        Description = item.Address,
            //        PicUrl = "",
            //        Url = "http://wx.ssrcb.com/Branch/BranchInfo?id=" + item.Id.ToString() + "&longitude=" + longitude + "&latitude=" + latitude
            //    });
            //}
            return(responseMessage);
        }
Ejemplo n.º 5
0
        // PUT api/<controller>/5
        public IHttpActionResult Put(Branch branch)
        {
            IHttpActionResult result  = null;
            BranchService     service = new BranchService();

            if (service.GetBranch(branch.ID) != null)
            {
                service.UpdateBranch(branch);
                result = Ok(branch);
            }
            else
            {
                result = NotFound();
            }

            return(result);
        }
Ejemplo n.º 6
0
        // GET api/<controller>/5
        public IHttpActionResult Get(int id)
        {
            IHttpActionResult result = null;

            BranchService service = new BranchService();

            Branch branch = service.GetBranch(id);

            if (branch != null)
            {
                result = Ok(branch);
            }
            else
            {
                result = NotFound();
            }

            return(result);
        }
Ejemplo n.º 7
0
        // DELETE api/<controller>/5
        public IHttpActionResult Delete(int id)
        {
            IHttpActionResult result  = null;
            BranchService     service = new BranchService();

            Branch branch = service.GetBranch(id);

            if (branch != null)
            {
                service.RemoveBranch(id);

                result = Ok(true);
            }
            else
            {
                result = NotFound();
            }

            return(result);
        }