Beispiel #1
0
        public ActionResult Create(CustomerCreateModel model)
        {
            var roles = _customerService.GetAllCustomerRoles();

            model.AvailableRoles = roles.ToSelectItems();

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var customer = new Customer
            {
                Username         = model.UserName,
                CreatedOn        = DateTime.Now,
                MobilePhone      = model.PhoneNumber,
                RealName         = model.RealName,
                CustomerRoleId   = model.CustomerRoleId,
                Active           = model.IsActive,
                LastActivityDate = DateTime.Now
            };
            var customerRequest = new CustomerRegistrationRequest(customer, model.UserName, model.PassWord,
                                                                  PasswordFormat.Hashed);
            var reponse = _customerRegistrationService.RegisterCustomer(customerRequest);

            if (reponse.Success)
            {
                return(RedirectToAction("ListCustomer"));
            }

            reponse.Errors.ForEach(d => { ModelState.AddModelError(string.Empty, d); });
            return(View(model));
        }
Beispiel #2
0
        public async Task <IActionResult> Create(CustomerCreateModel input)
        {
            var owner = await this.userManager.GetUserAsync(this.User);

            if (owner.CompanyId == null)
            {
                return(this.RedirectToAction("Create", "Companies", new { area = "Owners" }));
            }

            try
            {
                await this.customersService.CreateAsync(input);
            }
            catch (Exception e)
            {
                this.ModelState.AddModelError(string.Empty, e.Message);
            }

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

            return(this.RedirectToAction("Index"));
        }
        public HttpResponseMessage CreateNewCustomerInfo(CustomerCreateModel customerCreateModel)
        {
            CustomerDto customerDto = this.mapper.Map <CustomerCreateModel, CustomerDto>(customerCreateModel);

            this.customerAppService.CreateNewCustomerInfo(customerDto);
            return(new HttpResponseMessage(HttpStatusCode.OK));
        }
        public DefaultApiResponse ImportCustomer(CustomerCreateModel customer, string token, out BusinessRulesApiResponse businessRulesApiResponse)
        {
            var _data = JsonConvert.SerializeObject(customer, Newtonsoft.Json.Formatting.None,
                                                    new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            });
            var _address = ApiHelper.Instance.SiteUrl + ApiHelper.Instance.CustomerCreateEndpoint;

            businessRulesApiResponse = null;

            try
            {
                var _jsonResult = ApiHelper.Instance.WebClient(token).UploadString(_address, "POST", _data);

                if (_jsonResult != "null")
                {
                    return(new DefaultApiResponse(200, "OK", new string[] { }));
                }

                return(new DefaultApiResponse(500, "Internal Application Error: Fail to Import Customer", new string[] { }));
            }
            catch (WebException _webEx)
            {
                using StreamReader _r = new StreamReader(_webEx.Response.GetResponseStream());
                string _responseContent = _r.ReadToEnd();

                return(ApiHelper.Instance.ProcessApiResponseContent(_webEx, _responseContent, out businessRulesApiResponse));
            }
        }
        public async Task <CustomerViewModel> CreateCustomer(CustomerCreateModel customer)
        {
            ApplicationUsers user = new ApplicationUsers()
            {
                UserName = customer.Users.UserName,
                FullName = customer.Users.UserName
            };


            var result = await _accountManager.CreateUserAsync(user, customer.Users.Roles, customer.Users.Password);

            if (result.Succeeded)
            {
                Customer customerByDB = new Customer()
                {
                    Name     = customer.Name,
                    Code     = customer.Code,
                    Address  = customer.Address,
                    Discount = customer.Discount,
                    User     = await _accountManager.GetUserByNameAsync(user.UserName)
                };
                _unitOfWork.Customers.Create(customerByDB);
                return(GetCustomersDBToViewModelById(customerByDB.Id));
            }

            return(null);
        }
