Ejemplo n.º 1
0
        public ActionResult Attending()
        {
            var userId = User.Identity.GetUserId();

            var viewModel = new ActivityViewModel
            {
                UpcommingActivities = _unitOfWork.Activities.GetActivitiesUserAttending(userId),
                ShowActions         = User.Identity.IsAuthenticated,
                Heading             = "Activities I'm Attending",
                Attendances         = _unitOfWork.Attendances.GetFutureAttendances(userId).ToLookup(a => a.ActivityId)
            };

            return(View("Activities", viewModel));
        }
Ejemplo n.º 2
0
        public ActionResult Index()
        {
            ActivityViewModel activityViewModel;
            ActivityLogic     activityLogic = new ActivityLogic();
            var activities = new List <ActivityViewModel>();

            foreach (var activity in activityLogic.PassActivities())
            {
                activityViewModel = new ActivityViewModel(activity);
            }


            return(View());
        }
Ejemplo n.º 3
0
        public ActivityViewModel CreateArticle(ActivityViewModel model, HttpPostedFileBase file, HttpServerUtilityBase server)
        {
            var article = mapArticle(model);

            model.ImageUrl = saveFileImage(false, article.ImageUrl, file, server);
            var url = article.EventDate.ToShortDateString() + "_" + article.Title;

            article.UrlParameter = url.ToUrlString("-");

            context.Events.Add(article);
            context.SaveChanges();

            return(mapViewModel(article));
        }
