예제 #1
0
        public HttpResponseMessage add(GiftCard post)
        {
            // Check for errors
            if (post == null)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The post is null"));
            }
            else if (Language.MasterPostExists(post.language_id) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The language does not exist"));
            }
            else if (Currency.MasterPostExists(post.currency_code) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The currency does not exist"));
            }

            // Make sure that the data is valid
            post.id       = AnnytabDataValidation.TruncateString(post.id, 50);
            post.amount   = AnnytabDataValidation.TruncateDecimal(post.amount, 0, 999999999999M);
            post.end_date = AnnytabDataValidation.TruncateDateTime(post.end_date);

            // Check if the gift card exists
            if (GiftCard.MasterPostExists(post.id) == true)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The id already exists"));
            }

            // Add the post
            GiftCard.Add(post);

            // Return the success response
            return(Request.CreateResponse <string>(HttpStatusCode.OK, "The post has been added"));
        } // End of the add method
예제 #2
0
        public ActionResult Edit(FormCollection collection)
        {
            // Get the current domain
            Domain currentDomain = Tools.GetCurrentDomain();

            ViewBag.CurrentDomain = currentDomain;

            // Get the return url
            string returnUrl = collection["returnUrl"];

            ViewBag.QueryParams = new QueryParams(returnUrl);

            // Check if the administrator is authorized
            if (Administrator.IsAuthorized(new string[] { "Administrator", "Editor" }) == true)
            {
                ViewBag.AdminSession = true;
            }
            else if (Administrator.IsAuthorized(Administrator.GetAllAdminRoles()) == true)
            {
                ViewBag.AdminSession    = true;
                ViewBag.AdminErrorCode  = 1;
                ViewBag.TranslatedTexts = StaticText.GetAll(currentDomain.back_end_language, "id", "ASC");
                return(View("index"));
            }
            else
            {
                // Redirect the user to the start page
                return(RedirectToAction("index", "admin_login"));
            }

            // Get all the form values
            string  id            = collection["txtId"];
            Int32   language_id   = Convert.ToInt32(collection["selectLanguage"]);
            string  currency_code = collection["selectCurrency"];
            decimal amount        = 0;

            decimal.TryParse(collection["txtAmount"].Replace(",", "."), NumberStyles.Any, CultureInfo.InvariantCulture, out amount);
            DateTime end_date = Convert.ToDateTime(collection["txtEndDate"]);

            // Get translated texts
            KeyStringList tt = StaticText.GetAll(currentDomain.back_end_language, "id", "ASC");

            // Get the gift card
            GiftCard giftCard   = GiftCard.GetOneById(id);
            bool     postExists = true;

            // Check if the gift card exists
            if (giftCard == null)
            {
                // Create an empty gift card
                giftCard   = new GiftCard();
                postExists = false;
            }

            // Update values
            giftCard.id            = id;
            giftCard.language_id   = language_id;
            giftCard.currency_code = currency_code;
            giftCard.amount        = amount;
            giftCard.end_date      = AnnytabDataValidation.TruncateDateTime(end_date);

            // Create a error message
            string errorMessage = string.Empty;

            if (giftCard.id.Length == 0 || giftCard.id.Length > 50)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_certain_length"), tt.Get("id"), "1", "50") + "<br/>";
            }
            if (giftCard.language_id == 0)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_select_value"), tt.Get("language").ToLower()) + "<br/>";
            }
            if (giftCard.currency_code == "")
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_select_value"), tt.Get("currency").ToLower()) + "<br/>";
            }
            if (giftCard.amount < 0 || giftCard.amount > 999999999999M)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_range"), tt.Get("amount"), "999 999 999 999") + "<br/>";
            }

            // Check if there is errors
            if (errorMessage == string.Empty)
            {
                // Check if we should add or update the gift card
                if (postExists == false)
                {
                    // Add the gift card
                    GiftCard.Add(giftCard);
                }
                else
                {
                    // Update the gift card
                    GiftCard.Update(giftCard);
                }

                // Redirect the user to the list
                return(Redirect("/admin_gift_cards" + returnUrl));
            }
            else
            {
                // Set form values
                ViewBag.ErrorMessage    = errorMessage;
                ViewBag.TranslatedTexts = tt;
                ViewBag.Languages       = Language.GetAll(currentDomain.back_end_language, "id", "ASC");
                ViewBag.GiftCard        = giftCard;
                ViewBag.ReturnUrl       = returnUrl;

                // Return the edit view
                return(View("edit"));
            }
        } // End of the edit method
