Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            CustomerAddRequest request = new CustomerAddRequest
            {
                CustomerModel = new CustomerModel
                {
                    Address      = "Yenımahalle",
                    City         = "Ankara",
                    CompanyName  = "TcHealth",
                    Country      = "Turkiye",
                    ContactName  = "Onur",
                    ContactTitle = "Hacı",
                    Fax          = "Cekme",
                    Phone        = "00000",
                    PostalCode   = "0005415",
                    Region       = "Tr"
                }
            };

            //var result = svc.AddCustomer(request);
            //if (result.SaveCount > 0)
            //    MessageBox.Show("işlem başarılı");
            //else
            //    MessageBox.Show("İşlem Başarısız");
        }
Beispiel #2
0
 public void Add(CustomerAddRequest customer)
 {
     QLTEQ.Domain.Customers.Customer cust    = new QLTEQ.Domain.Customers.Customer();
     QLTEQ.Domain.Customers.Address  address = new QLTEQ.Domain.Customers.Address(customer.Address.StreetAddress, customer.Address.City, customer.Address.State, customer.Address.ZipCode);
     cust.id      = customer.Id;
     cust.Address = address;
     this._context.Customers.Add(cust);
     this._context.SaveChanges();
 }
Beispiel #3
0
 public CustomerGetResponse GetById(CustomerAddRequest customerAddRequest)
 {
     return(this._context.Customers.Select(a => new CustomerGetResponse()
     {
         Id = a.id,
         name = a.name,
         email = a.email
     }).FirstOrDefault(x => x.Id == customerAddRequest.Id));
 }
Beispiel #4
0
        public CustomerResponse Any(CustomerAddRequest request)
        {
            if (Validator != null)
            {
                Validator.ValidateAndThrow(request, ApplyTo.Post);
            }

            OnBeforeCustomerAddRequest(request);

            var output = Repository.Create(request);

            OnAfterCustomerAddRequest(request, output);
            return(output);
        }
Beispiel #5
0
        public async Task AddCustomerAsync(CustomerAddRequest customerRequest)
        {
            _nullCheckMethod.CheckIfRequestIsNull(customerRequest);

            var customer = await _unitOfWork.Customers.GetCustomerByEmailAsync(customerRequest.Email);

            _nullCheckMethod.CheckIFObjectAlreadyExist(customer);

            var _customerRequest = Mapper.Map <Customer>(customerRequest);

            _unitOfWork.Customers.AddCustomer(_customerRequest);
            await _unitOfWork.CompleteAsync();

            await _emailService.SendCustomerAddNotifyEmailAsync(customerRequest.Email);
        }
Beispiel #6
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));
            }
        }
Beispiel #7
0
        public CustomerResponse Create(CustomerAddRequest request)
        {
            using (var adapter = DataAccessAdapterFactory.NewDataAccessAdapter())
            {
                OnBeforeCustomerAddRequest(adapter, request);

                var entity = request.FromDto();
                entity.IsNew = true;

                if (adapter.SaveEntity(entity, true))
                {
                    OnAfterCustomerAddRequest(adapter, request);
                    return(new CustomerResponse(entity.ToDto()));
                }
            }

            throw new InvalidOperationException();
        }
