Exemple #1
0
        public async Task <bool> AddAsync(CompanyDto dto)
        {
            ValidatorCompany.ValidateCompanyNameIfIsNull(dto.Name);

            var company = await this.context.Companies
                          .Include(office => office.Offices)
                          .FirstOrDefaultAsync(name => name.Name == dto.Name && name.IsDeleted == false);

            var validate = ValidatorCompany.ValidateCompanyIfExist(company);

            var countCompany = await this.context.Companies
                               .Where(name => name.Name == dto.Name && name.IsDeleted == false)
                               .CountAsync();

            if (validate || countCompany < existCompany)
            {
                var newCompany = new Company
                {
                    Name         = dto.Name,
                    CreationDate = dto.CreationDate
                };
                await this.context.Companies.AddAsync(newCompany);

                await this.context.SaveChangesAsync();

                return(true);
            }
            return(false);
        }
Exemple #2
0
        public async Task EditAsync(CompanyDto dto)
        {
            ValidatorCompany.ValidateCompanyNameIfIsNull(dto.Name);

            var company = await this.context.Companies.FindAsync(dto.Id);

            company.Name         = dto.Name;
            company.CreationDate = dto.CreationDate;

            await this.context.SaveChangesAsync();
        }