示例#1
0
        public IActionResult Edit(int id, CustomerInputModel customer)
        {
            if (!this.ModelState.IsValid)
            {
                this.ViewData["actionName"] = nameof(Edit);
                return(this.View(customer));
            }

            this.customerService.EditCustomer(id, customer.Name, customer.DateOfBirth);
            return(this.RedirectToAction(nameof(Index), new { id = id }));
        }
 public async Task UpdateCustomer(Guid id, CustomerInputModel model)
 {
     if (ModelState.IsValid)
     {
         await _mediator.Send(new UpdateCustomer()
         {
             Id        = id,
             Honorific = model.Honorific,
             FirstName = model.FirstName,
             LastName  = model.LastName
         });
     }
 }
示例#3
0
        public IActionResult Add(CustomerInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                this.ViewData["actionName"] = nameof(Add);
                return(this.View(model));
            }

            this.customerService.AddCustomer(model.Name, model.DateOfBirth);
            object routeValue = new { order = "descending" };

            return(this.RedirectToAction(nameof(All), routeValue));
        }
示例#4
0
        public CustomerInputModel GetFilters()
        {
            var customer = new CustomerInputModel()
            {
                Cities          = _fieldService.GetDropDownList(_cityService.Get()),
                Classifications = _fieldService.GetDropDownList(_classificationService.Get()),
                Regions         = _fieldService.GetDropDownList(_regionService.Get()),
                Genders         = _fieldService.GetDropDownList(_genderService.Get()),
                Sellers         = _fieldService.GetDropDownList(_sellerService.Get())
            };

            return(customer);
        }
        public async Task OrderDetails_ValidData()
        {
            using (var mock = AutoMock.GetLoose())
            {
                // Setup CustomerInputModel
                var customerInputModel = new CustomerInputModel
                {
                    CustomerId   = "ABC123",
                    EmailAddress = "*****@*****.**"
                };

                // Arrange  Mock CustomerDetail API
                mock.Mock <ICustomerDetailApi>()
                .Setup(x => x.GetUserDetailsAsync(It.IsAny <string>()))
                .ReturnsAsync(new CustomerDetailDto {
                    CustomerId = "ABC123", FirstName = "Mr", LastName = "Blue"
                });

                // Arrange  Mock CustomerDetail API
                mock.Mock <IApiModelConverter>()
                .Setup(x => x.ConvertOrderItemsAndCustomerInfoToOrderDeliveryModel(It.IsAny <List <OrderItem> >(),
                                                                                   It.IsAny <CustomerDetailDto>()))
                .Returns(new OrderDeliveryModel()
                {
                    Customer = new CustomerModel()
                    {
                        FirstName = "Mr",
                        LastName  = "Blue"
                    },
                    Order = new OrderModel()
                    {
                        OrderNumber = 500
                    }
                });

                // Create Controller
                var controller = mock.Create <OrderDeliveryController>();

                // Act
                var actionResult = await controller.OrderDetails(customerInputModel);

                var contentResult = actionResult as OkNegotiatedContentResult <OrderDeliveryModel>;

                // Assert
                Assert.IsNotNull(contentResult);
                Assert.IsNotNull(contentResult.Content);
                Assert.AreEqual("Mr", contentResult.Content.Customer.FirstName);
                Assert.AreEqual("Blue", contentResult.Content.Customer.LastName);
                Assert.AreEqual(500, contentResult.Content.Order.OrderNumber);
            }
        }
        public ActionResult Index(CustomerInputModel customerInputModel)
        {
            // Normal stuff here, create a command and send it on the command bus
            // TODO: Go to the Sample.JesseHouse.Processing project's EndpointConfiguration class next
            var createCustomerCommand = new CreateCustomerCommand();

            createCustomerCommand.CustomerId = Guid.NewGuid();
            createCustomerCommand.FirstName  = customerInputModel.FirstName;
            createCustomerCommand.LastName   = customerInputModel.LastName;

            commandBus.Send(createCustomerCommand);

            return(RedirectToAction("Index"));
        }
