public string Get(string settings) { if (settings == "init") { _customerRepository.RemoveAllCustomers(); var name = _customerRepository.CreateIndex(); _customerRepository.AddCustomer(new Customers() { CustomerId = 1, ContactName = "Test customer 1", Address = "Test address 1", City = "Test City 1", Country = "Test country 1", PostalCode = 21000, CompanyName = "Test company name 1", ContactTitle = "Test title 1", Phone = "0038162222555", Fax = "0038154555544", CreatedOn = DateTime.Now, UpdatedOn = DateTime.Now }); _customerRepository.AddCustomer(new Customers() { CustomerId = 2, ContactName = "Test customer 2", Address = "Test address 2", City = "Test City 2", Country = "Test country 2", PostalCode = 21000, CompanyName = "Test company name 2", ContactTitle = "Test title 2", Phone = "0038162222555", Fax = "0038154555544", CreatedOn = DateTime.Now, UpdatedOn = DateTime.Now }); _customerRepository.AddCustomer(new Customers() { CustomerId = 3, ContactName = "Test customer 3", Address = "Test address 3", City = "Test City 3", Country = "Test country 3", PostalCode = 21000, CompanyName = "Test company name 3", ContactTitle = "Test title 3", Phone = "0038162222555", Fax = "0038154555544", CreatedOn = DateTime.Now, UpdatedOn = DateTime.Now }); _customerRepository.AddCustomer(new Customers() { CustomerId = 4, ContactName = "Test customer 4", Address = "Test address 4", City = "Test City 4", Country = "Test country 4", PostalCode = 21000, CompanyName = "Test company name 4", ContactTitle = "Test title 4", Phone = "0038162222555", Fax = "0038154555544", CreatedOn = DateTime.Now, UpdatedOn = DateTime.Now }); return("Database GeutebrueckDb was created, and collection 'Customers' was filled with 4 sample items"); } return("Unknown"); }
public void InitData() { /*var address = new Address() * { * StreetName = "smurf" * }; * address = _addressRepo.AddAddress(address); */ var customer1 = new Customer { FirstName = "John", LastName = "Billson", /*Address = new List<Address>() * { * address * }*/ }; _customerRepo.AddCustomer(customer1); var customer2 = new Customer { FirstName = "Johnny", LastName = "Billsony" }; _customerRepo.AddCustomer(customer2); }
public string AddCustomer(Customer customer) { var customerDomain = Mapper.Map <Domain.CustomerManagement.Customer>(customer); customerRepository.AddCustomer(customerDomain); return("Customer created!"); }
public async Task <ActionResult <Customer> > CreateCustomer(Customer customer) { try { if (customer == null) { return(BadRequest()); } // Add custom model validation error var cust = customerRepository.GetCustomerByEmail(customer.Email); if (cust != null) { ModelState.AddModelError("email", "Customer email already in use"); return(BadRequest(ModelState)); } var createdCustomer = await customerRepository.AddCustomer(customer); return(CreatedAtAction(nameof(GetCustomer), new { id = createdCustomer.CustomerID }, createdCustomer)); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Error creating new customer record")); } }
public void GetCustomer() { //Act var customer = new Customer { Name = "karthik108", Username = "******", Password = "******", Address = null, State = null, Country = null, EmailAddress = null, PAN = null, ContactNumber = null, DOB = Convert.ToDateTime("2000-12-31T23:59:59"), AccountType = null }; _repo.AddCustomer(customer); var savedCustomer = _repo.GetCustomerByName("karthik108"); var actual = _repo.GetCustomer(savedCustomer.Id); //Assert Assert.IsAssignableFrom <Customer>(actual); Assert.True(actual.Name == "karthik108"); }
public Task <bool> AddCustomer(CustomerModel customer) { try { //Customer customer = null; // var customerEntity = _mapper.Map<Customer>(customer); Customer cust = new Customer { FirstName = customer.FirstName, LastName = customer.LastName, MiddleName = customer.MiddleName, UserName = customer.UserName, Password = customer.Password, UserTypeID = customer.UserTypeID }; return(_customerRepository.AddCustomer(cust)); } catch (AutoMapperConfigurationException ex) { throw new ApiException(ex.Message, 500); } catch (Exception ex) { throw new ApiException(ex.Message, 500); } }
public ActionResult CreateCustomer([FromBody] CustomerForCreationDto customerForCreation) { if (customerForCreation == null) { _logger.LogWarning("An invalid customer object was received for create"); return(BadRequest()); } else { _logger.LogInformation("Starting to process the new customer"); } var customerRepo = AutoMapper.Mapper.Map <Customer>(customerForCreation); if (!ModelState.IsValid) { _logger.LogInformation("Creating new customer failed validation"); return(BadRequest(ModelState)); } _customerRepository.AddCustomer(customerRepo); if (!_customerRepository.Save()) { //Global error handler will return expected status code throw new Exception("Creating customer failed on save"); } var customerToReturn = AutoMapper.Mapper.Map <CustomerDto>(customerRepo); _logger.LogInformation($"New customer with Id {customerToReturn.CustomerId} was created"); return(CreatedAtRoute("GetCustomer", new { customerid = customerToReturn.CustomerId }, customerToReturn)); }
public IActionResult CreateCustomer([FromBody] CustomerDTO customerToCreate) { try { if (customerToCreate == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(new WebApiHelpers.ObjectResults.UnprocessableEntityObjectResult(ModelState)); } var customerEntity = Mapper.Map <Customer>(customerToCreate); _repo.AddCustomer(customerEntity); if (!_repo.Save()) { throw new Exception("Error creating customer."); } var customerToReturn = Mapper.Map <CustomerDTO>(customerEntity); return(CreatedAtRoute("GetCustomer", new { id = customerToReturn.Id }, customerToReturn)); } catch (Exception ex) { throw new Exception(ex.Message); } }
public void AddCustomer(Customer customer) { var customerEntity = new Customers() { CustomerId = customer.Id, Uname = customer.Uname, Email = customer.Email, Phone = customer.Phone, PostDate = customer.PostDate, FirstName = customer.BillingAddress.FirstName, LastName = customer.BillingAddress.LastName, Address1 = customer.BillingAddress.Address1, Address2 = customer.BillingAddress.Address2, City = customer.BillingAddress.City, State = customer.BillingAddress.State, PostalCode = customer.BillingAddress.PostalCode, Country = customer.BillingAddress.Country, ShippingFirstName = customer.ShippingAddress.FirstName, ShippingLastName = customer.ShippingAddress.LastName, ShippingAddress1 = customer.ShippingAddress.Address1, ShippingAddress2 = customer.ShippingAddress.Address2, ShippingCity = customer.ShippingAddress.City, ShippingState = customer.ShippingAddress.State, ShippingPostalCode = customer.ShippingAddress.PostalCode, ShippingCountry = customer.ShippingAddress.Country, }; _customerRepository.AddCustomer(customerEntity); }
public int AddCustomer(NewCustomerVm customer) { var cust = _mapper.Map <Customer>(customer); var id = _customerRepository.AddCustomer(cust); return(id); }
public ICustomerDto Handle(ICreateCustomerRequest request) { var uid = _uidGenerator.GetUid(); var customer = new Customer(uid, request.Name); return(_customerRepository.AddCustomer(customer)); }
public ActionResult Create(CustomerViewModel viewModel) { try { if (ModelState.IsValid) { // Create new instance of customer from the viewmodel var newCustomer = new BusinessLogic.Models.Customer { FirstName = viewModel.FirstName, LastName = viewModel.LastName, Phone = viewModel.Phone }; // Add to db via repo _repo.AddCustomer(newCustomer); //_logger.Info("Added new customer"); return(RedirectToAction(nameof(AllCustomers))); } return(View(viewModel)); } catch { //_logger.Debug(ex.Message); Console.WriteLine("Invalid Customer info"); return(View()); } }
public IActionResult AddCustomer(CustomerRegObj customerRegObj) { try { if (customerRegObj != null) { Customer customer = customerRegObj.Customer; User user = customerRegObj.User; Address address = customerRegObj.Address; _customerRepository.AddCustomer(customer); _userRepository.AddUser(user); _addressRepository.AddAddress(address); Token token = new Token(_configuration); var tokenString = token.GenerateJSONWebToken(); _logger.LogInformation($"User {user.UserName} login on {DateTime.UtcNow.ToLongTimeString()}"); ResponseUser resSuccess = new ResponseUser(user.UserName, tokenString); return(Ok(resSuccess)); } else { return(BadRequest("Request is null.")); } } catch (Exception e) { _logger.LogError("Error in CustomerController: " + e.ToString()); return(Problem(e.ToString())); } }
public async Task <Customer> AddCustomer(Customer customer, string userId) { if (await _customerRepository.GetCustomerByNameAsync(customer.Name) != null) { _customExceptionService.ThrowInvalidOperationException("Name already exists"); return(null); } _customerRepository.AddCustomer(customer); //Add registry operation if (await _customerRepository.SaveChangesAsync()) { CustomerAudit customerAudit = new CustomerAudit { Date = DateTime.Now, Operation = CustomerAuditOperationType.Create, Customer = customer }; _customerRepository.AddCustomerAudit(customerAudit, userId); if (await _customerRepository.SaveChangesAsync()) { return(customer); } } else { _customExceptionService.ThrowInvalidOperationException("Error adding customer"); } return(null); }
public HttpResponseMessage AddCustomer(CustomerModel model) { ResponseStatus response = new ResponseStatus(); try { if (model.PhoneNumber != "" && model.StoreId > 0) { var data = _repository.AddCustomer(model.PhoneNumber, model.StoreId, model.CustomerName); if (data != null) { response.isSuccess = true; response.serverResponseTime = System.DateTime.Now; return(Request.CreateResponse(HttpStatusCode.OK, new { data, response })); } else { response.isSuccess = false; response.serverResponseTime = System.DateTime.Now; return(Request.CreateResponse(HttpStatusCode.BadRequest, new { response })); } } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Please Check Store Id !")); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Something Worng !", ex)); } }
public async Task <ActionResult <CustomerModel> > AddCustomer([FromBody] CustomerModel customerModel) { try { var location = _linkGenerator.GetPathByAction("GetCustomer", "Customers", new { customerId = customerModel.CustomerId }); if (string.IsNullOrEmpty(location)) { return(BadRequest("Could not use current customer id")); } var customer = _mapper.Map <Customer>(customerModel); _customerRepository.AddCustomer(customer); if (await _customerRepository.SaveChangesAsync()) { return(Created(location, _mapper.Map <CustomerModel>(customer))); } return(this.StatusCode(StatusCodes.Status500InternalServerError, "Opps!")); } catch (Exception) { return(this.StatusCode(StatusCodes.Status500InternalServerError, "Something went wrong!")); } }
[ValidateAntiForgeryToken] //CSRF Implementation public ActionResult Create(CustomersViewModel newCustomerInfo) { TempData["CreatedCustomer"] = "true"; string thisMethod = TempData["actionMethod"].ToString(); string nextMethod = ""; switch (thisMethod) { case "ChooseLocation": nextMethod = "New"; break; case "": nextMethod = ""; break; default: break; } if (!ModelState.IsValid) { var NewCustomer = _repository.AddCustomer(newCustomerInfo.User_FirstName, newCustomerInfo.User_LastName); return(RedirectToAction(thisMethod, "Orders", new { CustomerId = NewCustomer.CustomerId, actionMethod = nextMethod, }, null)); } return(RedirectToAction("Index")); }
public string AddCustomer(NewCustomerVm customer) { var cust = _mapper.Map <Customer>(customer); var id = _customerRepo.AddCustomer(cust); return(id); }
public Response <Customer> RegisterCustomer(Customer details) { var returnValue = new Response <Customer>(); try { // Get customer data object. var customer = _customerRepo.AddCustomer(new Contracts.Models.Data.Customer() { Name = details.Name, Surname = details.Surname, Email = details.Email, Address = details.Address }); // Update ID details.Id = customer.Id; returnValue.IsSuccess = true; returnValue.Data = details; return(returnValue); } catch (Exception e) { returnValue.IsSuccess = false; returnValue.ExceptionMessage = e.Message; return(returnValue); } }
public async Task <ActionResult <Customer> > AddCustomer([FromBody] Customer customer) { if (ModelState.IsValid) { try { var custId = await repo.AddCustomer(customer); if (custId > 0) { return(Ok(custId)); } else { return(NotFound()); } } catch (Exception) { return(BadRequest()); } } return(BadRequest()); }
public void ImportModule(Module module, string content, string version) { List <Customer> Customers = null; if (!string.IsNullOrEmpty(content)) { Customers = JsonSerializer.Deserialize <List <Customer> >(content); } if (Customers != null) { foreach (Customer Customer in Customers) { Customer _Customer = new Customer(); _Customer.ModuleId = module.ModuleId; _Customer.FirstName = Customer.LastName; _Customer.LastName = Customer.LastName; _Customer.Address1 = Customer.Address1; _Customer.Address2 = Customer.Address2; _Customer.City = Customer.City; _Customer.UsState = Customer.UsState; _Customer.ZipCode = Customer.ZipCode; _Customer.Phone = Customer.Phone; _Customer.Email = Customer.Email; _Customers.AddCustomer(_Customer); } } }
public IActionResult CreateCustomer(CustomerViewModel customerview) { if (customerview is null) { throw new ArgumentNullException(nameof(customerview)); } try { if (ModelState.IsValid) { var addtorepo = new CustomerModel { FirstName = customerview.FirstName, LastName = customerview.LastName }; _customerRepo.AddCustomer(addtorepo); _customerRepo.saveChanges(); return(RedirectToAction(nameof(Index))); } return(View(customerview)); } catch { return(View(customerview)); } }
/// <summary> /// The RegisterNewCustomer /// </summary> /// <param name="userName">The userName<see cref="string"/></param> /// <param name="passWord">The passWord<see cref="string"/></param> /// <returns>The <see cref="string"/></returns> public string RegisterNewCustomer(string userName, string passWord) { if (string.IsNullOrWhiteSpace(userName)) { throw new ArgumentNullException("userName", "UserName cannot be null, enmpty or only white spaces."); } if (string.IsNullOrWhiteSpace(passWord)) { throw new ArgumentNullException("password", "Password cannot be null, enmpty or only white spaces."); } var locker = LockFile("customer.lk"); if (_customerRepository.FindCustomer(userName) != null) { UnlockFile(locker); throw new InvalidOperationException($"UserName {userName} has been used."); } var customer = new Customer { UserName = userName, PassWord = passWord }; var locker2 = LockFile("cart.lk"); var result = _customerRepository.AddCustomer(customer).ToString(); UnlockFile(locker2); UnlockFile(locker); return(result); }
//Thêm mới khách hàng: public ServiceResult AddCustomer(Customer customer) { var serviceResult = new ServiceResult(); //validate dữ liệu, nếu dữ liệu chưa hợp lệ thì trả về lỗi //Check trường bắt buộc nhập var customerCode = customer.CustomerCode; if (string.IsNullOrEmpty(customerCode)) { var msg = new { devMsg = new { fieldName = "CustomerCode", msg = "Mã khách hàng không được phép để trống" }, userMsg = "Mã khách hàng không được phép để trống", Code = MISACode.NotValid, }; serviceResult.MISACode = MISACode.NotValid; serviceResult.Messenger = "Mã khách hàng không được phép để trống"; serviceResult.Data = msg; return(serviceResult); } //Check trùng mã var res = _customerRepository.GetCustomerByCode(customerCode); if (res != null) { var msg = new { devMsg = new { fieldName = "CustomerCode", msg = "Mã khách hàng đã tồn tại" }, userMsg = "Mã khách hàng đã tồn tại", Code = MISACode.NotValid, }; serviceResult.MISACode = MISACode.NotValid; serviceResult.Messenger = "Mã khách hàng đã tồn tại"; serviceResult.Data = msg; return(serviceResult); } //Thêm mới khi dữ liệu đã hợp lệ: var rowAffects = _customerRepository.AddCustomer(customer); serviceResult.MISACode = MISACode.IsValid; serviceResult.Messenger = "Thêm thành công"; serviceResult.Data = rowAffects; return(serviceResult); }
public POCO.CustomerPoco AddCustomer(POCO.CustomerPoco customerPoco) { var dbCustomer = Mapper.Map <CustomerManagement.Data.DAO.Customer>(customerPoco); dbCustomer = _customerRepository.AddCustomer(dbCustomer); customerPoco = Mapper.Map <POCO.CustomerPoco>(dbCustomer); return(customerPoco); }
public ActionResult <Customer> PostCustomer([FromBody] CustomerDto customerDto) { var mappedCustomer = _mapper.Map <Customer>(customerDto); _customerRepository.AddCustomer(mappedCustomer); return(Ok(customerDto)); }
public int AddCustomer(string name, string surname, string email) { ICustomer newCustomer = factory.CreateCustomer(name, surname, email); int custID = customerRepository.AddCustomer(newCustomer); Debug.WriteLine("Customer with ID " + custID + " added to repo from facade"); return(custID); }
public void AddCustomer(string name, string currency, string cash) { Customer customer = new Customer { Name = name, Currency = currency, Cash = cash }; _repository.AddCustomer(customer); }
public void AddCustomer(AddNewCustomerViewModel model) { var addedInfo = UpdateModel(model.Country); model.Telephonecountrycode = addedInfo[0]; model.CountryCode = addedInfo[1]; _customerRepository.AddCustomer(model); }
public IActionResult Post([FromBody] CustomerEntity value) { if (value.CustomerAge < 10) { throw new InvalidAgeException("Age is less than 10"); } _repo.AddCustomer(value); return(Ok()); }
public CustomerModule(ICustomerRepository customerRepository) : base("/customers") { Get["/"] = _ => { var customers = customerRepository.GetCustomers(); return Response.AsJson(customers, HttpStatusCode.OK); }; Get["/{id}"] = parameters => { Customer customer = customerRepository.GetCustomer(parameters.id); return Response.AsJson(customer, HttpStatusCode.OK); }; Post["/create"] = parameters => { Customer cust = this.Bind<Customer>(); customerRepository.AddCustomer(cust); return HttpStatusCode.OK; }; Get["/count"] = _ => { int count = customerRepository.GetCustomerCount(); return Response.AsJson(count); }; }