Exemplo n.º 1
0
 public async Task <ActionResult <Company> > AddNewCompany([FromBody] Company newCompany)
 {
     if (_companyService.Add(newCompany))
     {
         var company = _companyService.GetInserted();
         // TODO: da se vraca kompanija koja je dodat kao objekat
         return(Created("", company));
     }
     return(Forbid("Nemoguce uneti novu kompaniju!"));
 }
Exemplo n.º 2
0
        public override async Task <UpsertCompanyResponse> AddCompany(CompanyRequest request, ServerCallContext context)
        {
            PredlaganjeSaradnjeIRC.Data.Model.Company company =
                _mapper.Map <PredlaganjeSaradnjeIRC.Data.Model.Company>(request);

            PredlaganjeSaradnjeIRC.Data.Model.Location location =
                _mapper.Map <PredlaganjeSaradnjeIRC.Data.Model.Location>(request.Location);

            PredlaganjeSaradnjeIRC.Data.Model.Contact contact =
                _mapper.Map <PredlaganjeSaradnjeIRC.Data.Model.Contact>(request.Contact);

            company.Locations = new List <PredlaganjeSaradnjeIRC.Data.Model.Location> {
                location
            };
            company.Contacts = new List <PredlaganjeSaradnjeIRC.Data.Model.Contact> {
                contact
            };

            if (_companyService.Add(company))
            {
                var createdCompany = _companyService.GetInserted();

                _logger.LogInformation("company created");

                return(new UpsertCompanyResponse
                {
                    Status = StatusCode.Ok,
                    Message = "Kompanija je kreirana",
                    Company = _mapper.Map <CompanyResponse>(createdCompany),
                    Contact = _mapper.Map <ContactResponse>(createdCompany.Contacts.LastOrDefault()),
                    Location = _mapper.Map <LocationResponse>(createdCompany.Locations.LastOrDefault())
                });
            }

            _logger.LogError("company can't be created");
            return(new UpsertCompanyResponse
            {
                Status = StatusCode.Error,
                Message = "Nije moguce kreirati kompaniju"
            });
        }