예제 #3
0
        private void InitGiftCard()
        {
            GiftCard.Clear();
            DataTable GiftCards = GiftCardModel.advanceSearchGiftCardByMultiCondition(this._txtKeySearch, paging.StringLimit, this._txtSortBy);

            if (GiftCards.Rows.Count == 0 && paging.CurrentPage > 1)
            {
                paging.CurrentPage = paging.CurrentPage - 1;
                GiftCards          = GiftCardModel.advanceSearchGiftCardByMultiCondition(this._txtKeySearch, paging.StringLimit, this._txtSortBy);
                ShowCurPage        = paging.CurrentPage;
            }
            if (GiftCards.Rows.Count > 0)
            {
                var i = 1;
                foreach (DataRow dr in GiftCards.Rows)
                {
                    DateTime dt           = UnixTimeToDateTime(Convert.ToInt32(dr["CreateDate"]));
                    DateTime _expreTime   = UnixTimeToDateTime(Convert.ToInt32(dr["ExpirationDate"].ToString()));
                    string   _giftCardImg = GiftCardModel.GiftCardImgPath + dr["Barcode"].ToString() + ".png";
                    string   _deliverDate = string.Empty;
                    if (Convert.ToInt32(dr["DeliveredDate"].ToString()) > 0)
                    {
                        DateTime _isDelivered = UnixTimeToDateTime(Convert.ToInt32(dr["DeliveredDate"].ToString()));
                        _deliverDate = _isDelivered.ToString(StaticClass.GeneralClass.dateFromatSettings[StaticClass.GeneralClass.app_settings["dateFormat"]].ToString() + _orderTime);
                    }
                    GiftCard.Add(new GiftCardModel {
                        No = i, GiftCardID = Convert.ToInt32(dr["GiftCardID"].ToString()), Barcode = dr["Barcode"].ToString(), Serial = dr["Serial"].ToString(), CreateDate = dt.ToString(StaticClass.GeneralClass.dateFromatSettings[StaticClass.GeneralClass.app_settings["dateFormat"]].ToString() + _orderTime), ExpirationDate = _expreTime.ToString(StaticClass.GeneralClass.dateFromatSettings[StaticClass.GeneralClass.app_settings["dateFormat"]].ToString() + _orderTime), CustomerIDUse = Convert.ToInt32(dr["CustomerIDUse"].ToString()), Amount = Convert.ToDouble(dr["Amount"].ToString()), Balance = Convert.ToDouble(dr["Balance"].ToString()), IsChecked = false, CustomerName = string.IsNullOrEmpty(dr["FullName"].ToString())?"None": dr["FullName"].ToString(), DeliveredDate = _deliverDate
                    });
                    i++;
                }
            }
            if (GiftCards.Rows.Count == 0 || (paging.CurrentPage == 1 && paging.MaxPage == 1))
            {
                ShowNextPage  = false;
                ShowLastPage  = false;
                ShowFirstPage = false;
                ShowPrevPage  = false;
                IsPaging      = "Hidden";

                /*if (GiftCards.Rows.Count == 0)
                 * {
                 *  ModernDialog md = new ModernDialog();
                 *  md.CloseButton.FindResource("close").ToString();
                 *  md.Content = App.Current.FindResource("cannot_found_data").ToString();
                 *  md.Title = App.Current.FindResource("notification").ToString();
                 *  md.ShowDialog();
                 * }*/
            }
            else if (paging.CurrentPage == paging.MaxPage)
            {
                ShowNextPage  = false;
                ShowLastPage  = false;
                ShowFirstPage = true;
                ShowPrevPage  = true;
            }
            else if (paging.MaxPage > 1)
            {
                IsPaging     = "Visible";
                ShowNextPage = true;
                ShowLastPage = true;
            }
            IsCheckAll = false;
        }