示例#7
0
        public IActionResult Index(CustomerInputModel customerInputModel)
        {
            _isAuthenticated = HttpContext.Session.IsAuthenticated();

            var userSession = HttpContext.Session.GetUserSession();

            ViewData["IsAdmin"]  = userSession?.IsAdmin ?? false;
            ViewData["LoggedIn"] = _isAuthenticated;

            ViewData["Messages"] = null;

            if (!(userSession?.IsAdmin ?? false))
            {
                customerInputModel.SellerId = userSession.Id;
            }

            var customerFilter = _mapper.Map <CustomerFilter>(customerInputModel);

            var result = _customerService.Get(customerFilter);

            ModelState.Clear();

            if (!result.Success)
            {
                ViewData["Messages"] = result.Messages;
            }
            else
            {
                ViewData["Customer"] = _mapper.Map <IEnumerable <CustomerViewModel> >(result.Data);

                var customer = GetFilters();
                customerInputModel.Cities          = customer.Cities;
                customerInputModel.Classifications = customer.Classifications;

                if (customerInputModel.CityId.HasValue)
                {
                    customerInputModel.Regions = GetRegionsByCityId(customerInputModel.CityId.Value);
                }
                else
                {
                    customerInputModel.Regions = customer.Regions;
                }

                customerInputModel.Genders = customer.Genders;
                customerInputModel.Sellers = customer.Sellers;
            }

            return(View(customerInputModel));
        }
        public async Task <IActionResult> Create(CustomerInputModel model)
        {
            // Write here your implementation before call IntegrationService

            var result = await this._integrationService.Integrate(new Protos.CustomerIntegrationRequest
            {
                Id   = new Guid("b292e25e-10d3-4877-b5b9-6c7cc0108f5c").ToString("D"),
                Name = model.Name
            });

            return(Ok(new
            {
                Succeded = result.Succeeded
            }));
        }
示例#9
0
        public async Task <ActionResult> Post([FromBody] CustomerInputModel customer)
        {
            try
            {
                CustomerModel customerModel = (CustomerModel)customer;
                await _customerBusinessLayer.AddCustomerAsync(customerModel);

                return(Accepted());
            }
            catch (ArgumentException ex)
            {
                _logger.LogError(ex, "Error adding customer");
                return(BadRequest());
            }
        }
示例#10
0
        public ActionResult <BaseResult <List <CustomerViewModel> > > Get([FromQuery] CustomerInputModel inputModel)
        {
            CustomerFilter customer = null;

            if (inputModel != null)
            {
                customer = _mapper.Map <CustomerFilter>(inputModel);
            }

            var result = _customerService.GetWithAllRelations(customer);

            if (result.Success)
            {
                var resultMap = _mapper.Map <List <CustomerViewModel> >(result.Data);

                return(BaseResult <List <CustomerViewModel> > .OK(resultMap));
            }

            return(BaseResult <List <CustomerViewModel> > .NotOK(result.Messages));
        }
        public CustomerDto CreateCustomer(CustomerInputModel customer)
        {
            var newCustomer = _dbContext.Customers.Add(new Customer {
                Name     = customer.Name,
                Email    = customer.Email,
                Password = customer.Password
            }).Entity;

            _dbContext.SaveChanges();

            var dto = new CustomerDto
            {
                Id    = newCustomer.Id,
                Name  = newCustomer.Name,
                Email = newCustomer.Email
            };

            _mbClient.PublishMessage(_routingKey, dto);

            return(dto);
        }
