Beispiel #1
0
        public ActionResult UpdateIssueStatus(UIIssueStatus_U uim)
        {
            AjaxStatus status = new AjaxStatus();

            using (var context = new DataContext())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        Account account = base.GetLoginAccount();
                        Issue   dbm     = IssueOperations.TryRead(account, context, uim.id);
                        // Create transition
                        IssueTransition transition = uim.CreateModel(dbm, account);
                        IssueTransitionOperations.TryCreate(account, context, transition);
                        // Update model
                        uim.UpdateModel(dbm);
                        IssueOperations.TryUpdate(account, context, dbm);
                        // Mark as unread
                        IssueOperations.TryDeleteReaders(account, context, dbm.id);
                        // TODO: If new status is to archive, move to archived tables
                        context.SaveChanges();
                        transaction.Commit();
                    }
                    catch (Exception e)
                    {
                        transaction.Rollback();
                        base.HandleException("UpdateIssueStatus", e);
                        status.SetError(e.Message);
                    }
                }
            }
            return(Json(status));
        }
Beispiel #2
0
 public IssueTransitionStruct(IssueTransition transition)
 {
     this.fromstatus = Issue.StatusAsString(transition.fromstatus);
     this.tostatus   = Issue.StatusAsString(transition.tostatus);
     this.statusicon = Images.StatusAsImage(transition.tostatus);
     this.name       = transition.createdname;
     this.date       = DateUtils.ConvertToDateString(transition.createddate);
     this.time       = DateUtils.ConvertToTimeString(transition.createddate);
 }
Beispiel #3
0
        public static void TryDelete(Account requester, DataContext context, int id)
        {
            if (!requester.IsAtLeastManagement())
            {
                throw new ServerAuthorizeException("Du har inte behörighet att radera konto");
            }
            // Issues -- delete NOT OK
            Issue issue = context.Issues.FirstOrDefault(i => id == i.residentid);

            if (issue != null)
            {
                throw new ServerConflictException("Konto används som boende i ärende " + issue.id);
            }

            issue = context.Issues.FirstOrDefault(i => id == i.assignedid);
            if (issue != null)
            {
                throw new ServerConflictException("Konto används som tilldelad i ärende " + issue.id);
            }

            IssueMaterial issuematerial = context.IssueMaterials.FirstOrDefault(i => id == i.createdby);

            if (issuematerial != null)
            {
                throw new ServerConflictException("Konto används för material i ärende " + issuematerial.issueid);
            }

            IssuePhoto issuephoto = context.IssuePhotos.FirstOrDefault(i => id == i.createdby);

            if (issuephoto != null)
            {
                throw new ServerConflictException("Konto används för fotografi i ärende " + issuephoto.issueid);
            }

            IssueTime issuetime = context.IssueTimes.FirstOrDefault(i => id == i.createdby);

            if (issuetime != null)
            {
                throw new ServerConflictException("Konto används för tid i ärende " + issuetime.issueid);
            }

            IssueTransition issuetransition = context.IssueTransitions.FirstOrDefault(i => id == i.createdby);

            if (issuetransition != null)
            {
                throw new ServerConflictException("Konto används för historik i ärende " + issuetransition.issueid);
            }

            // Do deletion
            Account dbentity = GetDBEntity(context, id);

            context.Accounts.Remove(dbentity);
            context.Entry(dbentity).State = System.Data.Entity.EntityState.Deleted;
        }
        public IssueTransition CreateModel(Issue dbm, Account requester)
        {
            IssueTransition model = new IssueTransition();

            model.fromstatus  = dbm.status;
            model.tostatus    = this.status;
            model.issueid     = dbm.id;
            model.createdby   = requester.id;
            model.createdname = requester.Name;
            model.createddate = DateUtils.TimeStamp;
            return(model);
        }
Beispiel #5
0
        //should have put this in stateless as well
        private async Task <Issue> TransferOwnerShip(Issue issue, IssueTransition transition, string userId)
        {
            switch (transition)
            {
            case IssueTransition.Assign:
                var user = await _db.Users.GetAsync(userId);

                var solverRole = await _db.Roles.SingleOrDefaultAsync(r => r.Name.ToLower().Equals("solver"));

                if (user?.Roles.FirstOrDefault(r => r.RoleId == solverRole.Id) == null)
                {
                    throw new BusinessException(BusinessErrors.TargetUserInvalid);
                }

                issue.ResponsibleUserId = userId;
                break;

            case IssueTransition.Cancel:
            case IssueTransition.Close:
            case IssueTransition.Refuse:
                issue.ResponsibleUserId = null;
                break;

            case IssueTransition.Enquire:
            case IssueTransition.Solve:
                issue.ResponsibleUserId = issue.CreatorId;
                break;

            //in case of response, get latest history status and set responsible owner to be this guy. (the one who asked the question)
            case IssueTransition.Respond:
                var histories = await _db.Histories.FindAsync(h => h.IssueId == issue.Id);

                var latesthistory = histories.FirstOrDefault(h => h.CreatedOn == histories.Max(x => x.CreatedOn));

                if (latesthistory == null)
                {
                    throw new BusinessException(BusinessErrors.IssueInvalid);
                }

                issue.ResponsibleUserId = latesthistory.UserId;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(transition), transition, null);
            }
            return(null);
        }
Beispiel #6
0
        // Returns "null" att success, else message to be sent to trace log
        public string SendIssueTransitionNotification(Account receiver, Issue report, IssueTransition transition)
        {
            string subject = "TBD";
            string body    = "TBD";

            return(this.Send(receiver.email, receiver.Name, subject, body));
        }
 public static IssueTransition TryUpdate(Account requester, DataContext context, IssueTransition dbentity)
 {
     throw new ServerAuthorizeException("Ej tillåtet");
 }
 public static void TryCreate(Account requester, DataContext context, IssueTransition transition)
 {
     transition.Validate();
     context.IssueTransitions.Add(transition);
 }