public async Task <IActionResult> Create(int?fromProject, CompaniesCreateEditViewModel vm)
        {
            if (ModelState.IsValid)
            {
                await _context.Companies.AddAsync(vm.Company);

                //_context.Add(company);
                await _context.SaveChangesAsync();

                if (fromProject != null)
                {
                    return(RedirectToAction("Details", "Projects", new { id = fromProject }));
                }
                return(RedirectToAction(nameof(Index)));
            }

            vm.CompanyFieldOfActivitesSelectList = new SelectList(_context.CompanyFieldOfActivities
                                                                  .Include(i => i.ActivityName)
                                                                  .ThenInclude(i => i.Translations)
                                                                  , nameof(CompanyFieldOfActivity.CompanyFieldOfActivityId)
                                                                  , nameof(CompanyFieldOfActivity.ActivityName));

            vm.CompanyTypesSelectList = new SelectList(_context.CompanyTypes
                                                       .Include(i => i.CompanyTypeName)
                                                       .ThenInclude(i => i.Translations)
                                                       , nameof(CompanyType.CompanyTypeId)
                                                       , nameof(CompanyType.CompanyTypeName));

            //ViewData["CompanyFieldOfActivityId"] = new SelectList(_context.CompanyFieldOfActivities, "CompanyFieldOfActivityId", IsEnglish() ? "ActivityName" : "ActivityNameEst", company.CompanyFieldOfActivityId);
            //ViewData["CompanyTypeId"] = new SelectList(_context.CompanyTypes, "CompanyTypeId", IsEnglish() ? "CompanyTypeName" : "CompanyTypeNameEst", company.CompanyTypeId);
            return(View(vm));
        }
        // GET: Companies/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var company = await _context.Companies.FindAsync(id);

            if (company == null)
            {
                return(NotFound());
            }
            var vm = new CompaniesCreateEditViewModel();

            vm.Company = company;
            vm.CompanyFieldOfActivitesSelectList = new SelectList(_context.CompanyFieldOfActivities
                                                                  .Include(i => i.ActivityName)
                                                                  .ThenInclude(i => i.Translations)
                                                                  , nameof(CompanyFieldOfActivity.CompanyFieldOfActivityId)
                                                                  , nameof(CompanyFieldOfActivity.ActivityName));

            vm.CompanyTypesSelectList = new SelectList(_context.CompanyTypes
                                                       .Include(i => i.CompanyTypeName)
                                                       .ThenInclude(i => i.Translations)
                                                       , nameof(CompanyType.CompanyTypeId)
                                                       , nameof(CompanyType.CompanyTypeName));

            return(View(vm));
        }
        public async Task <IActionResult> Edit(int id, CompaniesCreateEditViewModel vm)
        {
            if (id != vm.Company.CompanyId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Companies.Update(vm.Company);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CompanyExists(vm.Company.CompanyId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Details", new { id }));
            }
            vm.CompanyFieldOfActivitesSelectList = new SelectList(_context.CompanyFieldOfActivities
                                                                  .Include(i => i.ActivityName)
                                                                  .ThenInclude(i => i.Translations)
                                                                  , nameof(CompanyFieldOfActivity.CompanyFieldOfActivityId)
                                                                  , nameof(CompanyFieldOfActivity.ActivityName));

            vm.CompanyTypesSelectList = new SelectList(_context.CompanyTypes
                                                       .Include(i => i.CompanyTypeName)
                                                       .ThenInclude(i => i.Translations)
                                                       , nameof(CompanyType.CompanyTypeId)
                                                       , nameof(CompanyType.CompanyTypeName));

            return(View(vm));
        }
        // GET: Companies/Create
        public IActionResult Create(int?fromProject)
        {
            var vm = new CompaniesCreateEditViewModel();

            if (fromProject != null)
            {
                vm.fromProject = fromProject;
                //ViewBag.fromProject = fromProject;
            }
            vm.CompanyFieldOfActivitesSelectList = new SelectList(_context.CompanyFieldOfActivities
                                                                  .Include(i => i.ActivityName)
                                                                  .ThenInclude(i => i.Translations)
                                                                  , nameof(CompanyFieldOfActivity.CompanyFieldOfActivityId)
                                                                  , nameof(CompanyFieldOfActivity.ActivityName));

            vm.CompanyTypesSelectList = new SelectList(_context.CompanyTypes
                                                       .Include(i => i.CompanyTypeName)
                                                       .ThenInclude(i => i.Translations)
                                                       , nameof(CompanyType.CompanyTypeId)
                                                       , nameof(CompanyType.CompanyTypeName));
            return(View(vm));
        }