Пример #1
0
        public ActionResult Add(ProductBrandAddEditViewModel formData)
        {
            ProductBrand brand = new ProductBrand()
            {
                Name = formData.Name,
            };

            if (!brand.Exists())
            {
                brand.Add();
                return(RedirectToAction("Add"));
            }
            else
            {
                string        message   = "An Error occured when trying to add new brand.";
                List <string> solutions = new List <string>();
                solutions.Add("Brand Already exists");
                ErrorHelp error = new ErrorHelp()
                {
                    Message   = message,
                    Solutions = solutions
                };

                return(View("_ErrorView", error));
            }
        }
        public ActionResult Edit(Product formData)
        {
            Product product = new Product()
            {
                Id          = formData.Id,
                BrandId     = formData.BrandId,
                CategoryId  = formData.CategoryId,
                Description = formData.Description,
            };

            if (!product.Exists)
            {
                product.Update();
                return(RedirectToAction("Display"));
            }
            else
            {
                string        message   = "An Error occured when trying to edit product.";
                List <string> solutions = new List <string>();
                solutions.Add("Product Already exists");
                ErrorHelp error = new ErrorHelp()
                {
                    Message   = message,
                    Solutions = solutions
                };

                return(View("_ErrorView", error));
            }
        }
        public ActionResult Add(ProductAddEditViewModel formData)
        {
            Product product = new Product()
            {
                BrandId     = formData.BrandId,
                CategoryId  = formData.CategoryId,
                Description = formData.Description
            };

            if (!product.Exists)
            {
                product.Save();
                return(RedirectToAction("Add"));
            }
            else
            {
                string        message   = "An Error occured when trying to add new product.";
                List <string> solutions = new List <string>();
                solutions.Add("Product Already exists");
                ErrorHelp error = new ErrorHelp()
                {
                    Message   = message,
                    Solutions = solutions
                };

                return(View("_ErrorView", error));
            }
        }
        public ActionResult Edit(CategoryAddEditViewModel formData)
        {
            Category category = new Category()
            {
                Id   = formData.Id,
                Name = formData.Name
            };

            if (!category.Exists)
            {
                category.Update();
                return(RedirectToAction("display"));
            }
            else
            {
                string        message   = "An Error occured when trying to edit category.";
                List <string> solutions = new List <string>();
                solutions.Add("Category Already exists");
                ErrorHelp error = new ErrorHelp()
                {
                    Message   = message,
                    Solutions = solutions
                };

                return(View("_ErrorView", error));
            }
        }
        public ActionResult Add(InventoryAddViewModel formData)
        {
            Product   product   = Product.All(p => p.BrandId == formData.BrandId && p.Description == formData.Description).Single();
            Inventory inventory = new Inventory()
            {
                ProductId        = product.Id,
                PricePaidPerUnit = formData.PricePaidPerUnit,
                UnitsPurchased   = formData.UnitsPurchased,
                UnitsSold        = formData.UnitsSold
            };

            if (!inventory.Exists)
            {
                inventory.Save();
                return(RedirectToAction("Add"));
            }
            else
            {
                string        message   = "An Error occured when trying to add new inventory.";
                List <string> solutions = new List <string>();
                solutions.Add("Inventory Already exists");
                ErrorHelp error = new ErrorHelp()
                {
                    Message   = message,
                    Solutions = solutions
                };

                return(View("_ErrorView", error));
            }
        }
Пример #6
0
        private static HttpResponseException ReportToLogAndThrow(HttpRequestMessage request, HttpStatusCode code, Exception e, string msg, Func <string, HttpControllerDescriptor, HttpControllerDescriptor> wrapLog)
        {
            var helpText  = ErrorHelp.HelpText(e);
            var exception = new Exception(msg + helpText, e);

            DotNetNuke.Services.Exceptions.Exceptions.LogException(exception);
            wrapLog("error", null);
            return(new HttpResponseException(request.CreateErrorResponse(code, exception.Message, e)));
        }
Пример #7
0
        internal static HttpResponseException ReportToLogAndThrow <T>(HttpRequestMessage request, HttpStatusCode code, Exception e, string msg, Func <string, T, T> wrapLog)
        {
            var helpText  = ErrorHelp.HelpText(e);
            var exception = new Exception(msg + helpText, e);

            DotNetNuke.Services.Exceptions.Exceptions.LogException(exception);
            wrapLog("error", default);
            return(new HttpResponseException(request.CreateErrorResponse(code, exception.Message, e)));
        }