Beispiel #6
0
        public async Task <int> CreateAsync(CustomerCreateModel input)
        {
            if (await this.IsExistEmail(input.Email, input.OwnerId))
            {
                throw new Exception($"You already have customer with email: {input.Email}");
            }
            if (await this.IsExistPhone(input.PhoneNumber, input.OwnerId))
            {
                throw new Exception($"You already have customer with phone: {input.PhoneNumber}");
            }

            var address = await this.addressService.CreateAsync(input.AddressCountry, input.AddressCity, input.AddressStreet, input.AddressZipCode);

            var jobTitle = await this.jobTitlesService.CreateAsync(input.JobTitleName);

            var customer = new Customer
            {
                FirstName      = input.FirstName,
                MiddleName     = input.MiddleName,
                LastName       = input.LastName,
                JobTitleId     = jobTitle,
                AddressId      = address,
                EmployerId     = input.EmployerId,
                OwnerId        = input.OwnerId,
                PhoneNumber    = input.PhoneNumber,
                Email          = input.Email,
                AdditionalInfo = input.AdditionalInfo,
            };

            await this.customersRepository.AddAsync(customer);

            return(await this.customersRepository.SaveChangesAsync());
        }
        public IActionResult CreateCustomer([FromBody] CustomerCreateModel customer)
        {
            if (customer == null || !ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var newCustomer = new CustomerDataTransferObject
            {
                Name     = customer.Name,
                Adress   = customer.Adress,
                Code     = customer.Code,
                Discount = customer.Discount
            };

            var newCustomerId = _customerService.CreateCustomer(newCustomer);

            var customerUser = new CustomerInfoDataTransferObject
            {
                UserName   = customer.Email,
                Email      = customer.Email,
                CustomerId = newCustomerId
            };

            _customerService.AddCustomerUser(_userManager, customerUser, customer.Password).Wait();

            return(CreatedAtRoute("GetCustomer", new { id = newCustomerId },
                                  new CustomerGetModel
            {
                Id = newCustomerId,
                Name = newCustomer.Name,
                Code = newCustomer.Code,
                Adress = newCustomer.Adress,
                Discount = newCustomer.Discount
            }));
        }
Beispiel #8
0
        public async Task <CustomerViewModel> CreateAsync([FromBody] CustomerCreateModel createModel)
        {
            var model = createModel.ToModel();

            var customer = await _customerService.CreateAsync(model);

            return(customer.ToViewModel());
        }
Beispiel #9
0
 public static Customer ToDataAccess(this CustomerCreateModel model)
 {
     return(new Customer
     {
         FirstName = model.FirstName,
         LastName = model.LastName,
         DateOfBirth = model.DateOfBirth
     });
 }
Beispiel #10
0
        /// <summary>
        /// Creates this instance.
        /// </summary>
        /// <returns></returns>
        public ActionResult Create()
        {
            var model = new CustomerCreateModel();
            var roles = _customerService.GetAllCustomerRoles();

            model.AvailableRoles = roles.ToSelectItems();
            model.IsActive       = true;
            return(View(model));
        }
Beispiel #11
0
        public async Task <int> CreateCustomerAsync(CustomerCreateModel model)
        {
            await _customerCreateModelValidator.ValidateAndThrowAsync(model);

            var newCustomer = _mapper.Map <Customer>(model);

            _context.Add(newCustomer);
            await _context.SaveChangesAsync();

            return(newCustomer.Id);
        }
Beispiel #12
0
        public async Task <IActionResult> Post([FromBody] CustomerCreateModel cm)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var customer = await this.service.AddAsync(cm);

            return(Ok(customer));
        }
        public CustomerDetailsModel CreateCustomer(CustomerCreateModel customerCreateModel)
        {
            var customer = new Customer
            {
                Id        = Guid.NewGuid(),
                CreatedAt = DateTime.UtcNow
            };

            Mapper.Map <CustomerCreateModel, Customer>(customerCreateModel, customer);
            Database.Add(customer);
            return(Mapper.Map <CustomerDetailsModel>(customer));
        }
Beispiel #14
0
 public static void CreateCustomer(int clientId, CustomerCreateModel model)
 {
     using (var sctx = new DataAccess.ShopContext())
     {
         sctx.Set <DataAccess.Customer>()
         .Add(new DataAccess.Customer()
         {
             ClientId = clientId, Amount = model.Ammount, Nickname = model.Nickname
         });
         sctx.SaveChanges();
     }
 }