Ejemplo n.º 4
0
        public ActionResult Create(ActivityViewModel activity)
        {
            var tempEntity = new commonEntity()
            {
                Id = activity.redirectProperty.Id,
                returnController = activity.redirectProperty.returnController,
                returnId         = activity.redirectProperty.returnId,
                returnMethod     = activity.redirectProperty.returnMethod,
                returnTarget     = activity.redirectProperty.returnTarget
            };

            activity.redirectProperty = tempEntity;


            if (ModelState.IsValid)
            {
                var addActivity = new Activity()
                {
                    ActivityName   = activity.ActivityName,
                    ActivityTypeId = activity.ActivityTypeId,
                    ModuleId       = activity.ModuleId,
                };
                DateTime s = activity.StartDate;
                DateTime e = activity.EndDate;
                if (activity.StartDateAm)
                {
                    addActivity.StartDate = new DateTime(s.Year, s.Month, s.Day, 0, 0, 0);
                }
                else
                {
                    addActivity.StartDate = new DateTime(s.Year, s.Month, s.Day, 12, 0, 0);
                }
                if (activity.EndDateAm)
                {
                    addActivity.EndDate = new DateTime(e.Year, e.Month, e.Day, 11, 59, 59);
                }
                else
                {
                    addActivity.EndDate = new DateTime(e.Year, e.Month, e.Day, 23, 59, 59);
                }

                db.Activities.Add(addActivity);
                db.SaveChanges();
                return(RedirectToAction(activity.redirectProperty.returnMethod, activity.redirectProperty.returnController, new { id = activity.redirectProperty.returnId, redirect = activity.redirectProperty.returnTarget }));
            }

            ViewBag.ActivityTypeId = new SelectList(db.ActivityTypes, "Id", "ActivityTypeName", activity.ActivityTypeId);
            return(View(activity));
        }
        public async Task GetAllInDestinationDoesNotReturnActivitiesInOtherDestinations()
        {
            await this.AddTestingCountryToDb();

            this.DbContext.Destinations.Add(new Destination
            {
                Id        = SecondTestDestinationId,
                Name      = SecondTestDestinationName,
                CountryId = TestCountryId,
            });
            this.DbContext.Activities.AddRange(new List <Activity>
            {
                new Activity
                {
                    Id            = TestActivityId,
                    Name          = TestActivityName,
                    DestinationId = SecondTestDestinationId,
                    Type          = ActivityType.Adventure,
                },
                new Activity
                {
                    Id            = SecondTestActivityId,
                    Name          = SecondTestActivityName,
                    DestinationId = TestDestinationId,
                    Type          = ActivityType.Other,
                }
            });
            await this.DbContext.SaveChangesAsync();

            var expected = new ActivityViewModel[]
            {
                new ActivityViewModel
                {
                    Id            = TestActivityId,
                    Name          = TestActivityName,
                    DestinationId = SecondTestDestinationId,
                    Type          = ActivityType.Adventure.ToString(),
                },
            };

            var actual = await this.ActivitiesServiceMock.GetAllInDestinationAsync(SecondTestDestinationId);

            Assert.Equal(expected[0].Id, actual.First().Id);
            Assert.Equal(expected[0].Name, actual.First().Name);
            Assert.Equal(expected[0].DestinationId, actual.First().DestinationId);
            Assert.Equal(expected[0].Type, actual.First().Type);

            Assert.Equal(expected.Length, actual.Count());
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Add([FromBody] ActivityViewModel activity)
        {
            var user = _context.Users
                       .Include(x => x.Activities)
                       .FirstOrDefault(x => x.UserId == activity.UserId);

            if (user != null)
            {
                if (user.Activities == null)
                {
                    user.Activities = new List <Activity>();
                }

                FitnessType activityType;

                if (!string.IsNullOrEmpty(activity.Type)) //Old clients
                {
                    activityType = OldSupport.PatchOld(activity.Type);
                }
                else
                {
                    activityType = activity.FitnessType;
                }

                var existing = user.Activities.FirstOrDefault(x => x.Date.Date == activity.Date.Date && x.Type == activityType);
                if (existing == null)
                {
                    user.Activities.Add(new Activity {
                        Amount = activity.Amount,
                        Date   = activity.Date,
                        Type   = activityType,
                        UserId = activity.UserId
                    });
                }
                else
                {
                    existing.Date   = activity.Date;
                    existing.Amount = activity.Amount;
                }

                user.LastRecordedDate = activity.Date.Date;
                await _context.SaveChangesAsync();

                return(Ok());
            }
            {
                return(NotFound());
            }
        }
Ejemplo n.º 7
0
        public async Task <ActionResult <Activity> > PostDrainPatrol(ActivityViewModel drainPatrolViewModel)
        {
            var insertData = new Activity
            {
                Master_node = drainPatrolViewModel.Master_node,
                Index       = drainPatrolViewModel.Index,
                Address     = drainPatrolViewModel.Address,
                Time        = drainPatrolViewModel.Time,
                Active      = drainPatrolViewModel.Active
            };

            // SignalR to update page with above record
            await _hub.Clients.All.SendAsync("DrainActivity", insertData.Address, insertData);


            // Save data in Azure Table Storage to flatten out the data.

            await SaveToTableStorage(drainPatrolViewModel);



            // Save activity in Azure SQL to table Activities
            _context.Activities.Add(insertData);
            await _context.SaveChangesAsync();

            // Email if A or B-Alarm
            switch (insertData.Address)
            {
            case "2O1":
                await SendEmailAlarm(insertData, "A-larm");

                break;

            case "2O2":
                await SendEmailAlarm(insertData, "B-larm");

                break;

            default:
                if (insertData.Address.StartsWith("3") && insertData.Address.EndsWith("8"))
                {
                    await SendEmailWellFull(insertData);
                }

                break;
            }

            return(Ok(drainPatrolViewModel));
        }
Ejemplo n.º 8
0
        public void Edit_Invalid()
        {
            //Arrange
            ActivityViewModel model = new ActivityViewModel()
            {
            };

            controllerWEB.ModelState.AddModelError("Error", "Что-то пошло не так");

            //Act
            var result = (ViewResult)controllerWEB.Edit(model);

            //Assert
            Assert.AreEqual("", result.ViewName);
        }
Ejemplo n.º 9
0
        public async Task <ActionResult> Create(ActivityViewModel model)
        {
            ActivityEnvelope envelope = new ActivityEnvelope(model);

            if (Request.HttpMethod == "POST")
            {
                await YammerRepository.PostActivity(envelope);

                return(Redirect("/"));
            }
            else
            {
                return(View(model));
            }
        }
Ejemplo n.º 10
0
 public static Activity AsModel(this ActivityViewModel activity)
 {
     return(new Activity
     {
         id = activity.Id,
         CreatedAt = activity.CreatedAt,
         Data = activity.Data,
         Text = activity.Text,
         TrackId = activity.TrackId,
         Type = (int)activity.Type,
         UserDisplayName = activity.UserDisplayName,
         UserId = activity.UserId,
         VehicleId = activity.VehicleId
     });
 }
Ejemplo n.º 11
0
        public PromodoTimer()
        {
            this.InitializeComponent();

            CoreApplication.Exiting += ApplicationExiting;
            _service   = new LocalStorageService();
            _viewModel = new ActivityViewModel();
            SetUpActivities();
            SetupSettings();
            this.DataContext = _viewModel;

            _timer          = new DispatcherTimer();
            _timer.Interval = new TimeSpan(0, 0, 1);
            _timer.Tick    += Timer_Tikk;
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> CreateTraining(ActivityViewModel activity)
        {
            var runner = await _runnerRepo.GetUserAsync(_userManager.GetUserId(User));

            Activity obj = new Activity
            {
                IdRunner = runner.Id,
                Name     = activity.Name,
                Place    = activity.Place,
                Type     = 1, //1= training, 2 = gara
            };
            await _activityRepo.InsertAsync(obj);

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 13
0
        public IActionResult Delete([FromRoute] int id, ActivityViewModel model)
        {
            var activity = _activityRepository.Get(id);

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

            _telemetryRepository.Delete(id);

            _activityRepository.Delete(id);

            return(RedirectToAction("/Index"));
        }
Ejemplo n.º 14
0
 public ActionResult Edit(ActivityViewModel activity)
 {
     if (ModelState.IsValid)
     {
         var entity = Mapper.Map <Activity>(activity);
         activityService.Update(entity);
         return(RedirectToAction("Index"));
     }
     ViewBag.CampaignId    = new SelectList(campaignService.GetAll(), "Id", "Name", activity.CampaignId);
     ViewBag.CompanyId     = new SelectList(companyService.GetAll(), "Id", "Name", activity.CompanyId);
     ViewBag.Companies     = companyService.GetAll();
     ViewBag.ContactId     = new SelectList(contactService.GetAll(), "Id", "FullName", activity.ContactId);
     ViewBag.OpportunityId = new SelectList(opportunityService.GetAll(), "Id", "Name", activity.OpportunityId);
     return(View(activity));
 }
Ejemplo n.º 15
0
        public ActionResult ManageReport(int id, ActivityViewModel activityViewModel)
        {
            // validazione
            if (ModelState.IsValid)
            {
                // salvo
                var activityReport = this.session.Load <DailyReport>(id);
                activityReport.AddActivity(activityViewModel.Description, activityViewModel.Hours);
                this.session.Update(activityReport);

                return(RedirectToAction("ManageReport", new { id = id }));
            }
            GetDataForManageReport(id);
            return(View(activityViewModel));
        }
Ejemplo n.º 16
0
        internal ActivityViewModel Update(ActivityViewModel workLog, int userId)
        {
            var workLogToUpdate = _context.WorkLogs.Single(u => u.WorkLogId == workLog.Id);

            if (workLogToUpdate.User.UserId != userId)
            {
                throw new UnauthorizedAccessException("You are not allowed to edit this worklog!");
            }

            workLogToUpdate.Hours       = workLog.Hours;
            workLogToUpdate.Description = workLog.Description;
            _context.SaveChanges();

            return(ActivityViewModel.From(workLogToUpdate));
        }
Ejemplo n.º 17
0
        private Activity CreateActivity(ActivityViewModel model)
        {
            var activityTypeResult = _context.ActivityType.SingleOrDefault(activityType => activityType.ActivityTypeID == Convert.ToInt32(model.ActivityTypeID));

            return(new Activity
            {
                ActivityID = model.ActivityID,
                Name = model.Name,
                Description = model.Description,
                StartDateTime = DateTime.ParseExact(model.StartDateTime, "dd-MM-yyyy HH:mm", new CultureInfo("nl-NL")),
                EndDateTime = DateTime.ParseExact(model.EndDateTime, "dd-MM-yyyy HH:mm", new CultureInfo("nl-NL")),
                NeedsSignUp = model.NeedsSignUp,
                ActivityType = activityTypeResult
            });
        }
Ejemplo n.º 18
0
        public ActionResult Edit([Bind(Include = "Id,HostBy,HostEmail,HostPhone,EventDate,ImageUrl,Title,Summary,BodyHtml,UrlParameter,Created,Modified,IsActive,Address,Lat,Lng,LogMessages")]
                                 ActivityViewModel activity, FormCollection fc)
        {
            rep = new ActivityRepository();
            var file = Request.Files.AllKeys.Any() ? Request.Files[0] : null;

            if (ModelState.IsValid)
            {
                activity = rep.EditArticle(activity, file, Server);
                return(RedirectToAction("Index"));
            }

            ViewBag.page = "Modify";
            return(View("Modify", activity));
        }
Ejemplo n.º 19
0
        public ActivityViewModel EditArticle(ActivityViewModel model, HttpPostedFileBase file, HttpServerUtilityBase server)
        {
            var article = mapArticle(model);

            model.ImageUrl = saveFileImage(true, article.ImageUrl, file, server);
            var url = article.EventDate.ToShortDateString() + "_" + article.Title;

            article.UrlParameter = url.ToUrlString("-");

            context.Entry(article.Location).State = EntityState.Modified;
            context.Entry(article).State          = EntityState.Modified;
            context.SaveChanges();

            return(mapViewModel(article));
        }
        public IActionResult Post([FromBody] ActivityViewModel activity)
        {
            try
            {
                dbContext.Activity.Add(mapper.Map <ActivityViewModel, Activity>(activity));
                dbContext.SaveChanges();
                return(CreatedAtRoute("GetActivity", new { id = activity.Id }, activity));
            }
            catch (Exception ex)
            {
                logger.LogError($"Failed to save a activities: {ex}");
            }

            return(BadRequest("Failed to save activities"));
        }
Ejemplo n.º 21
0
        public ActionResult Edit(ActivityViewModel avm, int?page)
        {
            var av = db.Activities.Find(avm.ActivityID);

            av.ActivityName = avm.ActivityName;
            av.BeginDate    = avm.BeginDate;
            av.EndDate      = avm.EndDate;
            av.ActivityID   = avm.ActivityID;
            av.DiscountID   = avm.DiscountID;

            db.Entry(av).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();

            TempData["savepage"] = page ?? 1;
            return(RedirectToAction("Edit", new { id = avm.ActivityID, page = TempData["savepage"] }));
        }
        public void ShowWindow(BaseViewModel viewModel)
        {
            Window window = viewModel switch
            {
                null => throw new ArgumentNullException(nameof(viewModel)),

                      EmployeeViewModel _ => new MainWindow(),

                      ActivityViewModel _ => new ActivityWindow(),

                      _ => throw new InvalidOperationException($"Unknown VieModel of type '{viewModel}'"),
            };

            window.DataContext = viewModel;
            window.ShowDialog();
        }
Ejemplo n.º 23
0
        public void Update(ActivityViewModel activityInfo)
        {
            var activity = Repository.GetById(activityInfo.Id);

            activity.ActivityTypeId = activityInfo.ActivityTypeId;
            activity.Title          = activityInfo.Title;
            activity.CourseInfo     = activityInfo.CourseInfo;
            activity.DueDate        = activityInfo.DueDate;
            activity.GradeWorth     = activityInfo.GradeWorth;
            activity.InitialMood    = activityInfo.InitialMood;
            activity.IsArchived     = activityInfo.IsArchived;

            Repository.Update(activity);

            UnitOfWork.SaveChanges();
        }
Ejemplo n.º 24
0
        public ActionResult Delete(ActivityViewModel activityViewModel, int?id)
        {
            if (!LoginUserSession.IsStateAdmin)
            {
                return(Redirect("/Users/Login"));
            }

            var activity = _repository.SelectByID(id.Value);

            var deletedActivity = Mapper.Map(activityViewModel, activity);

            _repository.Delete(deletedActivity);
            _repository.Save();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 25
0
        public async Task <ActionResult> Index()
        {
            var vm      = new ActivityViewModel();
            var account = await _accountsService.GetAccount(User);

            if (account == null)
            {
                vm.Transactions = new List <Transaction>();
            }
            else
            {
                vm.Transactions = await _transactionsService.GetTransactions(account.Id);
            }

            return(View(vm));
        }
Ejemplo n.º 26
0
        public async Task <IActionResult> Create(ActivityViewModel model)
        {
            if (ModelState.IsValid)
            {
                _context.Add(CreateActivity(model));
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            var activityTypesResult = _context.ActivityType.ToListAsync().Result;

            ViewBag.ActivityTypes = new SelectList(activityTypesResult, "ActivityTypeID", "Name");

            return(View(model));
        }
Ejemplo n.º 27
0
        public IActionResult ShowReviews(int ActivityID)
        {
            //check for logged in state
            if (HttpContext.Session.GetInt32("logged_id") == null)
            {
                return(RedirectToAction("LoginReg", "LoginReg"));
            }
            //grab user and activity for front end
            ViewBag.LoggedUserID = (int)HttpContext.Session.GetInt32("logged_id");
            Activity a = _context.Activities.Include(activity => activity.Creator).Include(activity => activity.UsersAttending).ThenInclude(ua => ua.User).Include(activity => activity.Reviews).ThenInclude(review => review.Reviewer).SingleOrDefault(activity => activity.ActivityID == ActivityID);

            ViewBag.Activity = a;
            ActivityViewModel viewModel = ActivityViewModel.GetActivityViewModel(a);

            return(View("ShowReviews", viewModel));
        }
Ejemplo n.º 28
0
        public ActivitiesPage(ICollection <Activity> list, string subtitle)
        {
            InitializeComponent();
            if (list != null && list.Count > 0)
            {
                Activities = list.ToList();
                Activities.ForEach(act => act.Image = ImageManager <string> .GetInstance().GetImageFromPath(act.Image));

                BindingContext = new ActivityViewModel(Activities, subtitle);

                foreach (Activity act in list)
                {
                    Content.Children.Add(ShowActivity(act));
                }
            }
        }
Ejemplo n.º 29
0
        public IActionResult Index(int pageId = 1)
        {
            ActivityViewModel activityViewModel = new ActivityViewModel();

            activityViewModel.Activities   = activityRepository.GetActiveActivitiesForPage(pageId, PageSize);
            activityViewModel.CurrentPage  = pageId;
            activityViewModel.ItemsPerPage = PageSize;
            activityViewModel.TotalItems   = activityRepository.NumberOfActiveActivities();

            if (TempData["Message"] != null)
            {
                activityViewModel.Message = TempData["Message"].ToString();
            }

            return(View(activityViewModel));
        }
Ejemplo n.º 30
0
        private async void Init()
        {
            userViewModel    = new UserViewModel();
            this.DataContext = userViewModel;
            if (_localSettings.Values.ContainsKey("isRemember"))
            {
                if (_localSettings.Values["isRemember"].ToString() == "true")
                {
                    await userViewModel.AutoLogin();

                    NameShow.Text = userViewModel.User.nickname;
                }
            }
            activityViewModel = new ActivityViewModel();
            this.DataContext  = activityViewModel;
        }
 private string NewnessGroupText(ActivityViewModel viewModel)
 {
     if (viewModel is MessageActivityViewModel || viewModel is ModeratorMessageActivityViewModel)
     {
         return "unread";
     }
     else if (viewModel is ModeratorActivityViewModel || viewModel is ReportActivityViewModel)
     {
         return "unreviewed";
     }
     else if (viewModel is PostedLinkActivityViewModel || viewModel is PostedCommentActivityViewModel ||
         viewModel is RecivedCommentReplyActivityViewModel || viewModel is MentionActivityViewModel)
     {
         return "unviewed";
     }
     else
         throw new ArgumentOutOfRangeException();
 }
 private string MessageGroupText(ActivityViewModel viewModel)
 {
     if (viewModel is MessageActivityViewModel || viewModel is ModeratorMessageActivityViewModel)
     {
         return "messages";
     }
     else if (viewModel is ModeratorActivityViewModel)
     {
         return "activities";
     }
     else if (viewModel is ReportActivityViewModel)
         return "reports";
     else if (viewModel is PostedLinkActivityViewModel || viewModel is PostedCommentActivityViewModel ||
         viewModel is RecivedCommentReplyActivityViewModel || viewModel is MentionActivityViewModel)
     {
         return "replies";
     }
     else
         throw new ArgumentOutOfRangeException();
 }
        public ActionResult ManageReport(int id, ActivityViewModel activityViewModel)
        {
            // validazione
            if (ModelState.IsValid)
            {
                // salvo
                var activityReport = this.session.Load<DailyReport>(id);
                activityReport.AddActivity(activityViewModel.Description, activityViewModel.Hours);
                this.session.Update(activityReport);

                return RedirectToAction("ManageReport", new { id = id });
            }
            GetDataForManageReport(id);
            return View(activityViewModel);
        }