/// <summary>
        /// Добавление данных пользователя в базу данных
        /// </summary>
        /// <param name="user"></param>
        /// <param name="customer"></param>
        /// <returns></returns>
        private async Task AddToDataBase(User user, CustomerDto customer)
        {
            await _customersService.AddAsync(customer);

            await _userManager.AddToRoleAsync(user, "Customer");

            await _signInManager.SignInAsync(user, false);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("FirstName,LastName,Gender,LoyaltyCardId")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                await _customersService.AddAsync(customer);

                return(RedirectToAction("Index"));
            }
            return(View(customer));
        }
Ejemplo n.º 3
0
        public async Task <IHttpActionResult> PostCustomer(CustomerResource resoure)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            CustomerResource result = await _customersService.AddAsync(resoure);

            return(CreatedAtRoute("DefaultApi", new { id = result.Id }, result));
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            await _customersService.AddAsync(Customer);

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 5
0
        public void Add_WhenNewCustomer_ReturnsNotEmptyCollection()
        {
            // Arrange
            var countBefore = _repository.GetAll().ToList().Count;
            var customerDto = new CustomerDto
            {
                Id          = 1,
                Image       = new byte[10],
                FirstName   = "FirstName",
                MiddleName  = "MiddleName",
                LastName    = "LastName",
                PhoneNumber = 123123,
                Bonus       = 123,
                Cash        = 123,
                UserId      = "123",
            };

            // Act
            _customersService.AddAsync(customerDto).GetAwaiter().GetResult();
            var countAfter = _repository.GetAll().ToList().Count;

            // Assert
            Assert.NotEqual(countBefore, countAfter);
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Post([FromBody] Customer customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var success = await _customersService.AddAsync(customer);

            if (!success)
            {
                return(BadRequest());
            }

            return(Ok(customer));
        }
        public async Task <IActionResult> Create([FromBody] CustomerResource customerResource)
        {
            if (customerResource == null)
            {
                customerResource = new CustomerResource();
            }

            var customer = _mapper.Map <CustomerResource, Customer>(customerResource);
            var result   = await _customersService.AddAsync(customer);

            if (!result.Success)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Post([FromBody] Customer customer)
        {
            customer = await _customersService.AddAsync(customer);

            return(CreatedAtAction(nameof(Get), new { id = customer.Id }, customer));
        }
Ejemplo n.º 9
0
        public async Task <CustomerModel> PostAsync(CustomerSave customer)
        {
            var result = await _customersService.AddAsync(customer);

            return(result);
        }