Пример #1
0
        public async Task <IActionResult> Index(OrderViewModel orderViewModel)
        {
            if (ModelState.IsValid)
            {
                var items = await _shoppingCartService.GetShoppingCartItems(Session.ShoppingCartId);

                var customer = await _customerService.AddCustomerAsync(_mapper.Map <Customer>(orderViewModel));

                var order = new Order()
                {
                    Amount     = _shoppingCartService.GetShoppingCartTotal(Session.ShoppingCartId),
                    CustomerId = customer.Id,
                    Date       = DateTime.Now
                };
                await _orderService.AddOrderAsync(order);

                foreach (var item in items)
                {
                    var orderItem = new OrderItem()
                    {
                        OrderId            = order.Id,
                        ProductItemId      = item.ProductItemId,
                        ComboMealId        = item.ComboMealId,
                        CustomizeProductId = null,
                        Quantity           = item.Quantity
                    };
                    await _orderItemService.AddOrderItemAsync(orderItem);
                }

                await _shoppingCartService.ClearCart(Session.ShoppingCartId);

                return(RedirectToAction("OrderComplete"));
            }
            return(View(orderViewModel));
        }
        private async void OnSave()
        {
            _statusMessage = string.Empty;

            UpdateCustomer(Customer, _editingCustomer);

            if (EditMode)
            {
                bool updateStatus = await _customerService.UpdateCustomerAsync(_editingCustomer);

                if (updateStatus)
                {
                    _statusMessage = "Customer was updated successfully!";
                }
                else
                {
                    _statusMessage = "Failed to update customer! :-(";
                }
            }
            else
            {
                bool updateStatus = await _customerService.AddCustomerAsync(_editingCustomer);

                if (updateStatus)
                {
                    _statusMessage = "Customer was added successfully!";
                }
                else
                {
                    _statusMessage = "Failed to add customer! :-(";
                }
            }

            Done();
        }
Пример #3
0
        public async Task <ActionResult> CreateCustomerAsync(CustomerCreateDTO customerDto)
        {
            var newCustomer     = _mapper.Map <Customer>(customerDto);
            var createdCustomer = await _customerService.AddCustomerAsync(newCustomer);

            return(Ok(createdCustomer));
        }
Пример #4
0
        public async Task <ActionResult <Customer> > CreateCustomer(Customer customer)
        {
            var selectedCustomer = customer;
            var result           = await _customerService.AddCustomerAsync(customer);

            return(result);
        }
Пример #5
0
        public async Task <ActionResult> MakeOrder(Customer customer)
        {
            #region До использования UnitOfWork
            //SelectList waters = new SelectList(db.Waters, "Id", "WaterName");
            //ViewBag.Waters = waters;
            //if (ModelState.IsValid)
            //{
            //    // добавляем информацию о дате покупки в БД
            //    customer.Date = DateTime.Now;
            //    db.Customers.Add(customer);
            //    db.SaveChanges();
            //    return RedirectToAction("Index");
            //}
            //return View(customer);
            #endregion
            SelectList waters = new SelectList(_waterContext.Waters, "Id", "WaterName");
            ViewBag.Waters = waters;
            if (ModelState.IsValid)
            {
                // добавляем информацию о дате покупки в БД
                customer.Date = DateTime.Now;
                await _customerService.AddCustomerAsync(customer);

                return(RedirectToAction("Index"));
            }
            return(View(customer));
        }
 public async Task <IActionResult> Post([FromBody] CustomerModel customer)
 {
     if (ModelState.IsValid)
     {
         return(Ok(await _customerService.AddCustomerAsync(customer)));
     }
     return(BadRequest("Invalid customer info"));
 }
        public async Task Register_Success_ReturnsOkResponse()
        {
            _customerService.AddCustomerAsync(null).ReturnsForAnyArgs(new RegisterResponse());

            var response = await _customerController.Register(null) as ObjectResult;

            Assert.That(response.StatusCode, Is.EqualTo(StatusCodes.Status200OK));
        }
        public async Task <IActionResult> AddCustomer([Required] string name,
                                                      [Range(1, 999)] int age,
                                                      Country country)
        {
            var newCustomer = new NewCustomer(name, age, country);
            await _customerService.AddCustomerAsync(newCustomer);

            return(Ok());
        }
Пример #9
0
        public async Task <IActionResult> OnPostAsync(Customer customer)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            await customerService.AddCustomerAsync(customer);

            return(RedirectToPage("GetAllCustomers"));
        }
