Example #1
0
        public async Task <ViewModels.DispatchTask> UpdateAsync(Guid id, ViewModels.DispatchTask dispatchTask, CancellationToken ct)
        {
            if (!(await _authorizationService.AuthorizeAsync(_user, null, new ContentDeveloperRequirement())).Succeeded)
            {
                throw new ForbiddenException();
            }

            var dispatchTaskToUpdate = await _context.DispatchTasks.SingleOrDefaultAsync(v => v.Id == id, ct);

            if (dispatchTaskToUpdate == null)
            {
                throw new EntityNotFoundException <DispatchTask>();
            }

            dispatchTask.CreatedBy    = dispatchTaskToUpdate.CreatedBy;
            dispatchTask.DateCreated  = dispatchTaskToUpdate.DateCreated;
            dispatchTask.DateModified = DateTime.UtcNow;
            dispatchTask.ModifiedBy   = _user.GetId();
            Mapper.Map(dispatchTask, dispatchTaskToUpdate);

            _context.DispatchTasks.Update(dispatchTaskToUpdate);
            await _context.SaveChangesAsync(ct);

            return(_mapper.Map(dispatchTaskToUpdate, dispatchTask));
        }
Example #2
0
        public async Task <ViewModels.DispatchTask> CreateAsync(ViewModels.DispatchTask dispatchTask, CancellationToken ct)
        {
            if (!(await _authorizationService.AuthorizeAsync(_user, null, new ContentDeveloperRequirement())).Succeeded)
            {
                throw new ForbiddenException();
            }
            if (dispatchTask.VmMask != "" && dispatchTask.VmList.Count > 0)
            {
                throw new InvalidOperationException("A DispatchTask cannot have BOTH a VmMask and a VmList!");
            }
            // convert the list of vm guids into a comma separated string and save it in VmMask
            if (dispatchTask.VmList.Count() > 0)
            {
                var vmIdString = "";
                foreach (var vmId in dispatchTask.VmList)
                {
                    vmIdString = vmIdString + vmId + ",";
                }
                dispatchTask.VmMask = vmIdString.Remove(vmIdString.Count() - 1);
            }
            dispatchTask.DateCreated = DateTime.UtcNow;
            dispatchTask.CreatedBy   = _user.GetId();
            dispatchTask.UserId      = _user.GetId();
            var dispatchTaskEntity = Mapper.Map <DispatchTaskEntity>(dispatchTask);

            _context.DispatchTasks.Add(dispatchTaskEntity);
            await _context.SaveChangesAsync(ct);

            return(await GetAsync(dispatchTaskEntity.Id, ct));
        }
Example #3
0
        public async Task <IEnumerable <ViewModels.DispatchTaskResult> > CreateAndExecuteAsync(ViewModels.DispatchTask dispatchTask, CancellationToken ct)
        {
            // create the DispatchTaskEntity
            dispatchTask = await CreateAsync(dispatchTask, ct);

            // execute the DispatchTaskEntity.  Authorization is null, because there can't be any subtasks on a CreateAndExecute.
            var dispatchTaskResultList = await ExecuteAsync(dispatchTask.Id, ct);

            return(dispatchTaskResultList);
        }