private bool IsValidTransition(NominationStatus fromStatus, NominationStatus toStatus)
        {
            switch (toStatus)
            {
            case NominationStatus.Approved:
                return(fromStatus == NominationStatus.PendingApproval);

            case NominationStatus.Uploading:
                return(fromStatus == NominationStatus.Approved || fromStatus == NominationStatus.PendingApproval);

            case NominationStatus.Importing:
                return(fromStatus == NominationStatus.Uploading);

            case NominationStatus.Complete:
                return(fromStatus == NominationStatus.Importing || fromStatus == NominationStatus.Error);

            case NominationStatus.PendingApproval:
            case NominationStatus.Rejected:
            case NominationStatus.Error:
                return(true);

            default:
                return(false);
            }
        }
Exemple #2
0
        //
        // GET: /NominationStatus/Edit/5

        public ActionResult Edit(int id = 0)
        {
            NominationStatus nominationstatus = db.NominationStatus.Find(id);

            if (nominationstatus == null)
            {
                return(HttpNotFound());
            }
            return(View(nominationstatus));
        }
Exemple #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            NominationStatus nominationstatus = db.NominationStatus.Find(id);

            db.NominationStatus.Remove(nominationstatus);
            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
                Session["FlashMessage"] = "Failed to delete status." + e.Message;
                return(View(nominationstatus));
            }
            return(RedirectToAction("Index"));
        }
Exemple #4
0
 public ActionResult Edit(NominationStatus nominationstatus)
 {
     if (ModelState.IsValid)
     {
         db.Entry(nominationstatus).State = EntityState.Modified;
         try
         {
             db.SaveChanges();
         }
         catch (Exception e)
         {
             Session["FlashMessage"] = "Failed to edit status." + e.Message;
             return(View(nominationstatus));
         }
         return(RedirectToAction("Index"));
     }
     return(View(nominationstatus));
 }
Exemple #5
0
        public ActionResult Create(NominationStatus nominationstatus)
        {
            if (ModelState.IsValid)
            {
                db.NominationStatus.Add(nominationstatus);
                try
                {
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    Session["FlashMessage"] = "Failed to create status." + e.Message;
                    return(View(nominationstatus));
                }
                return(RedirectToAction("Index"));
            }

            return(View(nominationstatus));
        }
        public async Task <(bool found, string name)> UpdateNominationStatusAndReturnName(
            Guid id,
            NominationStatus status,
            ClaimsPrincipal user,
            CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            var docUri  = CreateUserDataDocumentUri(id);
            var options = new RequestOptions
            {
                PartitionKey = new PartitionKey(WellKnownIds.DatasetNominationDatasetId.ToString())
            };

            var nomination = await Client.ReadDocumentAsync <DatasetNominationStorageItem>(docUri, options);

            if (nomination == null)
            {
                return(false, null);
            }

            if (!IsValidTransition(nomination.Document.NominationStatus, status))
            {
                throw new InvalidOperationException($"Invalid transition of nomination to {status} state.");
            }

            nomination.Document.Modified         = DateTime.UtcNow;
            nomination.Document.NominationStatus = status;

            if (user != null)
            {
                var name  = GetUserName(user);
                var email = GetUserEmail(user);
                nomination.Document.ModifiedByUserName  = name;
                nomination.Document.ModifiedByUserEmail = email;
            }

            await Client.ReplaceDocumentAsync(docUri, nomination.Document);

            return(true, nomination.Document.Name);
        }
        /// <summary>
        /// Approves the nominated dataset
        /// </summary>
        /// <param name="id">The dataset ID</param>
        /// <param name="user">user approving the nomination</param>
        /// <param name="cancellationToken"></param>
        /// <returns>The current identifier for the nominated dataset or null if nomination is not found</returns>
        public async Task <bool> ApproveNominationAsync(Guid id, ClaimsPrincipal user, CancellationToken cancellationToken)
        {
            var nomination = await GetByIdAsync(id, cancellationToken);

            if (nomination == null || nomination.NominationStatus != NominationStatus.PendingApproval)
            {
                return(false);
            }

            var contentLink = CreateUserDataDocumentAttachmentUri(id, "Content");
            var options     = new RequestOptions
            {
                PartitionKey = new PartitionKey(WellKnownIds.DatasetNominationDatasetId.ToString())
            };
            bool foundStorage = false;

            try
            {
                var response = await Client.ReadAttachmentAsync(contentLink.ToString(), options).ConfigureAwait(false);

                var resource = response?.Resource;
                if (resource != null)
                {
                    var accountName   = resource.GetPropertyValue <string>("account");
                    var containerName = resource.GetPropertyValue <string>("container");
                    foundStorage = !string.IsNullOrWhiteSpace(accountName) && !string.IsNullOrWhiteSpace(containerName);
                }
            }
            catch (DocumentClientException ex) when(ex.StatusCode == HttpStatusCode.NotFound)
            {
            }

            NominationStatus status = foundStorage ? NominationStatus.Uploading : NominationStatus.Approved;

            return(await UpdateNominationStatus(id, status, user, cancellationToken));
        }
        public async Task <bool> UpdateNominationStatus(Guid id, NominationStatus status, ClaimsPrincipal user, CancellationToken cancellationToken)
        {
            var(found, _) = await UpdateNominationStatusAndReturnName(id, status, user, cancellationToken);

            return(found);
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            NominationStatus status = (NominationStatus?)value ?? DefaultStatus;

            writer.WriteValue(status.ToString());
        }