示例#1
0
        public async Task <ActionResult <Guid> > Create(TaskStatus status, CancellationToken ct = default)
        {
            status.AccountId = _userContext.AccountId;

            var id = await _taskStatusesService.CreateAsync(_userContext.UserId, status, ct);

            return(Created("Get", id));
        }
示例#2
0
        public async Task <ActionResult> Update(TaskStatus status, CancellationToken ct = default)
        {
            var oldStatus = await _taskStatusesService.GetAsync(status.Id, true, ct);

            if (oldStatus == null)
            {
                return(NotFound(status.Id));
            }

            return(await ActionIfAllowed(
                       () => _taskStatusesService.UpdateAsync(_userContext.UserId, oldStatus, status, ct),
                       Roles.Tasks,
                       oldStatus.AccountId));
        }
示例#3
0
        public async Task UpdateAsync(
            Guid userId,
            TaskStatus oldStatus,
            TaskStatus newStatus,
            CancellationToken ct)
        {
            var change = oldStatus.UpdateWithLog(userId, x =>
            {
                x.Name           = newStatus.Name;
                x.IsFinish       = newStatus.IsFinish;
                x.IsDeleted      = newStatus.IsDeleted;
                x.ModifyDateTime = DateTime.UtcNow;
            });

            _storage.Update(oldStatus);
            await _storage.AddAsync(change, ct);

            await _storage.SaveChangesAsync(ct);
        }
示例#4
0
        public async Task <Guid> CreateAsync(Guid userId, TaskStatus status, CancellationToken ct)
        {
            var newStatus = new TaskStatus();
            var change    = newStatus.CreateWithLog(userId, x =>
            {
                x.Id             = status.Id;
                x.AccountId      = status.AccountId;
                x.Name           = status.Name;
                x.IsFinish       = status.IsFinish;
                x.IsDeleted      = status.IsDeleted;
                x.CreateDateTime = DateTime.UtcNow;
            });

            var entry = await _storage.AddAsync(newStatus, ct);

            await _storage.AddAsync(change, ct);

            await _storage.SaveChangesAsync(ct);

            return(entry.Entity.Id);
        }