public Guid AddNewCompany(AddComanyViewModel addComanyViewModel)
        {
            if (addComanyViewModel is null)
            {
                throw new ArgumentNullException("Object Null");
            }
            try
            {
                Guid    companyToken = Guid.NewGuid();
                Company company      = new Company()
                {
                    Email        = addComanyViewModel.email,
                    Name         = addComanyViewModel.name,
                    Description  = addComanyViewModel.description,
                    NickName     = addComanyViewModel.nickName,
                    BusinessRate = 0,
                    FiscalId     = addComanyViewModel.fiscalId,
                    Token        = companyToken,
                    Password     = addComanyViewModel.password
                };

                _context.Company.Add(company);

                Address address = new Address()
                {
                    AddressNumber = int.Parse(addComanyViewModel.addressNumber),
                    Cep           = addComanyViewModel.cep,
                    Street        = addComanyViewModel.street,
                    City          = addComanyViewModel.city,
                    Geolocation   = addComanyViewModel.geolocation,
                    Company       = company
                };

                _context.Address.Add(address);

                Contact contact = new Contact()
                {
                    MobilePhone  = int.Parse(addComanyViewModel.mobilePhone),
                    Phone        = int.Parse(addComanyViewModel.phone),
                    Whatsapp     = int.Parse(addComanyViewModel.whatsapp),
                    LocationCode = int.Parse(addComanyViewModel.LocationCode),
                    Company      = company
                };

                _context.Contact.Add(contact);

                _context.SaveChanges();

                return(companyToken);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Ejemplo n.º 2
0
        public IActionResult AddCompany(AddComanyViewModel addComanyViewModel)
        {
            try
            {
                var token = _companyRepository.AddNewCompany(addComanyViewModel);
                return(Ok(token));
            }
            catch (Exception e)
            {
                return(Ok(e));

                throw;
            }
        }
 public void UpdateCompany(AddComanyViewModel addComanyViewModel)
 {
     if (addComanyViewModel is null)
     {
         throw new ArgumentNullException("Object Null");
     }
     try
     {
     }
     catch (Exception e)
     {
         throw e;
     }
 }