Beispiel #15
0
        public async Task <IActionResult> Create()
        {
            var owner = await this.userManager.GetUserAsync(this.User);

            var employees = this.employeesManagerService.GetAll <EmployeesDropDownViewModel>(owner.CompanyId).ToList();
            var viewModel = new CustomerCreateModel
            {
                OwnerId   = owner.Id,
                Employees = employees,
            };

            return(this.View(viewModel));
        }
        public async Task <IActionResult> CreateNewUser([FromBody] CustomerCreateModel model)
        {
            try
            {
                var result = await customerService.AddCustomerAsync(model);

                return(Ok(result));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public IActionResult CreateCustomer([FromBody] CustomerCreateModel customerCreateModel)
        {
            try
            {
                var createdCustomer = CustomersService.CreateCustomer(customerCreateModel);

                return(CreatedAtAction("GetCustomerById", new { Id = createdCustomer.Id }, createdCustomer));
            }
            catch (Exception e)
            {
                Logger.LogCritical(e, "Error while creating new Customer");
                return(StatusCode(500));
            }
        }
Beispiel #18
0
        public async Task <IActionResult> Create()
        {
            var employerAccount = await this.userManager.GetUserAsync(this.User);

            var employerId = await this.employeesManagerService.GetEmployersIdAsync(employerAccount.Id);

            var viewModel = new CustomerCreateModel
            {
                EmployerId = employerId,
                OwnerId    = employerAccount.ParentId,
            };

            return(this.View(viewModel));
        }
Beispiel #19
0
        public async Task <CustomerViewModel> AddAsync(CustomerCreateModel cm)
        {
            cm.Id = Guid.NewGuid();

            var coins = await coinRepository.Get(x => new CoinViewModel {
                Id = x.Id
            }).ToListAsync();

            cm.Balances = new List <Balance>();
            coins.ForEach(x => cm.Balances.Add(new Balance {
                CoinId = x.Id, CustomerId = cm.Id
            }));

            return(await base.AddAsync <CustomerCreateModel, CustomerViewModel>(cm));
        }
        public static Customer ToModel(this CustomerCreateModel model)
        {
            if (model == null)
            {
                return(null);
            }

            return(new Customer {
                Name = model.Name,
                Description = model.Description,
                MainContactNumber = model.MainContactNumber,
                MainContactPerson = model.MainContactPerson,
                SubContactNumber = model.SubContactNumber,
                SubContactPerson = model.SubContactPerson,
                Area = model.Area
            });
        }
Beispiel #21
0
        public static void UpdateCustomer(int clientId, int customerId, CustomerCreateModel model)
        {
            using (var sctx = new DataAccess.ShopContext())
            {
                var curCustomer = sctx.Set <DataAccess.Customer>()
                                  .SingleOrDefault(cust => cust.ClientId == clientId && cust.Id == customerId);
                if (curCustomer == null)
                {
                    throw new Exception("There is no such Customer");
                }

                curCustomer.Amount   = model.Ammount;
                curCustomer.Nickname = model.Nickname;

                sctx.SaveChanges();
            }
        }
        public IActionResult Create()
        {
            CustomerCreateModel customerCreateModel = new CustomerCreateModel();

            customerCreateModel.Customer = new Customer();
            List <SelectListItem> countries = _dbcontext.Countries
                                              .OrderBy(n => n.Name)
                                              .Select(n =>
                                                      new SelectListItem
            {
                Value = n.Code,
                Text  = n.Name
            }).ToList();

            customerCreateModel.Countries = countries;
            customerCreateModel.Cities    = new List <SelectListItem>();
            return(View(customerCreateModel));
        }
        public IActionResult CreateCustomer()
        {
            CustomerCreateModel customer = epayco.CustomerCreate(
                "PwifgQPvca6fLoJvh",
                "alejo desde .net",
                ".net",
                "*****@*****.**",
                true,
                "caldas",
                "calle falsa",
                "3032546",
                "314625443cus5");

            if (customer.status)
            {
            }

            return(Ok(customer));
        }
Beispiel #24
0
        public IActionResult CreateCustomer([FromBody] CustomerCreateModel customer)
        {
            if (customer == null)
            {
                return(BadRequest());
            }
            var customerEntity = AutoMapper.Mapper.Map <Customer>(customer);

            _repository.AddCustomer(customerEntity);

            if (!_repository.Save())
            {
                return(StatusCode(500, "Server Error"));
            }

            var returnEntity = AutoMapper.Mapper.Map <CustomerModel>(customerEntity);

            return(CreatedAtRoute("GetCustomer", new { customerId = returnEntity.Id }, returnEntity));
        }
Beispiel #25
0
        public bool CreateCustomer(CustomerCreateModel model)
        {
            using (var ctx = new BankEntities())
            {
                //1 Collecting info from model
                //2 Storing in matching Entity Property
                var entity = new Customer
                {
                    //2                               //1
                    SocialSecurityNumber = model.SocialSecurityNumber,
                    FirstName            = model.FirstName,
                    LastName             = model.LastName,
                    CreatedUtc           = DateTime.Now
                };

                ctx.Customers.Add(entity);

                return(ctx.SaveChanges() == 1);
            }
        }
Beispiel #26
0
        public CustomerCreateModel CustomerCreate(string token_card,
                                                  string name,
                                                  string last_name,
                                                  string email,
                                                  bool isDefault,
                                                  string city       = "",
                                                  string address    = "",
                                                  string phone      = "",
                                                  string cell_phone = "")
        {
            PARAMETER = body.getBodyCreateCustomer(token_card, name, last_name, email, isDefault, city, address, phone, cell_phone);
            ENDPOINT  = Constants.url_create_customer;
            string content = _request.Execute(
                ENDPOINT,
                "POST",
                _auxiliars.ConvertToBase64(_PUBLIC_KEY),
                PARAMETER);
            CustomerCreateModel customer = JsonConvert.DeserializeObject <CustomerCreateModel>(content);

            return(customer);
        }
        public void Should_Be_Able_To_Create_CustomerCreateModel_Object()
        {
            //Arrange
            int    ssn       = 888;
            string firstName = "Dwight";
            string lastName  = "Eisenhower";

            CustomerCreateModel user = new CustomerCreateModel
            {
                SocialSecurityNumber = ssn,
                FirstName            = firstName,
                LastName             = lastName
            };

            //Act
            user.FirstName = "Dwight";

            //Assert
            Assert.AreEqual(user.FirstName, firstName);
            Assert.AreNotSame(user.FirstName, lastName);
        }
        public static int NewCustomerSignUpQuestions()
        {
            Console.WriteLine("What is your SSN?");
            string ssnString = Console.ReadLine();
            int    ssn       = Int32.Parse(ssnString);

            Console.WriteLine("What is your first name?");
            string firstName = Console.ReadLine();

            Console.WriteLine("What is your last name?");
            string lastName = Console.ReadLine();

            CustomerCreateModel user = new CustomerCreateModel
            {
                SocialSecurityNumber = ssn,
                FirstName            = firstName,
                LastName             = lastName
            };

            CreateCustomerService().CreateCustomer(user);
            return(user.SocialSecurityNumber);
        }
        /// <summary>
        /// Enters the models info.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">model</exception>
        public virtual ICreatePage EnterInformation(CustomerCreateModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            Info.EnterEmail(model.Email)
            .EnterPassword(model.Password)
            .SetCustomerRoles(model.CustomerRoles)
            .SetManagerOfVendor(model.ManagerOfVendor)
            .SetGender(model.Gender)
            .EnterFirstName(model.FirstName)
            .EnterLastName(model.LastName)
            .EnterDateOfBirth(model.DateOfBirth)
            .EnterCompanyName(model.CompanyName)
            .EnterAdminComment(model.AdminComment)
            .SetTaxExcempt(model.IsTaxExempt)
            .SetNewsLetters(model.NewsLetters)
            .SetIsActive(model.Active);

            return(this);
        }
Beispiel #30
0
        public async Task Example2()
        {
            string address = "http://localhost:9000/";

            using (WebApp.Start <WebAPI.Startup>(address))
            {
                var clientModel = new ClientCreateModel()
                {
                    Name = "First Client"
                };
                var customerModel = new CustomerCreateModel()
                {
                    Ammount = 1000, Nickname = "Alex"
                };
                var itemModel = new ClientItemCreateModel()
                {
                    Code = "asd", Name = "Emperor's sword", Price = 500
                };

                var clientUrl = new Url(address + "clients");
                var resp      = await clientUrl.PostJsonAsync(clientModel);


                Console.WriteLine(resp);

                //ClientService.CreateClient(clientModel);

                var customerUrl = new Url(address + "clients/customers").SetQueryParams(new { clientId = 1, model = customerModel });
                var resp3       = await customerUrl.PostAsync(new HttpMessageContent(new HttpRequestMessage()));

                Console.WriteLine(resp3);
                var itemUrl = new Url(address + "clients/items");
                var resp2   = await itemUrl.PostJsonAsync(new { clientId = 1, model = itemModel });

                Console.WriteLine(resp2);
            }
        }