Пример #1
0
 public async Task Post(int value)
 {
     if (_companyManager.Read(value) == null)
     {
         await _companyManager.Create(value);
     }
 }
Пример #2
0
        public async Task <CompanyDto> CreateCompany(CompanyDto dto)
        {
            var newEntity = _mapper.Map <CompanyEntity>(dto);

            newEntity.Address  = new CompanyAddressEntity();
            newEntity.Settings = new CompanySettingsEntity();

            var entity = await _companyManager.Create(newEntity);

            return(_mapper.Map <CompanyDto>(entity));
        }
Пример #3
0
        public IActionResult Post([FromBody] OrganizationRequestMessage organization)
        {
            if (!ModelState.IsValid)
            {
                var errors = new List <string>();
                foreach (var key in ModelState.Keys)
                {
                    if (ModelState[key].Errors.Any())
                    {
                        errors.Add($"{key}: {string.Join(",", ModelState[key].Errors.Select(x => x.ErrorMessage))}");
                    }
                }
                return(new BadRequestObjectResult(new GenericResponseMessage <CompanyBo>
                {
                    StatusCode = HttpStatusCode.BadRequest,
                    Errors = errors
                }));
            }

            var company = _companyManager.GetByEmail(organization.Email);

            if (company != null)
            {
                return(new BadRequestObjectResult(new GenericResponseMessage <CompanyBo>
                {
                    StatusCode = HttpStatusCode.BadRequest,
                    Errors = new[] { "The company already exists" }
                }));
            }

            Guid companyId;

            try
            {
                company   = organization.ToBusinessObject <CompanyBo>();
                companyId = _companyManager.Create(company);
            }
            catch (Exception)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }

            return(new OkObjectResult(new { companyId, Name = company.Name }));
        }
Пример #4
0
        public ActionResult AddCompany(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                return(Json(new { success = false }));
            }

            using (var scope = new TransactionScope())
            {
                var lastMonth = DateTime.Now.AddMonths(-1);

                // Create a new company.
                var newCompany = _companyManager.Create(new Company
                {
                    Name          = name,
                    StartMonth    = lastMonth,
                    TwitterHandle = string.Empty
                });

                // Associate the user to the company.
                _companyManager.AddUser(newCompany.Id, User.Identity.GetUserId <int>(), true);

                // Create a trial subscription
                var subscription = new Subscription {
                    Status = SubscriptionStatus.Trialing
                };
                subscription.AddDays(ConfigUtil.DefaultTrialDuration);
                subscription.CompanyId = newCompany.Id;

                _subscriptionManager.Create(subscription);

                // Complete the scope.
                scope.Complete();
            }

            return(Json(new { success = true }));
        }
Пример #5
0
        public async Task <IActionResult> Create([FromBody] CompanyWithoutIdModel model)
        {
            manager.Create(model);

            return(Ok());
        }
Пример #6
0
        public async Task <CompanyDto> CreateCompany(CompanyGeneralDto dto)
        {
            var entity = await _companyManager.Create(_mapper.Map <CompanyEntity>(dto));

            return(_mapper.Map <CompanyDto>(entity));
        }