예제 #1
0
        public GiftCard get_by_id(string id = "")
        {
            // Create the post to return
            GiftCard post = GiftCard.GetOneById(id);

            // Return the post
            return(post);
        } // End of the get_by_id method
예제 #2
0
        public ActionResult orders(string id = "", string returnUrl = "")
        {
            // Get the current domain
            Domain currentDomain = Tools.GetCurrentDomain();

            ViewBag.CurrentDomain = currentDomain;

            // Get query parameters
            ViewBag.QueryParams = new QueryParams(returnUrl);

            // Check if the administrator is authorized
            if (Administrator.IsAuthorized(new string[] { "Administrator", "Editor", "Translator" }) == 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 the gift card
            GiftCard giftCard = GiftCard.GetOneById(id);

            // Check if the gift card is null
            if (giftCard == null)
            {
                return(RedirectToAction("index"));
            }

            // Set form data
            ViewBag.CurrentDomain   = currentDomain;
            ViewBag.GiftCard        = giftCard;
            ViewBag.OrderGiftCards  = OrderGiftCard.GetByGiftCardId(giftCard.id, "order_id", "ASC");
            ViewBag.TranslatedTexts = StaticText.GetAll(currentDomain.back_end_language, "id", "ASC");
            ViewBag.CultureInfo     = Tools.GetCultureInfo(Language.GetOneById(currentDomain.back_end_language));
            ViewBag.ReturnUrl       = returnUrl;

            // Return the view
            return(View());
        } // End of the orders method
예제 #3
0
        public ActionResult edit(string id = "", string returnUrl = "")
        {
            // Get the current domain
            Domain currentDomain = Tools.GetCurrentDomain();

            ViewBag.CurrentDomain = currentDomain;

            // Get query parameters
            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"));
            }

            // Add data to the view
            ViewBag.TranslatedTexts = StaticText.GetAll(currentDomain.back_end_language, "id", "ASC");
            ViewBag.Languages       = Language.GetAll(currentDomain.back_end_language, "name", "ASC");
            ViewBag.GiftCard        = GiftCard.GetOneById(id);
            ViewBag.ReturnUrl       = returnUrl;

            // Create a new empty gift card post if the gift card does not exist
            if (ViewBag.GiftCard == null)
            {
                // Add data to the view
                ViewBag.GiftCard = new GiftCard();
            }

            // Return the edit view
            return(View("edit"));
        } // End of the edit method
예제 #4
0
        public HttpResponseMessage update(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);

            // Get the saved post
            GiftCard savedPost = GiftCard.GetOneById(post.id);

            // Check if the post exists
            if (savedPost == null)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The record does not exist"));
            }

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

            // Return the success response
            return(Request.CreateResponse <string>(HttpStatusCode.OK, "The update was successful"));
        } // End of the update method
예제 #5
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