Beispiel #8
0
        public Model.Result.CustomerAddResult AddCustomer(CustomerAddRequest request)
        {
            CustomerAddResult result = new CustomerAddResult();

            try
            {
                if (request != null && request.CustomerModel != null)
                {
                    using (StockDbContext context = new StockDbContext())
                        using (IUnitOfWork unitofwork = new EfUnitOfWork(context))
                        {
                            Customer customer = new Customer
                            {
                                CustomerId   = Guid.NewGuid(),
                                City         = request.CustomerModel.City,
                                CompanyName  = request.CustomerModel.CompanyName,
                                Address      = request.CustomerModel.Address,
                                Region       = request.CustomerModel.Region,
                                Phone        = request.CustomerModel.Phone,
                                ContactTitle = request.CustomerModel.ContactTitle,
                                ContactName  = request.CustomerModel.ContactName,
                                PostalCode   = request.CustomerModel.PostalCode,
                                Country      = request.CustomerModel.Country,
                                Fax          = request.CustomerModel.Fax,
                            };
                            unitofwork.GetRepository <Customer>().Add(customer);
                            result.SaveCount = unitofwork.SaveChanges();
                            if (result.SaveCount > 0)
                            {
                                return(result);
                            }
                        }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                throw;
            }

            return(result);
        }
Beispiel #9
0
 partial void OnAfterCustomerAddRequest(IDataAccessAdapter adapter, CustomerAddRequest request);
Beispiel #10
0
 partial void OnAfterCustomerAddRequest(CustomerAddRequest request, CustomerResponse response);
Beispiel #11
0
        public void Customer_Add()
        {
            var api = Credentials.GetAPI();


            var request  = new CustomerAddRequest(Credentials.EnterpriseCode, Credentials.DealerNumber, Settings.ServerName);
            var customer = new
            {
                FirstName = "Tom",
                LastName  = "Monck",
                Email     = "*****@*****.**"
            };
            // DT requires that you do a search for the entity first before you add.
            // They are trying to avoid duplicate customer records.
            // The search method returns a datatoken that is active for 15 minutes that you can use in an add request.
            string dataToken = null;

            try
            {
                var customerRequest = new CustomerSearchRequest(Credentials.EnterpriseCode, Credentials.DealerNumber)
                {
                    FirstName = customer.FirstName.ToUpper(),
                    LastName  = customer.LastName.ToUpper(),
                    Email     = customer.Email.ToUpper()
                };

                var searchResponse = api.FindCustomers(customerRequest);
                dataToken = searchResponse.DataToken;
            }
            catch (OpenTrackException openTrackException)
            {
                if (openTrackException.ErrorCode != "CS02")
                {
                    throw;
                }

                var dataTokenElements = openTrackException.Response.GetElementsByTagName("DataToken");
                if (dataTokenElements.Count > 0)
                {
                    dataToken = dataTokenElements[0].InnerText;
                }

                request.Customer = new Customer
                {
                    DataToken                  = dataToken,
                    TypeCode                   = "C",
                    LastName                   = "Smith",
                    FirstName                  = "John",
                    MiddleName                 = "O",
                    Salutation                 = "Mr",
                    Gender                     = "Male",
                    Language                   = "English",
                    Address1                   = "123 Main St",
                    Address2                   = "Apt 103",
                    Address3                   = "Test",
                    City                       = "Raleigh",
                    County                     = "Wake",
                    StateCode                  = "NC",
                    ZipCode                    = "27612",
                    PhoneNumber                = "555-555-5555",
                    BusinessPhone              = "555-555-5555",
                    BusinessExt                = "426",
                    FaxNumber                  = "",
                    BirthDate                  = "",
                    DriversLicense             = "",
                    Contact                    = "",
                    PreferredContact           = "",
                    MailCode                   = "",
                    TaxExmptNumber             = "",
                    AssignedSalesperson        = "",
                    CustomerType               = "R",
                    PreferredPhone             = "",
                    CellPhone                  = "",
                    PagePhone                  = "",
                    OtherPhone                 = "",
                    OtherPhoneDesc             = "",
                    Email1                     = "*****@*****.**",
                    Email2                     = "",
                    OptionalField              = "",
                    AllowContactByPostal       = "",
                    AllowContactByEmail        = "Yes",
                    AllowContactByPhone        = "",
                    BusinessPhoneExtension     = "",
                    InternationalBusinessPhone = "",
                    InternationalCellPhone     = "",
                    ExternalCrossReferenceKey  = "",
                    InternationalFaxNumber     = "",
                    InternationalOtherPhone    = "",
                    InternationalHomePhone     = "",
                    CustomerPreferredName      = "",
                    InternationalPagerPhone    = "",
                    PreferredLanguage          = "",
                    InternationalZipCode       = ""
                };

                var response = api.AddCustomer(request);
                Assert.NotNull(response);
            }
        }
Beispiel #12
0
        public void Customer_Add()
        {
            var api = Credentials.GetAPI();


            var request = new CustomerAddRequest(Credentials.EnterpriseCode, Credentials.DealerNumber, Settings.ServerName);
            var customer = new
            {
                FirstName = "Tom",
                LastName = "Monck",
                Email = "*****@*****.**"
            };
            // DT requires that you do a search for the entity first before you add.
            // They are trying to avoid duplicate customer records.
            // The search method returns a datatoken that is active for 15 minutes that you can use in an add request.
            string dataToken = null;
            try
            {
                var customerRequest = new CustomerSearchRequest(Credentials.EnterpriseCode, Credentials.DealerNumber)
                {
                    FirstName = customer.FirstName.ToUpper(),
                    LastName = customer.LastName.ToUpper(),
                    Email = customer.Email.ToUpper()
                };

                var searchResponse = api.FindCustomers(customerRequest);
                dataToken = searchResponse.DataToken;

            }
            catch (OpenTrackException openTrackException)
            {
                if (openTrackException.ErrorCode != "CS02") throw;

                var dataTokenElements = openTrackException.Response.GetElementsByTagName("DataToken");
                if (dataTokenElements.Count > 0)
                {
                    dataToken = dataTokenElements[0].InnerText;
                }

                request.Customer = new Customer
                {
                    DataToken = dataToken,
                    TypeCode = "C",
                    LastName = "Smith",
                    FirstName = "John",
                    MiddleName = "O",
                    Salutation = "Mr",
                    Gender = "Male",
                    Language = "English",
                    Address1 = "123 Main St",
                    Address2 = "Apt 103",
                    Address3 = "Test",
                    City = "Raleigh",
                    County = "Wake",
                    StateCode = "NC",
                    ZipCode = "27612",
                    PhoneNumber = "555-555-5555",
                    BusinessPhone = "555-555-5555",
                    BusinessExt = "426",
                    FaxNumber = "",
                    BirthDate = "",
                    DriversLicense = "",
                    Contact = "",
                    PreferredContact = "",
                    MailCode = "",
                    TaxExmptNumber = "",
                    AssignedSalesperson = "",
                    CustomerType = "R",
                    PreferredPhone = "",
                    CellPhone = "",
                    PagePhone = "",
                    OtherPhone = "",
                    OtherPhoneDesc = "",
                    Email1 = "*****@*****.**",
                    Email2 = "",
                    OptionalField = "",
                    AllowContactByPostal = "",
                    AllowContactByEmail = "Yes",
                    AllowContactByPhone = "",
                    BusinessPhoneExtension = "",
                    InternationalBusinessPhone = "",
                    InternationalCellPhone = "",
                    ExternalCrossReferenceKey = "",
                    InternationalFaxNumber = "",
                    InternationalOtherPhone = "",
                    InternationalHomePhone = "",
                    CustomerPreferredName = "",
                    InternationalPagerPhone = "",
                    PreferredLanguage = "",
                    InternationalZipCode = ""
                };

                var response = api.AddCustomer(request);
                Assert.NotNull(response);
            }
        }
Beispiel #13
0
 public CustomerAddResponse AddCustomer(CustomerAddRequest query)
 {
     return(SubmitRequest <CustomerAddResponse>(query));
 }
Beispiel #14
0
 partial void OnBeforeCustomerAddRequest(CustomerAddRequest request);
Beispiel #15
0
 public void SaveCustomer(CustomerAddRequest customer)
 {
     this._customerRepository.Add(customer);
 }
Beispiel #16
0
        public CustomerGetResponse GetCustomerById(CustomerAddRequest customer)
        {
            var result = this._customerRepository.GetById(customer);

            return(result);
        }
Beispiel #17
0
        public async Task <IActionResult> CustomerRegistration([FromForm] CustomerAddRequest request)
        {
            var   currentUser = HttpContext.User;
            Int32 userId      = Convert.ToInt32(currentUser.Claims.FirstOrDefault(c => c.Type == "user_id").Value);

            LoginCredentials objLoginCredentials = new LoginCredentials();
            string           folderName          = "Images";

            try
            {
                var customer = JsonConvert.DeserializeObject <CustomerViewModel>(request.customer);
                if (customer.UserID == 0)
                {
                    objLoginCredentials             = _mapper.Map <LoginCredentials>(customer);
                    objLoginCredentials.IsActive    = true;
                    objLoginCredentials.IsDelete    = false;
                    objLoginCredentials.Username    = customer.EmailID;
                    objLoginCredentials.RoleId      = (Int32)Helper.EnumList.Roles.Customer;
                    objLoginCredentials.CreatedBy   = userId;
                    objLoginCredentials.CreatedDate = DateTime.Now;
                    objLoginCredentials.Password    = Helper.Helper.CreateRandomPassword();

                    #region image upload

                    //string webRootPath = _hostingEnvironment.WebRootPath;
                    //string newPath = Path.Combine(webRootPath, folderName);
                    //if (!Directory.Exists(newPath))
                    //{
                    //    Directory.CreateDirectory(newPath);
                    //}
                    //if (file.Length > 0)
                    //{
                    //    string fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
                    //    string fullPath = Path.Combine(newPath, fileName);
                    //    using (var stream = new FileStream(fullPath, FileMode.Create))
                    //    {
                    //        file.CopyTo(stream);
                    //    }
                    //}

                    if (request.file != null) //return BadRequest("Null File");
                    {
                        if (request.file.Length == 0)
                        {
                            return(BadRequest("Empty File"));
                        }
                        if (request.file.Length > 2 * 1024 * 1024)
                        {
                            return(BadRequest("Max file size exceeded."));
                        }
                        string webRootPath     = _hostingEnvironment.WebRootPath;
                        string uploadFilesPath = Path.Combine(webRootPath, folderName);
                        if (!Directory.Exists(uploadFilesPath))
                        {
                            Directory.CreateDirectory(uploadFilesPath);
                        }
                        var fileName = Guid.NewGuid().ToString() + Path.GetExtension(request.file.FileName);
                        var filePath = Path.Combine(uploadFilesPath, fileName);
                        using (var stream = new FileStream(filePath, FileMode.Create))
                        {
                            await request.file.CopyToAsync(stream);
                        }

                        objLoginCredentials.ProfileImage = fileName;
                    }

                    #endregion

                    _context.Add(objLoginCredentials);
                    _context.SaveChanges();
                }
                else
                {
                    var data   = _context.LoginCredentials.FirstOrDefault(q => q.UserId == customer.UserID && q.IsActive == true && q.IsDelete == false);
                    var result = _mapper.Map(customer, data);

                    result.Username = customer.EmailID;

                    #region remove existing profile picture

                    if (request.file != null)
                    {
                        string webRootPath1 = _hostingEnvironment.WebRootPath;
                        string imagename1   = data.ProfileImage;
                        imagename1 = imagename1 == null?Guid.NewGuid().ToString() + Path.GetExtension(request.file.FileName) : imagename1;

                        string uploadFilesPath1 = Path.Combine(webRootPath1, folderName, imagename1);
                        using (var stream = new FileStream(uploadFilesPath1, FileMode.Create))
                        {
                            await request.file.CopyToAsync(stream);

                            result.ProfileImage = imagename1;
                        }
                    }

                    #endregion

                    _context.Entry(result).State = EntityState.Modified;
                    _context.SaveChanges();
                }

                return(Ok(new { success = true }));
            }
            catch (Exception e)
            {
                return(StatusCode((int)HttpStatusCode.ExpectationFailed));
            }
        }