Пример #10
0
        public async Task <IActionResult> Create([Bind("Id,Name,FirstName")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                await _customerService.AddCustomerAsync(customer);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
        public async Task <ActionResult <Customer> > CreateCustomer()
        {
            var customer = new Customer
            {
                Age       = 30,
                FirstName = "Wolfgang",
                LastName  = "Ofner"
            };

            return(await _customerService.AddCustomerAsync(customer));
        }
Пример #12
0
        public async Task <IActionResult> Add([FromForm] AddCustomerViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            await customerService.AddCustomerAsync(model);

            return(RedirectToAction("Index"));
        }
Пример #13
0
        public async Task <IActionResult> AddCustomer([FromForm] Customer customer)
        {
            var a = HttpContext.Request;
            var b = Request.Form["customer"];

            if (ModelState.IsValid)
            {
                return(await _customerService.AddCustomerAsync(customer) ? Ok() : StatusCode(500));
            }
            return(BadRequest());
        }
Пример #14
0
        public async Task <IActionResult> AddCustomers([FromBody] Customer customer)
        {
            var createdCustomer = await _customerService.AddCustomerAsync(customer);

            if (createdCustomer != null)
            {
                return(CreatedAtRoute("GetCustomer", new { id = customer.Id }, createdCustomer));
            }

            return(BadRequest("Customer could not created"));
        }
Пример #15
0
        public async Task <ActionResult <Int32ServiceResult> > CreateCustomer([FromBody] CreateCustomerRequest request)
        {
            var result = await _customerService.AddCustomerAsync(request);

            if (result.IsSuccess)
            {
                return(Ok(result));
            }

            return(BadRequest(ServiceResult.Error(result.Message)));
        }
        public async Task <ActionResult> CreateAsync([Bind("Id,Name,Contact,Email")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                customer.Id = Guid.NewGuid().ToString();
                await _customerService.AddCustomerAsync(customer);

                return(RedirectToAction("Index"));
            }

            return(View(customer));
        }
Пример #17
0
        public async Task <IActionResult> CreateNewUser([FromBody] CustomerCreateModel model)
        {
            try
            {
                var result = await customerService.AddCustomerAsync(model);

                return(Ok(result));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #18
0
        private async void BtnAdd_Click(object sender, EventArgs e)
        {
            var newCustomer = new Customer()
            {
                Name    = txtName.Text,
                Contact = txtContact.Text,
                Email   = txtEmail.Text
            };

            var result = _customerService.AddCustomerAsync(newCustomer);

            await LoadCustomers();
        }
Пример #19
0
        public async Task <ActionResult> Create(CustomerViewModel customerViewModel)
        {
            var result = await _customerServ.AddCustomerAsync(customerViewModel.ToModel());

            if (result)
            {
                ViewBag.Result = "Operacija sėkiminga";
            }
            else
            {
                ViewBag.Result = "Operacija nesėkminga";
            }
            return(View());
        }
        public async Task <IActionResult> Create([FromBody] CreateCustomer Request)
        {
            try
            {
                if (Request == null)
                {
                    return(BadRequest(new ErrorResponse(new ErrorModel {
                        Message = "Request cannot be null"
                    })));
                }


                if (Request.isAffiliate == true && Request.isEmployee == true)
                {
                    return(BadRequest(new ErrorResponse(new ErrorModel {
                        Message = "You Cannot Be an Affiliate And an Employee Kindly Pick one RoLe"
                    })));
                }
                var model = ToDomainModel(Request);
                var exist = await customerService.customerExist(model.CustomerId);

                if (!exist)
                {
                    var create = await customerService.AddCustomerAsync(model); if (!create)
                    {
                        return(BadRequest(new ErrorResponse(new ErrorModel {
                            Message = "Unable to create Customer"
                        })));
                    }

                    var baseUrl     = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}";
                    var locationUri = baseUrl + "/" + ApiRoutes.Customers.Get.Replace("{customerId}", model.CustomerId.ToString());
                    var response    = ToOutputModel(model);

                    return(Created(locationUri, response));
                }
                else
                {
                    return(Ok("Customer already exist"));
                }
            }
            catch (Exception ex)
            {
                logger.LogError(ex.Message + ":" + ex.StackTrace);
                throw;
            }
        }
Пример #21
0
        public async Task <CustomerResult> AddCustomer(
            [Inject] ICustomerService service,
            AddNewCustomerParams input)
        {
            var customerInput = input.newCustomer.Value;
            var customer      = new Customer {
                Name      = customerInput.newName,
                BirthDate = customerInput.BirthDate,
                Id        = customerInput.Id ?? Guid.NewGuid()
            };
            await service.AddCustomerAsync(customer);

            return(new CustomerResult
            {
                Customer = new CustomerGraph(customer),
            });
        }
Пример #22
0
        public async Task <IActionResult> AddCustomer(CustomerAddRequest customerRequest)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    await _customerService.AddCustomerAsync(customerRequest);

                    return(RedirectToAction("Index", "Customer"));
                }

                return(View(customerRequest));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Пример #23
0
        public async Task <ActionResult> AddCustomer(CustomerModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            string      userId      = User.Identity.GetUserId();
            CustomerDto customerDto = mapper.Map <CustomerModel, CustomerDto>(model);

            customerDto.UserId    = userId;
            customerDto.IsActive  = true;
            customerDto.IsBlocked = false;
            OperationDetails operationDetails = await customerService.AddCustomerAsync(customerDto);

            if (operationDetails.Succedeed)
            {
                return(RedirectToAction("Index", "Customer", userId));
            }
            ModelState.AddModelError(operationDetails.Property, operationDetails.Message);
            return(View(model));
        }
Пример #24
0
        public async Task <ActionResult> Post([FromBody] AddCustomerRequest request)
        {
            /*
             * Assumption: Errors that I return from here are not really in a proper structure, in order to handle more complex case, I will need to define a proper json for Error return
             * For example:
             * {
             * "errors": [
             *  {
             *    "code": "001",
             *    "message": "some error here"
             *  },
             *  {
             *    "code": "002",
             *    "message": "some error here"
             *  }
             * ]
             * }
             */
            var validator        = new AddCustomerRequestValidator();
            var validationResult = validator.Validate(request);

            if (!validationResult.IsValid)
            {
                return(BadRequest(new { ErrorMessage = validationResult.ErrorMessage }));
            }

            var customerEntity = _mapper.Map <CustomerEntity>(request);

            var result = await _customerService.AddCustomerAsync(customerEntity);

            if (!result.IsSuccessful)
            {
                return(BadRequest(new { ErrorMessage = result.ErrorMessage }));
            }

            var customer = _mapper.Map <Customer>(result.Result);

            return(Created($"{Request.Path}/{result.Result.Id}", customer));
        }
Пример #25
0
        public async Task <ActionResult> Post([FromBody] Customer customer)
        {
            await _customerService.AddCustomerAsync(customer);

            return(Ok());
        }
Пример #26
0
        public async Task <ActionResult <Tbl_Customer> > CreateCustomer(Tbl_Customer tbl_Customer)
        {
            var result = await _customerService.AddCustomerAsync(tbl_Customer);

            return(CreatedAtAction("GetCustomer", new { id = result.id }, result));
        }
Пример #27
0
        public async Task <IHttpActionResult> PostCreateCustomersAsync(CustomerDto customerDto)
        {
            if (customerDto == null)
            {
                //return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "customer cannot be null");
                return(BadRequest("Customer cannot be null"));
            }

            Customer customer = new Customer();

            //Address address;
            try
            {
                customer = _mappingEngine.Map <CustomerDto, Customer>(customerDto);

                string userId = User.Identity.GetUserId();
                customer.ApplicationUserId = userId;

                //var newcustomer = new Customer
                //{
                //    FirstName = customer.FirstName,
                //    Surname = customer.Surname,
                //    Telephone = customer.Telephone,
                //    MobilePhone = customer.MobilePhone,
                //    Active = true,
                //    ApplicationUserId = userId,
                //};

                //var newAddress = new Address
                //{
                //    AddressLine1 = customer.Address.AddressLine1,
                //    AddressLine2 = customer.Address.AddressLine2,
                //    AddressLine3 = customer.Address.AddressLine3,
                //    AddressLine4 = customer.Address.AddressLine4,
                //    Postcode = customer.Address.Postcode,
                //    Email = customer.Address.Email,
                //};



                //var newcustomer = new Customer
                //{
                //    FirstName = _firstname,
                //    Surname = _surname,
                //    Telephone = _telephone,
                //    MobilePhone = _mobilePhone,
                //    Active = _active,
                //    //InceptionDate = _inceptionDate,
                //    ApplicationUserId = userId,
                //    //Address = newAddress,
                //};
                //var newAddress = new Address
                //{
                //    AddressLine1 = _addressLine1,
                //    AddressLine2 = _addressLine2,
                //    AddressLine3 = _addressLine3,
                //    AddressLine4 = _addressLine4,
                //    Postcode = _postcode,
                //    Email = _email
                //};



                //newcustomer.Address = newAddress;

                customer = await _customerService.AddCustomerAsync(customer);

                //newcustomer = await _customerService.AddCustomerAsync(newcustomer);


                //newAddress.Id = customer.Id;
                //newcustomer.Address = newAddress;

                //await _customerService.UpdateAsync(newcustomer);

                //newcustomer = await _customerService.AddCustomerAsync(newcustomer);
                customerDto.Id = customer.Id;
            }
            catch (Exception ex)
            {
                var errMessage = string.Format("Customer could not be created by user: {1}, errormessage: ", _user, ex.Message);
                //return Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, errMessage);

                var error = new HttpError(errMessage);
                return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, error)));
            }

            var results = CreatedAtRoute("ApiRoute", new { id = customerDto.Id }, customerDto);

            return(results);
            //return Request.CreateResponse(HttpStatusCode.Created, results);
            //return Ok(results);
        }
        public async Task <IActionResult> Add(string name)
        {
            bool didAdd = await customers.AddCustomerAsync(new Customer(name));

            return(Json(didAdd));
        }
Пример #29
0
        public async Task <ActionResult <Customer> > PostCustomer(CustomerViewModel customerViewModel)
        {
            Customer customer = await _customerService.AddCustomerAsync(customerViewModel);

            return(CreatedAtAction("GetCustomer", new { id = customer.Id }, customer));
        }
Пример #30
0
 public async Task AddCustomer([FromBody] Customer customer)
 {
     await _customerService.AddCustomerAsync(customer);
 }