Ejemplo n.º 1
0
        public async Task <ResultData <Office> > CreateNewOffice(OfficeInputModel inputModel)
        {
            if (string.IsNullOrEmpty(inputModel.Country) || string.IsNullOrEmpty(inputModel.Street) || string.IsNullOrEmpty(inputModel.City) || inputModel.StreetNumber == 0)
            {
                return(new ResultData <Office>(IncompleteOfficeAddressMessage, false, null));
            }

            Office office = new Office
            {
                Country      = inputModel.Country,
                City         = inputModel.City,
                Street       = inputModel.Street,
                StreetNumber = inputModel.StreetNumber,
                CompanyId    = inputModel.CompanyId
            };

            Company company = await this.companyRepository.GetCompanyWithOfficesById(inputModel.CompanyId);

            if (company.Offices.Count() == 0)
            {
                office.IsHeadquarters = true;
            }

            await this.officeRepository.CreateNewOffice(office);

            return(new ResultData <Office>(OfficeCreatedMessage, true, office));
        }
Ejemplo n.º 2
0
        public ResultData <OfficeInputModel> CreateOfficeInputModel(int companyId)
        {
            if (companyId == 0)
            {
                return(new ResultData <OfficeInputModel>(CompanyNotFoundMessage, false, null));
            }

            OfficeInputModel inputModel = new OfficeInputModel
            {
                CompanyId = companyId
            };

            return(new ResultData <OfficeInputModel>(OfficeInputModelCreatedMessage, true, inputModel));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create(OfficeInputModel inputModel)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(inputModel));
            }

            var result = await this.officeService.CreateNewOffice(inputModel);

            if (!result.Success)
            {
                return(this.View(inputModel));
            }

            return(this.RedirectToAction(nameof(Details), new { id = result.Data.Id }));
        }