예제 #4
0
        private void onPagingClick(string _param)
        {
            if (_param == PageOptions.First.ToString())
            {
                paging.CurrentPage = 1;
                ShowNextPage       = true;
                ShowLastPage       = true;
                ShowFirstPage      = false;
                ShowPrevPage       = false;
            }
            else if (_param == PageOptions.Last.ToString())
            {
                paging.CurrentPage = paging.MaxPage;
                ShowNextPage       = false;
                ShowLastPage       = false;
                ShowFirstPage      = true;
                ShowPrevPage       = true;
            }
            else if (_param == PageOptions.Previous.ToString())
            {
                if (paging.CurrentPage == 1)
                {
                    ShowNextPage  = true;
                    ShowLastPage  = true;
                    ShowFirstPage = false;
                    ShowPrevPage  = false;
                }
                else
                {
                    paging.CurrentPage--;
                    ShowNextPage  = true;
                    ShowLastPage  = true;
                    ShowFirstPage = true;
                    ShowPrevPage  = true;
                }
            }
            else if (_param == PageOptions.Next.ToString())
            {
                if (paging.CurrentPage == paging.MaxPage)
                {
                    ShowNextPage  = false;
                    ShowLastPage  = false;
                    ShowFirstPage = true;
                    ShowPrevPage  = true;
                }
                else
                {
                    paging.CurrentPage++;
                    ShowNextPage  = true;
                    ShowLastPage  = true;
                    ShowFirstPage = true;
                    ShowPrevPage  = true;
                }
            }
            ShowCurPage = paging.CurrentPage;
            GiftCard.Clear();
            DataTable GiftCards = GiftCardModel.advanceSearchGiftCardByMultiCondition(this._txtKeySearch, paging.StringLimit, this._txtSortBy);

            if (GiftCards.Rows.Count > 0)
            {
                var i = 1;
                foreach (DataRow dr in GiftCards.Rows)
                {
                    DateTime dt         = UnixTimeToDateTime(Convert.ToInt32(dr["CreateDate"]));
                    DateTime _expreTime = UnixTimeToDateTime(Convert.ToInt32(dr["ExpirationDate"].ToString()));
                    string   _delivered = string.Empty;
                    if (Convert.ToInt32(dr["DeliveredDate"]) > 0)
                    {
                        DateTime _timeDeliver = UnixTimeToDateTime(Convert.ToInt32(dr["DeliveredDate"].ToString()));
                        _delivered = _timeDeliver.ToString(_orderDate);
                    }
                    string _customName = string.IsNullOrEmpty(dr["FullName"].ToString())? "None": dr["FullName"].ToString();
                    GiftCard.Add(new GiftCardModel {
                        No = i, GiftCardID = Convert.ToInt32(dr["GiftCardID"].ToString()), Barcode = dr["Barcode"].ToString(), Serial = dr["Serial"].ToString(), CreateDate = dt.ToString(_orderDate), ExpirationDate = _expreTime.ToString(_orderDate), CustomerIDUse = Convert.ToInt32(dr["CustomerIDUse"].ToString()), Amount = Convert.ToDouble(dr["Amount"].ToString()), Balance = Convert.ToDouble(dr["Balance"].ToString()), IsChecked = false, CustomerName = _customName, DeliveredDate = _delivered
                    });
                    i++;
                }
            }
            IsCheckAll = false;
        }