Пример #8
0
        public ActionResult Delete(int id)
        {
            try
            {
                ProductBrand brand = ProductBrand.GetById(id);
                brand.Remove();
                return(RedirectToAction("Display"));
            }
            catch
            {
                string        message   = "An Error occured when trying to delete brand.";
                List <string> solutions = new List <string>();
                solutions.Add("Ensure that the brand you're trying to delete is not a part of your product list");
                ErrorHelp error = new ErrorHelp()
                {
                    Message   = message,
                    Solutions = solutions
                };

                return(View("_ErrorView", error));
            }
        }
        public ActionResult Add(CategoryAddEditViewModel categoryFormData)
        {
            Category category = new Category(categoryFormData.Name);

            if (!category.Exists)
            {
                category.Save();
                return(RedirectToAction("add"));
            }
            else
            {
                string        message   = "An Error occured when trying to add new category.";
                List <string> solutions = new List <string>();
                solutions.Add("Category Already exists");
                ErrorHelp error = new ErrorHelp()
                {
                    Message   = message,
                    Solutions = solutions
                };

                return(View("_ErrorView", error));
            }
        }
Пример #10
0
        public HttpControllerDescriptor SelectController(HttpRequestMessage request)
        {
            // Log this lookup and add to history for insights
            var log = new Log("Sxc.Http", null, request?.RequestUri?.AbsoluteUri);

            AddToInsightsHistory(request?.RequestUri?.AbsoluteUri, log);

            var wrapLog = log.Call <HttpControllerDescriptor>();

            if (!HandleRequestWithThisController(request))
            {
                return(wrapLog("upstream", PreviousSelector.SelectController(request)));
            }

            var routeData          = request.GetRouteData();
            var controllerTypeName = routeData.Values[RouteParts.ControllerKey] + "Controller";

            // Handle the app-api queries
            try
            {
                var appFolder = Route.AppPathOrNull(routeData);

                if (appFolder == null)
                {
                    log.Add("no folder found in url, will auto-detect");
                    var sexy = Helpers.GetCmsBlock(request, false, log);
                    appFolder = sexy.App.Folder;
                }

                log.Add($"App Folder: {appFolder}");

                // new for 2sxc 9.34 #1651
                var edition = "";
                if (routeData.Values.ContainsKey(RouteParts.EditionKey))
                {
                    edition = routeData.Values[RouteParts.EditionKey].ToString();
                }
                if (!string.IsNullOrEmpty(edition))
                {
                    edition += "/";
                }

                log.Add($"Edition: {edition}");

                var controllerFolder = Path.Combine(DnnMapAppToInstance.AppBasePath(), appFolder,
                                                    edition + "api/");

                controllerFolder = controllerFolder.Replace("\\", @"/");
                log.Add($"Controller Folder: {controllerFolder}");

                var controllerPath = Path.Combine(controllerFolder + controllerTypeName + ".cs");
                log.Add($"Controller Path: {controllerPath}");

                // note: this may look like something you could optimize/cache the result, but that's a bad idea
                // because when the file changes, the type-object will be different, so please don't optimize :)
                if (File.Exists(HostingEnvironment.MapPath(controllerPath)))
                {
                    var assembly = BuildManager.GetCompiledAssembly(controllerPath);
                    var type     = assembly.GetType(controllerTypeName, true, true);

                    // help with path resolution for compilers running inside the created controller
                    request?.Properties.Add(CodeCompiler.SharedCodeRootPathKeyInCache, controllerFolder);

                    var descriptor = new HttpControllerDescriptor(_config, type.Name, type);
                    return(wrapLog("ok", descriptor));
                }

                log.Add("path not found");
            }
            catch (Exception e)
            {
                var apiErrPrefix = "2sxc Api Controller Finder: " +
                                   "Error selecting / compiling an API controller. " +
                                   "Check event-log, code and inner exception. ";
                var helpText  = ErrorHelp.HelpText(e);
                var exception = new Exception(apiErrPrefix + helpText, e);
                DotNetNuke.Services.Exceptions.Exceptions.LogException(exception);
                wrapLog("error", null);
                throw new HttpResponseException(request.CreateErrorResponse(HttpStatusCode.InternalServerError, exception.Message, e));
            }

            wrapLog("error", null);
            throw new HttpResponseException(request.CreateErrorResponse(HttpStatusCode.NotFound, "2sxc Api Controller Finder: Controller " + controllerTypeName + " not found in app."));
        }