Ejemplo n.º 1
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var activity = new Domain.Activity
                {
                    Title       = request.Title,
                    Description = request.Description,
                    Category    = request.Category,
                    Date        = request.Date,
                    City        = request.City,
                    Venue       = request.Venue,
                };

                _context.Activities.Add(activity);

                var user = await _context.Users.SingleOrDefaultAsync(u => u.UserName == _userAccessor.GetCurrentUsername());

                var attendee = new UserActivity
                {
                    AppUser    = user,
                    Activity   = activity,
                    IsHost     = true,
                    DateJoined = DateTime.Now
                };

                _context.UserActivities.Add(attendee);

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

                if (success)
                {
                    return(Unit.Value);
                }
                throw new Exception("Failed to save new Activity");
            }
Ejemplo n.º 2
0
            // cancellation Token help aborted request or buggy request clean from server to not consume more pawer
            public async Task <Activity> Handle(Query request, CancellationToken cancellationToken)
            {
                Domain.Activity activity = await _context.Activites.FindAsync(request.Id);

                if (activity == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, new { activity = "Not Found!" });
                }

                return(activity);
            }
Ejemplo n.º 3
0
            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");
            }
        }
Ejemplo n.º 4
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var newActivity = new Activity
                {
                    Id          = request.Id,
                    Title       = request.Title,
                    Description = request.Description,
                    Category    = request.Category,
                    Date        = request.Date,
                    City        = request.City,
                    Venue       = request.Venue
                };

                _context.Activities.Add(newActivity);

                var currentUser = await _context.Users.SingleOrDefaultAsync(user =>
                                                                            user.UserName == _userAccessor.GetCurrentUsername()
                                                                            );

                var newApplicationUserActivity = new ApplicationUserActivity
                {
                    ApplicationUser = currentUser,
                    Activity        = newActivity,
                    IsHost          = true,
                    DateJoined      = DateTime.Now
                };

                _context.ApplicationUserActivities.Add(newApplicationUserActivity);

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

                if (success)
                {
                    return(Unit.Value);
                }

                throw new Exception("Problem adding new activity to the database");
            }
Ejemplo n.º 5
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var activity = new Domain.Activity
                {
                    Id          = request.Id,
                    Title       = request.Title,
                    Category    = request.Category,
                    City        = request.City,
                    Date        = request.Date,
                    Description = request.Description,
                    Venue       = request.Venue
                };

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

                if (success)
                {
                    return(Unit.Value);
                }

                throw new Exception("Unable to solve changes");
            }
Ejemplo n.º 6
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Activity attribute = new Activity
            {
                System_Created = DateTime.Now,
            };

            if (!string.IsNullOrEmpty(this.lblId.Text))
                attribute = this.View_QueryResults
                    .Where(x => x.Id == int.Parse(this.lblId.Text))
                    .FirstOrDefault();

            attribute.Name = this.txtActivityName.Text;
            attribute.Description = this.txtDescription.Text;
            attribute.SystemUpdateDateTime = DateTime.Now;

            this.View_SaveRecord(attribute);
            this.View_QueryRecords(null);
            this.WindowInputChanges(ModifierState.Save);
        }
Ejemplo n.º 7
0
        void SetControlValues(Activity activity)
        {
            if (activity == null)
                return;

            this.txtName.Text = activity.Name;
            this.txtDescription.Text = activity.Description;
        }