public IActionResult AddCompany([FromBody] CompaniesViewModel companyViewModel)
        {
            try{
                Company company = Mapper.Map <CompaniesViewModel, Company>(companyViewModel);

                company.UserId = IdentityHelper.GetUserId(HttpContext);

                company.CreationDate = DateTime.Now;
                company.LastUpdate   = DateTime.Now;
                company.ReminderDate = DateTime.Now.AddMonths(1);

                _companiesRepository.AddCompany(company);

                string content = "A new company listing has been added\n" +
                                 "\nID: " + company.CompanyId +
                                 "\nCompany name: " + company.CompanyName +
                                 "\n\nPlease go to https://capstone1.azurewebsites.net/admin to approve this company listing";
                string subject = "New company listing";

                _emailService.SendToAdmins(subject, content);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }
        public void CreateDefaultCompany()
        {
            _companiesRepository.AddCompany(new Company
            {
                CashBackPercentaje = 0,
                CompanyName        = "SolucionesAR",
                CompanyNickName    = "sar",
                CorporateId        = string.Empty,
                CreatetedAt        = DateTime.Now,
                Enabled            = true,
                UpdatedAt          = DateTime.Now,
            });

            _storesRepository.AddStore(new Store
            {
                CompanyId    = 1,
                CreatetedAt  = DateTime.Now,
                DistrictId   = 1,
                FaxNumber    = string.Empty,
                PhoneNumber1 = string.Empty,
                PhoneNumber2 = string.Empty,
                StoreName    = "SolucionesAR Central",
                UpdatedAt    = DateTime.Now,
            });
        }
        public async Task <ActionResult <long> > CreateAsync([FromBody] CompanyForCreation company)
        {
            var companyEntity = _mapper.Map <EfDataAccess.Entities.Company>(company);

            _companies.AddCompany(companyEntity);

            await _companies.SaveChangesAsync();

            return(CreatedAtRoute("GetCompany",
                                  new { id = companyEntity.Id },
                                  companyEntity));
        }
Ejemplo n.º 4
0
        public IActionResult CreateCompany([FromBody] CreateCompanyDto companyDto)
        {
            if (companyDto == null)
            {
                return(BadRequest());
            }

            Company company = Mapper.Map <Company>(companyDto);

            _companiesRepository.AddCompany(company);

            if (!_companiesRepository.Save())
            {
                return(StatusCode(500, "A problem happened with handling you request."));
            }

            return(CreatedAtRoute("GetById", new { id = company.Id }, company));
        }
Ejemplo n.º 5
0
        public async Task <long> AddCompany(AddCompanyCommand command)
        {
            var company = new Company()
            {
                Name = command.Name,
                EstablishmentYear = command.EstablishmentYear,
                Employees         = command.Employees.Select(e =>
                {
                    var employee = new Employee()
                    {
                        DateOfBirth = e.DateOfBirth,
                        FirstName   = e.FirstName,
                        LastName    = e.LastName,
                        JobTitle    = JobTitleHelper.GetEnumFromString(e.JobTitle)
                    };
                    return(employee);
                }).ToList()
            };

            return(await _companiesRepository.AddCompany(company));
        }
 private void AddCompany(Company company)
 {
     company.CreatetedAt = DateTime.Now;
     company.UpdatedAt   = DateTime.Now;
     _companiesRepository.AddCompany(company);
 }
Ejemplo n.º 7
0
        public async Task <IActionResult> Add(AddEditCompanyViewModel model)
        {
            await _companiesRep.AddCompany(model);

            return(RedirectToAction("Index"));
        }