Beispiel #1
0
        public async Task <IList <Edges> > GetAddressInfor()
        {
            string accestoken = Convert.ToString(Settings.Customer_Access_Token);
            //string addressId = SettingExtension.AddressId;
            char   quote          = '"';
            string modifiedString = quote + accestoken + quote;
            string query          = "{ customer(customerAccessToken: " + modifiedString + "){id firstName lastName email createdAt lastIncompleteCheckout{id createdAt webUrl lineItems(first: 5){ edges{ node{quantity id title variant{ id image{ id originalSrc}}}}}}addresses(first: 3){edges{ node{ id firstName lastName address1 address2 city company country zip province}}}orders(first: 3){edges{node{id orderNumber name email lineItems(first: 3){ edges{ node{quantity variant{ id image{ originalSrc}}}}}}}}}}";
            //string qury = "{ customer(customerAccessToken:" + modifiedString + "){ id email firstName lastName createdAt  addresses(first: 9){ edges{ node{ firstName lastName address1 address2 city company country zip } } } } }";
            var res1 = await _apiService.GetAddress(query);

            if (res1.data.customer.addresses.edges.Count > 0)
            {
                Settings.Customer_Email = res1.data.customer.email;
                Customer_Address customer_Address = new Customer_Address();
                customer_Address.firstName = res1.data.customer.addresses.edges[0].node.firstName;
                customer_Address.lastName  = res1.data.customer.addresses.edges[0].node.lastName;
                customer_Address.address1  = res1.data.customer.addresses.edges[0].node.address1;
                customer_Address.address2  = res1.data.customer.addresses.edges[0].node.address2;
                customer_Address.company   = res1.data.customer.addresses.edges[0].node.company;
                customer_Address.country   = res1.data.customer.addresses.edges[0].node.country;
                customer_Address.zip       = res1.data.customer.addresses.edges[0].node.zip;
                customer_Address.zip       = res1.data.customer.addresses.edges[0].node.zip;
                customer_Address.zip       = res1.data.customer.addresses.edges[0].node.zip;
                customer_Address.zip       = res1.data.customer.addresses.edges[0].node.zip;
                //App.Locator.ShippingConfirmation.InitializeData(customer_Address);
                return(res1.data.customer.addresses.edges);
            }
            else
            {
                await App.Current.MainPage.Navigation.PushModalAsync(new AddNewAddress());

                return(null);
            }
        }
