public JsonResult AddressAdd(string userGuid)
        {
            addressModelItem item = new addressModelItem();
            userShared us = new userShared(db);

            var userItem = us.getUserByGuid(userGuid);

            //Close Url
            pageShared ps = new pageShared(db);
            var mainPage = ps.getPageByType(pageType.account, langId);
            var addressPage = ps.getPageByType(pageType.accountAddress, langId);
            item.closeUrl = getSiteName(Request) + langCode + "/" + mainPage.url + "/" + addressPage.url + ".html";

            if (userItem == null)
            {
                item.isMessageExist = true;
                item.message = getErrorMessage(lang.unexpectedErrorMsg);

                return Json(new { html = RenderRazorViewToString("AddressAdd", item) }, JsonRequestBehavior.AllowGet);
            }

            item.guid = userItem.guid;
            item.addressItem = new tbl_address();
            item.addressItem.isPersonal = true;

            string htmlText = RenderRazorViewToString("AddressAdd", item);
            return Json(new { html = htmlText }, JsonRequestBehavior.AllowGet);
        }
        public JsonResult AddressAdd(addressModelItem item)
        {
            System.Threading.Thread.Sleep(1500);

            //Close Url
            pageShared ps = new pageShared(db);
            addressShared ads = new addressShared(db);
            var mainPage = ps.getPageByType(pageType.account, langId);
            var addressPage = ps.getPageByType(pageType.accountAddress, langId);
            item.closeUrl = getSiteName(Request) + langCode + "/" + mainPage.url + "/" + addressPage.url + ".html";
            int addressId = 0;

            userShared us = new userShared(db);
            var userItem = us.getUserByGuid(item.guid);

            if (userItem == null)
            {
                item.isMessageExist = true;
                item.message = getErrorMessage(lang.unexpectedErrorMsg);

                return Json(new { html = RenderRazorViewToString("AddressAdd", item) }, JsonRequestBehavior.AllowGet);
            }

            extraValidation(item);

            if (ModelState.IsValid)
            {

                try
                {
                    item.addressItem.userId = userItem.userId;
                    item.addressItem.statu = true;
                    item.addressItem = ads.addAddress(item.addressItem);

                    item.isMessageExist = true;
                    item.message = getSuccesMessage(lang.addressAddSuccess);
                    item.isSuccess = true;
                    addressId = item.addressItem.addressId;

                }
                catch (Exception ex)
                {
                    errorSend(ex, "Account Address Add", true);

                    item.isMessageExist = true;
                    item.message = getErrorMessage(lang.unexpectedErrorMsg);

                }

            }

            string htmlText = RenderRazorViewToString("AddressAdd", item);
            return Json(new { html = htmlText, addressId = addressId });
        }
        public JsonResult AddressEdit(addressModelItem item)
        {
            System.Threading.Thread.Sleep(1500);

            //Close Url
            pageShared ps = new pageShared(db);
            addressShared ads = new addressShared(db);
            var mainPage = ps.getPageByType(pageType.account, langId);
            var addressPage = ps.getPageByType(pageType.accountAddress, langId);
            item.closeUrl = getSiteName(Request) + langCode + "/" + mainPage.url + "/" + addressPage.url + ".html";

            userShared us = new userShared(db);
            var userItem = us.getUserByGuid(item.guid);

            if (userItem == null || item.addressItem == null || item.addressItem.userId != userItem.userId)
            {
                item.isMessageExist = true;
                item.message = getErrorMessage(lang.unexpectedErrorMsg, "autoHide");

                return Json(new { html = RenderRazorViewToString("AddressEdit", item) }, JsonRequestBehavior.AllowGet);
            }

            extraValidation(item);

            if (ModelState.IsValid)
            {
                try
                {
                    item.addressItem.userId = userItem.userId;
                    item.addressItem.statu = true;

                    var updateItem = ads.getAddressById(item.addressItem.addressId);
                    db.Entry<tbl_address>(updateItem).CurrentValues.SetValues(item.addressItem);
                    db.SaveChanges();

                    item.isMessageExist = true;
                    item.message = getSuccesMessage(lang.addressEditSuccess, "autoHide");
                    item.isSuccess = true;

                }
                catch (Exception ex)
                {
                    errorSend(ex, "Account Address Edit", true);
                    item.isMessageExist = true;
                    item.message = getErrorMessage(lang.unexpectedErrorMsg, "autoHide");
                }
            }

            string htmlText = RenderRazorViewToString("AddressEdit", item);
            return Json(new { html = htmlText });
        }
        public JsonResult AddressDetail(string userGuid, int addressId)
        {
            userShared us = new userShared(db);
            addressShared ads = new addressShared(db);

            var userItem = us.getUserByGuid(userGuid);
            var addressItem = ads.getAddressById(addressId);

            addressModelItem item = new addressModelItem();

            if (userItem == null || addressItem == null || addressItem.userId != userItem.userId)
            {
                item.isMessageExist = true;
                item.message = getErrorMessage(lang.unexpectedErrorMsg);
            }

            item.addressItem = addressItem;

            return Json(new { html = RenderRazorViewToString("AddressDetail", item) }, JsonRequestBehavior.AllowGet);
        }
        public JsonResult AddressDelete(addressModelItem item)
        {
            System.Threading.Thread.Sleep(1500);

            //Close Url
            pageShared ps = new pageShared(db);
            addressShared ads = new addressShared(db);
            var mainPage = ps.getPageByType(pageType.account, langId);
            var addressPage = ps.getPageByType(pageType.accountAddress, langId);
            item.closeUrl = getSiteName(Request) + langCode + "/" + mainPage.url + "/" + addressPage.url + ".html";

            userShared us = new userShared(db);
            var userItem = us.getUserByGuid(item.guid);

            if (userItem == null || item.addressItem == null || item.addressItem.userId != userItem.userId)
            {
                item.isMessageExist = true;
                item.message = getErrorMessage(lang.unexpectedErrorMsg, "autoHide");

                return Json(new { html = RenderRazorViewToString("AddressEdit", item) }, JsonRequestBehavior.AllowGet);
            }

            try
            {

                ads.updateAddressIsDeleted(item.addressItem.addressId);
                item.isMessageExist = true;
                item.message = getSuccesMessage(lang.deleteAddressSuccess);
                item.isSuccess = true;

            }
            catch (Exception ex)
            {
                errorSend(ex, "Account Address Delete", true);
                item.isMessageExist = true;
                item.message = getErrorMessage(lang.unexpectedErrorMsg, "autoHide");
            }

            string htmlText = RenderRazorViewToString("AddressDelete", item);
            return Json(new { html = htmlText });
        }
        public JsonResult AddressDelete(string userGuid, int addressId)
        {
            userShared us = new userShared(db);
            addressShared ads = new addressShared(db);

            var userItem = us.getUserByGuid(userGuid);
            var addressItem = ads.getAddressById(addressId);

            addressModelItem item = new addressModelItem();

            if (userItem == null || addressItem == null || addressItem.userId != userItem.userId)
            {
                item.isMessageExist = true;
                item.message = getErrorMessage(lang.unexpectedErrorMsg);
                item.addressItem = new tbl_address();
                item.guid = "";
            }
            else
            {
                item.guid = userItem.guid;
                item.addressItem = addressItem;
            }

            //Close Url
            pageShared ps = new pageShared(db);
            var mainPage = ps.getPageByType(pageType.account, langId);
            var addressPage = ps.getPageByType(pageType.accountAddress, langId);
            item.closeUrl = getSiteName(Request) + langCode + "/" + mainPage.url + "/" + addressPage.url + ".html";

            return Json(new { html = RenderRazorViewToString("AddressDelete", item) }, JsonRequestBehavior.AllowGet);
        }