public IActionResult EditCompany([FromBody] CompaniesViewModel company)
 {
     try
     {
         if (company.CompanyId.HasValue)
         {
             if (company.UserId == IdentityHelper.GetUserId(HttpContext))
             {
                 _companiesRepository.UpdateCompany(company);
                 return(Ok());
             }
             else
             {
                 return(Unauthorized());
             }
         }
         else
         {
             return(BadRequest());
         }
     }
     catch (Exception ex)
     {
         return(BadRequest());
     }
 }
        public async Task <ActionResult> UpdateAsync([FromBody] Company newCompany, long id)
        {
            var company = await _companies.GetCompanyByIdAsync(id);

            if (company == null)
            {
                return(NotFound());
            }
            company.Name = newCompany.Name;
            company.EstablishmentYear = newCompany.EstablishmentYear;
            if (newCompany.Employees.Any())
            {
                company.Employees = _mapper.Map <IEnumerable <EfDataAccess.Entities.Employee> >(newCompany.Employees);
            }
            _companies.UpdateCompany(company);

            await _companies.SaveChangesAsync();

            return(Ok());
        }
Exemplo n.º 3
0
        public Companies InsertUpdateCompany(Companies _companyObj)
        {
            Companies result = null;

            try
            {
                if ((_companyObj.Code) == "" || _companyObj.Code == null)
                {
                    result = _companiesRepository.InsertCompany(_companyObj);
                }
                else
                {
                    result = _companiesRepository.UpdateCompany(_companyObj);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(result);
        }
 public async Task ExecuteAsync(Company company)
 {
     await _companiesRepository.UpdateCompany(company);
 }
Exemplo n.º 5
0
 public async Task UpdateCompany(UpdateCompanyCommand command)
 {
     await _companiesRepository.UpdateCompany(command);
 }