Beispiel #2
0
        public async Task SaveCustomer_AddressAsync(Customer_Address item, bool isNewItem = false)
        {
            var uri = new Uri(string.Format(Constants.Customer_AddressesUrl, string.Empty));

            try
            {
                var json    = JsonConvert.SerializeObject(item);
                var content = new StringContent(json, Encoding.UTF8, "application/json");

                HttpResponseMessage response = null;
                if (isNewItem)
                {
                    response = await _client.PostAsync(uri, content);
                }
                else
                {
                    response = await _client.PutAsync(uri, content);
                }

                if (response.IsSuccessStatusCode)
                {
                    Debug.WriteLine(@"\tCustomer_Address successfully saved.");
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(@"\tERROR {0}", ex.Message);
            }
        }
        public async Task <ActionResult <Customer_Address> > PostCustomer_Address(Customer_Address customer_Address)
        {
            _context.Customer_Addresses.Add(customer_Address);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCustomer_Address", new { id = customer_Address.AddressID }, customer_Address));
        }
        public async Task <IActionResult> PutCustomer_Address(int id, Customer_Address customer_Address)
        {
            if (id != customer_Address.AddressID)
            {
                return(BadRequest());
            }

            _context.Entry(customer_Address).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!Customer_AddressExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        static BaseCustomerDetailsViewModel()
        {
            account          = new Account();
            account.Customer = new Customer();

            address          = new Address();
            customer_address = new Customer_Address();
        }
Beispiel #6
0
        public void AddToCustomerAddress(int customerDbId, int addressDbId)
        {
            Customer_Address customerAddress = new Customer_Address();

            customerAddress.AddressId  = addressDbId;
            customerAddress.CustomerId = customerDbId;
            db.Customer_Addresses.Add(customerAddress);
            db.SaveChanges();
        }
        //add an aditional address to customer account
        async void AddAddressClicked()
        {
            CustomerAddressValidator customer_address_validator = new CustomerAddressValidator();
            ValidationResult         results = customer_address_validator.Validate(address); //validate address

            if (!results.IsValid)                                                            //invalid - show error
            {
                String result_messages = results.ToString("\n");
                await Application.Current.MainPage.DisplayAlert("Error", result_messages, "OK");
            }
            else //valid try to save address
            {
                AddressRestService          addressRestService          = new AddressRestService();
                Customer_AddressRestService customer_AddressRestService = new Customer_AddressRestService();
                Address created_address = await addressRestService.SaveAddressAsync(address, true); //save address entry to db

                Customer_Address customer_Address = new Customer_Address();

                //gather customer_address data
                customer_Address.CustomerID   = (int)Application.Current.Properties["customerID"];
                customer_Address.AddressID    = created_address.AddressID;
                customer_Address.AddressLabel = customer_address.AddressLabel;
                try //to save customer_address entry to db
                {
                    await customer_AddressRestService.SaveCustomer_AddressAsync(customer_Address, true);

                    await Application.Current.MainPage.DisplayAlert("Success", "Address Saved", "OK");

                    await Application.Current.MainPage.Navigation.PushAsync(new AccountManagementPage());
                }
                catch (Exception e)
                {
                    await Application.Current.MainPage.DisplayAlert("Error", e.Message, "OK");
                }
            }
        }
Beispiel #8
0
        public ActionResult CreateUpdate(Customer data, List <Customer_Address> details)
        {
            try
            {
                using (var dbConn = Helpers.OrmliteConnection.openConn())
                {
                    try
                    {
                        if (data.id > 0)
                        {
                            if (accessDetail != null && (accessDetail.access["all"] || accessDetail.access["update"]))
                            {
                                data.ngay_cap_nhat  = DateTime.Now;
                                data.nguoi_cap_nhat = User.Identity.Name;
                                dbConn.UpdateOnly(data,
                                                  onlyFields: p =>
                                                  new
                                {
                                    p.email,
                                    p.sdt,
                                    p.hoten,
                                    p.ngay_cap_nhat,
                                    p.nguoi_cap_nhat
                                },
                                                  where : p => p.id == data.id);
                            }
                            else
                            {
                                return(Json(new { success = false, error = "Don't have permission to update" }));
                            }
                        }
                        else
                        {
                            if (accessDetail != null && (accessDetail.access["all"] || accessDetail.access["create"]))
                            {
                                var lastId = dbConn.FirstOrDefault <Customer>("SELECT TOP 1 * FROM Customer ORDER BY ma_khach_hang DESC");
                                if (lastId != null)
                                {
                                    var nextNo = Int32.Parse(lastId.ma_khach_hang.Substring(2, 8)) + 1;
                                    data.ma_khach_hang = "KH" + String.Format("{0:00000000}", nextNo);
                                }
                                else
                                {
                                    data.ma_khach_hang = "KH00000001";
                                }

                                data.ma_user       = "******";
                                data.ngay_tao      = DateTime.Now;
                                data.nguoi_tao     = User.Identity.Name;
                                data.ngay_cap_nhat = DateTime.Parse("01/01/1900");

                                dbConn.Insert(data);
                                int Id = (int)dbConn.GetLastInsertId();
                                data.id = Id;
                                var checkMerchant_Customer = dbConn.FirstOrDefault <Merchant_Customer>("ma_gian_hang={0} and ma_khach_hang={1}".Params(currentUser.ma_gian_hang, data.ma_khach_hang));
                                if (checkMerchant_Customer == null)
                                {
                                    Merchant_Customer mc = new Merchant_Customer();
                                    mc.ma_gian_hang  = currentUser.ma_gian_hang;
                                    mc.ma_khach_hang = data.ma_khach_hang;
                                    dbConn.Insert(mc);
                                }
                            }
                            else
                            {
                                return(Json(new { success = false, error = "Don't have permission to create" }));
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        return(Json(new { success = false, error = "Lỗi" }));
                    }

                    try
                    {
                        if (accessDetail != null && (accessDetail.access["all"] || accessDetail.access["create"]))
                        {
                            //Xoa tat ca dia chi hien tai
                            string ma_kh = dbConn.QueryScalar <string>("select ma_khach_hang from Customer where id = " + data.id + " ");
                            string st    = new Customer_DAO().Delete(ma_kh, AppConfigs.MCCConnectionString);
                            //Tạo CustomerAddress
                            if (details != null)
                            {
                                Customer         Customertinfo = new Customer();
                                Customer_Address exist         = new Customer_Address();
                                foreach (Customer_Address item in details)
                                {
                                    Customertinfo      = dbConn.FirstOrDefault <Customer>("ma_khach_hang={0}", ma_kh);
                                    exist              = dbConn.FirstOrDefault <Customer_Address>("ma_khach_hang={0}".Params(ma_kh));
                                    item.ma_khach_hang = data.ma_khach_hang;
                                    item.id            = dbConn.QueryScalar <int>("select MAX(id)+1 from Customer_Address");
                                    item.ma_user       = "";
                                    item.ngay_tao      = DateTime.Now;
                                    dbConn.Insert(item);
                                }
                            }
                        }
                        else
                        {
                            return(Json(new { success = false, error = "Không có quyền tạo" }));
                        }
                    }
                    catch (Exception e)
                    {
                        return(Json(new { success = false, error = "Lỗi" }));
                    }
                }
                return(Json(new { success = true, data = data }));
            }
            catch (Exception e)
            {
                return(Json(new { success = false, error = e.Message }));
            }
        }