public async Task <LogbookDTO> CreateLogbookAsync(string name, int businessUnitId, string picture) { if (string.IsNullOrEmpty(name)) { throw new ArgumentException(ServicesConstants.NameCanNotBeNullOrEmpty); } businessValidator.IsNameInRange(name); var checkLogbookIfExists = await this.context.Logbooks .FirstOrDefaultAsync(n => n.Name == name); if (checkLogbookIfExists != null) { throw new AlreadyExistsException(ServicesConstants.LogbookAlreadyExists); } var logbook = new Logbook() { Name = name, Picture = picture, BusinessUnitId = businessUnitId }; await this.context.Logbooks.AddAsync(logbook); await this.context.SaveChangesAsync(); var result = await this.context.Logbooks .Include(bu => bu.BusinessUnit) .Include(n => n.Notes) .FirstOrDefaultAsync(x => x.Id == logbook.Id); return(result.ToDTO()); }
public async Task <BusinessUnitDTO> CreateBusinnesUnitAsync(string brandName, string address, string phoneNumber, string email, string information, int businessUnitCategoryId, int townId, string picture) { var checkBrandNameIfExists = await this.context.BusinessUnits .FirstOrDefaultAsync(n => n.Name == brandName); if (checkBrandNameIfExists != null) { throw new AlreadyExistsException(ServicesConstants.BusinessUnitNameAlreadyExists); } businessValidator.IsNameInRange(brandName); businessValidator.IsAddressInRange(address); businessValidator.IsEmailValid(email); businessValidator.IsPhoneNumberValid(phoneNumber); businessValidator.IsDescriptionInRange(information); var businessUnit = new BusinessUnit() { Name = brandName, Address = address, PhoneNumber = phoneNumber, Email = email, Information = information, BusinessUnitCategoryId = businessUnitCategoryId, TownId = townId, Picture = picture }; await this.context.BusinessUnits.AddAsync(businessUnit); await this.context.SaveChangesAsync(); var result = await this.context.BusinessUnits .Include(buc => buc.BusinessUnitCategory) .Include(t => t.Town) .FirstOrDefaultAsync(x => x.Id == businessUnit.Id); return(result.ToDTO()); }