コード例 #1
0
ファイル: List.cs プロジェクト: h-sharafi/sharafiSampleJob
            public async Task <List <ActivityOutput> > Handle(Query request, CancellationToken cancellationToken)
            {
                var user = await _userService.CurrentUser();

                var cutentUser = await _userManager.FindByNameAsync(user.Username);

                return(await _context.Activities.Where(a => a.AppUserId == cutentUser.Id).Select(activity => new ActivityOutput
                {
                    Id = activity.Id,
                    lat1 = activity.lat1,
                    lat2 = activity.lat2,
                    lon1 = activity.lon1,
                    lon2 = activity.lon2
                }).ToListAsync());
            }
コード例 #2
0
ファイル: Create.cs プロジェクト: h-sharafi/sharafiSampleJob
            public async Task <Distance> Handle(Query request, CancellationToken cancellationToken)
            {
                double disp = 0;

                try
                {
                    disp = ActicityDisp.DistanceBetweenPlaces(request.lon1, request.lat1, request.lon2, request.lat2);
                }
                catch (Exception ex)
                {
                    throw new RestException(HttpStatusCode.BadRequest, ex.Message);
                }


                //save to database

                var user = await _userService.CurrentUser();

                var cutentUser = await _userManager.FindByNameAsync(user.Username);

                var activity = new Domain.Activity
                {
                    Id        = request.Id,
                    lon1      = request.lon1,
                    lat1      = request.lat1,
                    lon2      = request.lon2,
                    lat2      = request.lat2,
                    AppUserId = cutentUser.Id
                };

                _context.Activities.Add(activity);
                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return new Distance
                           {
                               dis = disp.ToString()
                           }
                }
                ;

                throw new Exception("Problem saving changes");
            }
        }
コード例 #3
0
 public async Task <ActionResult <User> > CurrentUser()
 {
     return(await _userService.CurrentUser());
 }