Example #1
0
        public async Task <IActionResult> Create(CustomerAddInputModel input)
        {
            var user = await this.userManager.GetUserAsync(this.User);

            if (user.OrganizationId == null)
            {
                return(this.RedirectToAction("Create", "Organizations"));
            }

            foreach (var email in input.Emails)
            {
                if (!this.validationService.IsAvailableEmail(user.Id, email.Email))
                {
                    ModelState.AddModelError("", $"This {email.Email} is already taken by other customer in your list");
                }
            }

            foreach (var phone in input.Phones)
            {
                if (!this.validationService.IsAvailablePhone(user.Id, phone.Phone))
                {
                    ModelState.AddModelError("", $"This {phone.Phone} is already taken by other customer in your list");
                }
            }

            if (!this.ModelState.IsValid)
            {
                return(this.View("_CreateCustomer", input));
            }

            await this.customersService.CreateAsync(input, user.Id, user.OrganizationId, false);

            return(this.RedirectToAction("Index"));
        }
Example #2
0
        public async Task <IActionResult> Create(CustomerAddInputModel input, string organizationId)
        {
            var user = await this.userManager.GetUserAsync(this.User);

            if (user != null)
            {
                return(NotFound());
            }

            var userId = this.usersService.GetUserIdByOrganizationId(organizationId);

            await this.customersService.CreateAsync(input, userId, organizationId, true);

            this.TempData["Successful"] = "Your data sent successful";
            this.TempData[SentData]     = true;

            return(this.RedirectToAction("Successful"));
        }
Example #3
0
        public async Task <int> CreateAsync(CustomerAddInputModel input, string userId, string organizationId, bool isTemporary)
        {
            var address = await this.addressesService.CreateAsync(input.Address.Country, input.Address.City,
                                                                  input.Address.Street, input.Address.ZipCode);

            var customer = new Customer
            {
                Address        = address,
                UserId         = userId,
                OrganizationId = organizationId,
                Title          = input.Title,
                FirstName      = input.FirstName,
                MiddleName     = input.MiddleName,
                LastName       = input.LastName,
                JobTitle       = input.JobTitle,
                AdditionalInfo = input.AdditionalInfo,
                IsTemporary    = isTemporary,
            };

            await this.customersRepository.AddAsync(customer);

            await this.customersRepository.SaveChangesAsync();


            foreach (var email in input.Emails)
            {
                var emailAddress = await this.emailsService.CreateAsync(email.Email, email.EmailType, customer.Id);

                customer.Emails.Add(emailAddress);
            }

            foreach (var phone in input.Phones)
            {
                var phoneNumber = await this.phonesServices.CreateAsync(phone.Phone, phone.PhoneType, customer.Id);

                customer.Phones.Add(phoneNumber);
            }


            return(customer.Id);
        }