예제 #1
0
        public static string GetCustomerRowJsonString(int customerId)
        {
            var helper = new HelperRepository();
            var customer = helper.GetCustomer(customerId);
            var user = helper.GetUserByCustomerId(customerId);

            var result = new Dictionary<string, object>
            {
                ["firstname"] = customer.Name,
                ["middlename"] = customer.MiddleName ?? string.Empty,
                ["lastname"] = customer.LastName,
                ["email"] = user.Email,
                ["role"] = helper.GetRoleNameById(user.RoleId),
                ["id"] = customerId
            };

            return new JavaScriptSerializer().Serialize(result);
        }
예제 #2
0
        public static string GetOrderRowJsonString(int orderId)
        {
            var helper = new HelperRepository();
            var order = helper.GetOrder(orderId);
            var customer = helper.GetCustomer(order.CustomerId);
            var product = helper.GetProduct(order.ProductId);

            var result = new Dictionary<string, object>
            {
                ["customername"] = $"{customer.LastName}, {customer.Name}",
                ["productname"] = product.Name,
                ["quantity"] = order.Count,
                ["totalamount"] = order.Count*product.Price,
                ["date"] = order.Date.ToString("f"),
                ["id"] = orderId
            };

            return new JavaScriptSerializer().Serialize(result);
        }
예제 #3
0
        public ActionResult Delete(int id)
        {
            var result = new Dictionary<string, object>
            {
                ["isSuccess"] = false,
                ["error"] = "Something was wrong. Customer not found"
            };

            var helper = new HelperRepository();
            var customer = helper.GetCustomer(id);

            if (helper.DeleteCustomer(id))
            {
                result["success"] = $"Customer {customer.Name} {customer.LastName} has been successfully deleted";
                result["isSuccess"] = true;
            }

            return this.Json(result);
        }