Example #1
0
        public HttpResponseMessage add(AdditionalService post, Int32 languageId = 0)
        {
            // Check for errors
            if (post == null)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The post is null"));
            }
            else if (Language.MasterPostExists(languageId) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The language does not exist"));
            }
            else if (Unit.MasterPostExists(post.unit_id) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The unit does not exist"));
            }
            else if (ValueAddedTax.MasterPostExists(post.value_added_tax_id) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The value added tax does not exist"));
            }

            // Make sure that the data is valid
            post.product_code = AnnytabDataValidation.TruncateString(post.product_code, 50);
            post.name         = AnnytabDataValidation.TruncateString(post.name, 100);
            post.fee          = AnnytabDataValidation.TruncateDecimal(post.fee, 0, 9999999999.99M);
            post.account_code = AnnytabDataValidation.TruncateString(post.account_code, 10);

            // Add the post
            Int64 insertId = AdditionalService.AddMasterPost(post);

            post.id = Convert.ToInt32(insertId);
            AdditionalService.AddLanguagePost(post, languageId);

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

            // Get query parameters
            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
            Int32 id = Convert.ToInt32(collection["txtId"]);
            string product_code = collection["txtProductCode"];
            string name = collection["txtName"];
            decimal fee = 0;
            decimal.TryParse(collection["txtFee"].Replace(",", "."), NumberStyles.Any, CultureInfo.InvariantCulture, out fee);
            Int32 unit_id = Convert.ToInt32(collection["selectUnit"]);
            bool price_based_on_mount_time = Convert.ToBoolean(collection["cbPriceBasedOnMountTime"]);
            Int32 value_added_tax_id = Convert.ToInt32(collection["selectValueAddedTax"]);
            string account_code = collection["txtAccountCode"];
            bool inactive = Convert.ToBoolean(collection["cbInactive"]);

            // Get the default admin language id
            Int32 adminLanguageId = currentDomain.back_end_language;

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

            // Get the additional service
            AdditionalService additionalService = AdditionalService.GetOneById(id, adminLanguageId);

            // Check if the additional service exists
            if (additionalService == null)
            {
                // Create a empty additional service
                additionalService = new AdditionalService();
            }

            // Update values
            additionalService.product_code = product_code;
            additionalService.name = name;
            additionalService.fee = fee;
            additionalService.unit_id = unit_id;
            additionalService.price_based_on_mount_time = price_based_on_mount_time;
            additionalService.value_added_tax_id = value_added_tax_id;
            additionalService.account_code = account_code;
            additionalService.inactive = inactive;

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

            // Check for errors in the additional service
            if (additionalService.product_code.Length > 50)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_length"), tt.Get("product_code"), "50") + "<br/>";
            }
            if (additionalService.name.Length > 100)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_length"), tt.Get("name"), "100") + "<br/>";
            }
            if (additionalService.fee < 0 || additionalService.fee > 9999999999.99M)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_range"), tt.Get("fee"), "9 999 999 999.99") + "<br/>";
            }
            if (additionalService.account_code.Length > 10)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_length"), tt.Get("account_code"), "10") + "<br/>";
            }
            if (additionalService.unit_id == 0)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_select_value"), tt.Get("unit").ToLower()) + "<br/>";
            }
            if (additionalService.value_added_tax_id == 0)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_select_value"), tt.Get("value_added_tax").ToLower()) + "<br/>";
            }

            // Check if there is errors
            if (errorMessage == "")
            {
                // Check if we should add or update the additional service
                if (additionalService.id == 0)
                {
                    // Add the additional service
                    Int64 insertId = AdditionalService.AddMasterPost(additionalService);
                    additionalService.id = Convert.ToInt32(insertId);
                    AdditionalService.AddLanguagePost(additionalService, adminLanguageId);
                }
                else
                {
                    // Update the additional service
                    AdditionalService.UpdateMasterPost(additionalService);
                    AdditionalService.UpdateLanguagePost(additionalService, adminLanguageId);
                }

                // Redirect the user to the list
                return Redirect("/admin_additional_services" + returnUrl);
            }
            else
            {
                // Set form values
                ViewBag.ErrorMessage = errorMessage;
                ViewBag.Units = Unit.GetAll(adminLanguageId, "name", "ASC");
                ViewBag.AdditionalService = additionalService;
                ViewBag.TranslatedTexts = tt;
                ViewBag.ReturnUrl = returnUrl;

                // Return the edit view
                return View("edit");
            }

        } // End of the edit method