示例#1
0
 public async Task <IActionResult> Edit([Bind("Id,Unp,Name,Address,DirectorsName,DirectorsPhone")] Companies companies)
 {
     try
     {
         await _companies.UpdateAsync(companies);
     }
     catch (DbUpdateConcurrencyException)
     {
         if (!await _companies.ItemExists(x => x.Id == companies.Id))
         {
             return(NotFound());
         }
         throw;
     }
     return(PartialView("Create", companies));
 }
        public async Task <UpdateCompanyResultDto> Update(UpdateCompanyDto updateCompanyDto, int userId)
        {
            var company = await _companiesRepository.GetAsync(updateCompanyDto.Id, userId);

            if (company == null)
            {
                throw new ValidationException(Messages.CompanyDoesNotExist, nameof(Messages.CompanyDoesNotExist));
            }

            company.Address            = updateCompanyDto.Address;
            company.BrandName          = updateCompanyDto.BrandName;
            company.Logo               = updateCompanyDto.Logo;
            company.Name               = updateCompanyDto.Name;
            company.RegistrationNumber = updateCompanyDto.RegistrationNumber;
            company.VatNumber          = updateCompanyDto.VatNumber;

            await _companiesRepository.UpdateAsync(company);

            return(new UpdateCompanyResultDto());
        }
        public async Task <EntityActionOutcome> UpdateEntityAsync(CompanyInputData viewData)
        {
            var validator = new CompanyDataInputValidator();
            var result    = validator.Validate(viewData);

            if (result.IsValid == false)
            {
                return(EntityActionOutcome.UpdateFailed);
            }

            var updateSuccessful = await _repository.UpdateAsync(
                await PopulateEntityDataWithViewData(viewData, viewData.Id));

            if (updateSuccessful == null)
            {
                return(EntityActionOutcome.EntityNotFound);
            }

            return(EntityActionOutcome.Success);
        }