예제 #1
0
        public Automation UpdateAutomation(string id, AutomationViewModel request)
        {
            Guid entityId           = new Guid(id);
            var  existingAutomation = _repo.GetOne(entityId);

            if (existingAutomation == null)
            {
                throw new EntityDoesNotExistException($"Automation with id {id} could not be found");
            }

            existingAutomation.Name             = request.Name;
            existingAutomation.AutomationEngine = GetAutomationEngine(request.AutomationEngine);

            var automationVersion = _automationVersionRepository.Find(null, q => q.AutomationId == existingAutomation.Id).Items?.FirstOrDefault();

            if (!string.IsNullOrEmpty(automationVersion.Status))
            {
                //check if previous value was not published before setting published properties
                automationVersion.Status = request.Status;
                if (automationVersion.Status == "Published")
                {
                    automationVersion.PublishedBy    = _httpContextAccessor.HttpContext.User.Identity.Name;
                    automationVersion.PublishedOnUTC = DateTime.UtcNow;
                }
                _automationVersionRepository.Update(automationVersion);
            }
            return(existingAutomation);
        }
예제 #2
0
        public async Task <IActionResult> Put(string id, [FromBody] AutomationViewModel value)
        {
            try
            {
                Guid entityId = new Guid(id);

                var existingAutomation = repository.GetOne(entityId);
                if (existingAutomation == null)
                {
                    return(NotFound());
                }

                existingAutomation.Name             = value.Name;
                existingAutomation.AutomationEngine = value.AutomationEngine;

                var automationVersion = automationVersionRepo.Find(null, q => q.AutomationId == existingAutomation.Id).Items?.FirstOrDefault();
                if (!string.IsNullOrEmpty(automationVersion.Status))
                {
                    //determine a way to check if previous value was not published before setting published properties
                    automationVersion.Status = value.Status;
                    if (automationVersion.Status == "Published")
                    {
                        automationVersion.PublishedBy    = applicationUser?.Email;
                        automationVersion.PublishedOnUTC = DateTime.UtcNow;
                    }
                    automationVersionRepo.Update(automationVersion);
                }
                await webhookPublisher.PublishAsync("Automations.AutomationUpdated", existingAutomation.Id.ToString(), existingAutomation.Name).ConfigureAwait(false);

                return(await base.PutEntity(id, existingAutomation));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("Automation", ex.Message);
                return(BadRequest(ModelState));
            }
        }