public async Task <IActionResult> PutOrganizationUnit(int id, OrganizationUnit organizationUnit)
        {
            if (id != organizationUnit.Id)
            {
                return(BadRequest());
            }

            _context.Entry(organizationUnit).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OrganizationUnitExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 2
0
        public async Task<IActionResult> PutAudit(int id, Audit audit)
        {
            if (id != audit?.Id)
            {
                return BadRequest();
            }

            _context.Entry(audit).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AuditExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return NoContent();
        }
Esempio n. 3
0
        public async Task <IActionResult> HideBackendTask(BackendTask backendTask)
        {
            if (backendTask?.Id == null && backendTask?.UserId == User.Identity.Name)
            {
                return(BadRequest());
            }
            backendTask.IsVisible             = false;
            _context.Entry(backendTask).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BackendTaskExists(backendTask.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(true));
        }
Esempio n. 4
0
        private async Task <BackendTask> SendVmRequest(Adapter adapter, Vm newVm, string username)
        {
            var response = await EasyAdmin.Services.VMware.VmService.RequestVm(adapter, newVm);

            if (!response.isSuccess)
            {
                _logger.LogError(string.Format("{0}:{1}", response.errorCode, response.errorMessage));
            }

            var task = response.resultObject;

            task.IsVisible         = true;
            task.UserId            = username;
            task.AdapterId         = adapter.Id;
            task.Status            = "Запрошено создание ВМ";
            task.RelatedEntityType = typeof(Vm).ToString();
            task.RelatedEntityName = newVm.FullName;
            _context.BackendTasks.Add(response.resultObject);
            await _context.SaveChangesAsync();

            return(task);
        }
Esempio n. 5
0
        public async Task <IActionResult> PutAdapter(int id, Adapter adapter)
        {
            if (adapter == null || id != adapter.Id)
            {
                return(BadRequest());
            }
            if (adapter.Credentials.Id == 0)
            {
                Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry <Credentials> a = _context.Credentials.Add(adapter.Credentials);

                Credentials oldCredentials = _context.Credentials.Where(x => x.Id == adapter.CredetialsId).SingleOrDefault();
                if (oldCredentials != null)
                {
                    _context.Credentials.Remove(oldCredentials);
                }

                adapter.CredetialsId = a.Entity.Id;
            }


            _context.Entry(adapter).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AdapterExists(id))
                {
                    return(NotFound());
                }

                throw;
            }

            return(NoContent());
        }