public ActionResult AddTicket(FormCollection collection)
        {
            var ticket = _kanbanService.AddTicket(collection, _userService.GetUserIdByUsername(User.Identity.Name));

            //notifications for assignees
            var assigneesNotification = _notificationService.AddNotification("New ticket created!", "You've been assigned to newly created ticket: " + ticket.Name + ".");

            if (collection["assignees"] != null)
            {
                foreach (var userId in collection["assignees"].Split(',').ToList())
                {
                    _notificationService.AddUserNotification(assigneesNotification.Id, userId);
                }
            }

            //notifications for watchers
            var watchersNotification = _notificationService.AddNotification("New ticket created!", "You've been assigned to newly created ticket: " + ticket.Name + ", as watcher!");

            if (collection["watchers"] != null)
            {
                foreach (var userId in collection["watchers"].Split(',').ToList())
                {
                    _notificationService.AddUserNotification(watchersNotification.Id, userId);
                }
            }

            ViewBag.AssigneesNotification = assigneesNotification.Id;
            ViewBag.WatchersNotification  = watchersNotification.Id;

            return(PartialView("_Ticket", ticket));
        }
Exemplo n.º 2
0
        public IActionResult AddCredits(string userId, int credits)
        {
            Contract.Requires(credits > 0 && credits < 50);

            var user = _context.Users.FirstOrDefault(m => m.Id == userId);

            if (user == null)
            {
                return(BadRequest());
            }

            user.Credits += credits;
            _context.SaveChanges();

            _notificationService.AddUserNotification(NotificationLevel.Information, userId,
                                                     "You have recieved {0} credits.", new string[] { credits.ToString() });

            return(Ok());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    UserName         = model.Email,
                    Email            = model.Email,
                    FirstName        = model.FirstName,
                    Surname          = model.Surname,
                    OrganisationName = model.OrganisationName,
                    OrganisationType = model.OrganisationType,
                    Credits          = 0,
                    RegistrationDate = DateTime.Now
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.Action("ConfirmEmail", "Home", new { area = "Account", userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);
                    await _emailSender.SendEmailAsync(model.Email, "Confirm your account",
                                                      $"Please confirm your account by clicking this link: <a href='{callbackUrl}'>link</a>");

                    //await _signInManager.SignInAsync(user, isPersistent: false);
                    _logger.LogInformation(3, "User created a new account with password.");

                    var userId = await _userManager.GetUserIdAsync(user);

                    _notifyService.AddUserNotification(NotificationLevel.Information, userId,
                                                       "Welcome. Please evaluate the sample analyses, and add credits to run your own analyses.", new string[] {});
                    return(RedirectToAction("AwaitingEmailConfirmation"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 4
0
        public async Task <bool> ActivateProFeatures(int jobId, string userId)
        {
            var job = _context.Jobs
                      .Include(m => m.CreatedBy)
                      .Include(m => m.ProActivation)
                      .FirstOrDefault(m => m.Id == jobId);

            if (job == null)
            {
                throw new ArgumentException("An invalid job id was passed to the service");
            }

            // NB the user activating is not necessarily the job creator, but could be an admin.
            var user = _context.Users.FirstOrDefault(u => u.Id == userId);

            if (user == null)
            {
                throw new ArgumentException("An invalid user id was passed to the app service");
            }

            var isAdmin = await _userManager.IsInRoleAsync(user, "Admin");

            if (!isAdmin && user.Credits == 0 && _appOptions.PaymentsEnabled)
            {
                return(false);
            }

            // Allow reactivation by admin
            if (job.ProActivation != null && !isAdmin)
            {
                throw new ArgumentException("The analysis has already been activated");
            }

            // Submit processing for GeoTIFF output
            var request = new JobSubmission()
            {
                Title       = job.Name,
                Description = job.Description,
                UserName    = job.CreatedBy.UserName,
                East        = job.LongitudeEast,
                West        = job.LongitudeWest,
                North       = job.LatitudeNorth,
                South       = job.LatitudeSouth,
                Priority    = 2
            };
            var processorReference = await _processor.StartProJob(request);

            if (String.IsNullOrEmpty(processorReference))
            {
                return(false);
            }

            if (!isAdmin && _appOptions.PaymentsEnabled)
            {
                user.Credits = user.Credits - 1;
            }

            var activation = new ProActivation()
            {
                //Id = Guid.NewGuid(),
                UserIdOfPurchaser     = user.Id,
                TimeOfPurchase        = DateTime.Now,
                CreditsSpent          = 1,
                ProcessingStatus      = JobStatus.Submitted,
                JobProcessorReference = processorReference
            };

            job.ProActivation = activation;
            _context.Update(job);
            _context.Update(user);
            _context.SaveChanges();
            Hangfire.RecurringJob.AddOrUpdate("prostatus_" + job.Id, () => UpdateProStatusAsync(job.Id), Cron.Minutely);

            if (!isAdmin && _appOptions.PaymentsEnabled)
            {
                _notifyService.AddJobNotification(NotificationLevel.Success, job.Id,
                                                  "You used 1 credit to upgrade '{0}' to premium.", new string[] { job.Name });

                if (user.Credits <= 3 && user.Credits > 0)
                {
                    _notifyService.AddUserNotification(NotificationLevel.Information, user.Id,
                                                       "Your credits are running low. You only have enough for {0} more premium activations.", new string[] { user.Credits.ToString() });
                }
                else if (user.Credits == 0)
                {
                    _notifyService.AddUserNotification(NotificationLevel.Information, user.Id,
                                                       "You're out of credits, and will not be able to activate premium datasets unless you top up.", new string[] {});
                }
            }
            else if (!_appOptions.PaymentsEnabled)
            {
                _notifyService.AddJobNotification(NotificationLevel.Success, job.Id,
                                                  "Your request for a high-resolution data package for '{0}' has entered the queue.", new string[] { job.Name });
            }
            return(true);
        }