示例#12
0
        public async Task CreateCustomer(CustomerInputModel input)
        {
            var contactPerson = new ContactPerson
            {
                FirstName     = input.FirstName,
                LastName      = input.LastName,
                PreferredName = input.PreferredName,
                PhoneNumber   = input.PhoneNumber,
                EmailAddress  = input.EmailAddress,
            };

            var customer = new Customer
            {
                CompanyName   = input.CompanyName,
                EIK           = input.EIK,
                City          = input.City,
                AddressLine1  = input.AddressLine1,
                AddressLine2  = input.AddressLine2,
                PhoneNumber   = input.CompanyPhoneNumber,
                ContactPerson = contactPerson,
            };

            if (input.IsTheSameDeliveryAddress)
            {
                customer.DeliveryCity         = customer.City;
                customer.DeliveryAddressLine1 = customer.AddressLine1;
                customer.DeliveryAddressLine2 = customer.AddressLine2;
            }
            else
            {
                customer.DeliveryCity         = input.City;
                customer.DeliveryAddressLine1 = input.AddressLine1;
                customer.DeliveryAddressLine2 = input.AddressLine2;
            }

            await this.customerRepository.AddAsync(customer);

            await this.customerRepository.SaveChangesAsync();
        }
        public async Task OrderDetails_InvalidEmailAddress()
        {
            using (var mock = AutoMock.GetLoose())
            {
                // Setup CustomerInputModel
                var customerInputModel = new CustomerInputModel
                {
                    CustomerId   = "TestName",
                    EmailAddress = "TestEmail"
                };

                // Arrange
                var controller = mock.Create <OrderDeliveryController>();

                // Act
                var actionResult = await controller.OrderDetails(customerInputModel);

                // Assert
                Assert.IsInstanceOfType(actionResult, typeof(BadRequestErrorMessageResult));
                Assert.AreEqual("Invalid Email Address", ((BadRequestErrorMessageResult)actionResult).Message);
            }
        }
        public ActionResult Add(CustomerInputModel model)
        {
            if (this.ModelState.IsValid)
            {
                var customerName = this.customers
                    .GetAll()
                    .FirstOrDefault(x => x.Name.ToLower() == model.Name.ToLower());
                if (customerName == null)
                {
                    var customer = this.Mapper.Map<Customer>(model);
                    this.customers.Add(customer);
                    TempData["Success"] = GlobalConstants.CustomerAddNotify;
                }
                else
                {
                    TempData["Warning"] = GlobalConstants.CustomerExistsNotify;
                }

                return this.Redirect("/Admin/Customers/Index");
            }

            return this.View(model);
        }
示例#15
0
        public async Task <ShardKey> CreateCustomer(CustomerInputModel customer, CancellationToken cancellation)
        {
            AssignLocationIdSequence(customer.Locations);
            //save the new customer record into the default shard
            var customerPrms = new ParameterCollection()
                               .CreateInputParameters <CustomerInputModel>(customer, _logger)
                               .AddPgSmallintInputParameter("shardid", _shardSet.DefaultShard.ShardId);
            var shardBatch = new ShardBatch <short, ShardKey <short, int> >()
                             .Add(customer.Contacts, "temp_contacts", new MapToPgSmallintAttribute("contactshardid"), new MapToPgIntegerAttribute("contactid"))
                             .Add(customer.Locations, "temp_locations")
                             .Add(Queries.CustomerCreate, customerPrms, DataOrigins.Customer, "newcustomerid");
            var custKey = await _shardSet.DefaultShard.Write.RunAsync(shardBatch, cancellation);

            try
            {   // if there are any foreign shards, save those records into their respective shard.
                var foreignShards = ShardKey.ShardListForeign(custKey.ShardId, customer.Contacts);
                if (foreignShards.Count > 0)
                {
                    var contactPrms = new ParameterCollection()
                                      .AddPgSmallintInputParameter("customershardid", custKey.ShardId)
                                      .AddPgIntegerInputParameter("customerid", custKey.RecordId);
                    var setBatch = new ShardSetBatch <short>()
                                   .Add(customer.Contacts, "temp_contacts", new MapToPgSmallintAttribute("contactshardid"), new MapToPgIntegerAttribute("contactid"))
                                   .Add(Queries.ContactCustomersCreate, contactPrms);
                    await _shardSet.Write.RunAsync(setBatch, foreignShards, cancellation);
                }
                return(custKey);
            }
            catch
            {
                // revert
                await DeleteCustomer(custKey, default(CancellationToken));

                throw;
            }
        }
示例#16
0
        public ActionResult <int> UpdateCustomer([FromBody] CustomerInputModel model)
        {
            var result = _customerManager.UpdateCustomer(model);

            return(Ok(result));
        }
示例#17
0
        public int UpdateCustomer(CustomerInputModel customer)
        {
            var dto = _mapper.Map <CustomerDto>(customer);

            return(_customerRepository.UpdateCustomer(dto));
        }
示例#18
0
 public int CreateNewCustomer(CustomerInputModel customer) => _customerRepository.CreateNewCustomer(customer);
示例#19
0
 public void UpdateCustomerById(CustomerInputModel customer, int id)
 {
     throw new System.NotImplementedException();
 }
示例#20
0
 public void Post([ModelBinder] CustomerInputModel inputModel)
 {
 }
示例#21
0
 // POST api/customer
 public void Post([FromBody] CustomerInputModel value)
 {
     //Example of mapping fields fields with only similar fieldnames will be mapped
     Customer c = mapper.MapFields <Customer>(value);
 }
示例#22
0
        public IActionResult Create()
        {
            var model = new CustomerInputModel();

            return(this.View(model));
        }