Exemplo n.º 1
0
        //
        // GET: /EDC/Category/Detail
        public async Task <ActionResult> Detail(string key)
        {
            using (CategoryServiceClient client = new CategoryServiceClient())
            {
                MethodReturnResult <Category> result = await client.GetAsync(key);

                if (result.Code == 0)
                {
                    CategoryViewModel viewModel = new CategoryViewModel()
                    {
                        Name        = result.Data.Key,
                        Status      = result.Data.Status,
                        CreateTime  = result.Data.CreateTime,
                        Creator     = result.Data.Creator,
                        Description = result.Data.Description,
                        Editor      = result.Data.Editor,
                        EditTime    = result.Data.EditTime
                    };
                    return(PartialView("_InfoPartial", viewModel));
                }
                else
                {
                    ModelState.AddModelError("", result.Message);
                }
            }
            return(PartialView("_InfoPartial"));
        }
        private void add_Click(object sender, RoutedEventArgs e)
        {
            ServiceReference4.Category c      = new ServiceReference4.Category();
            CategoryServiceClient      client = new CategoryServiceClient();

            client.Add(c);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Attempts to update the specified category.  Prints results to console.
 /// </summary>
 /// <param name="id">The ID of the category to update</param>
 /// <param name="name">The new name</param>
 /// <param name="description">The new description</param>
 private static void TestUpdateCategory(int id, string name, string description)
 {
     var catService = new CategoryServiceClient();
     try
     {
         Console.WriteLine(string.Format("\nAttempting to update category {0}.", id));
         if (name == null)
         {
             Console.WriteLine(string.Format(" - Name = null."));
         }
         if (description == null)
         {
             Console.WriteLine(string.Format(" - Description = null."));
         }
         var cat = new Category
                       {
                           ID = id,
                           Name = name,
                           Description = description
                       };
         catService.UpdateCategory(cat);
         Console.WriteLine(string.Format(" - Category Updated: ID = {0}, Name = {1}, Description = {2}", cat.ID, cat.Name,
                                         cat.Description));
     }
     catch (FaultException<CategoryFault> ex)
     {
         Console.WriteLine(string.Format(" - Update Exception: {0}", ex.Detail.FaultMessage));
     }
     catch (FaultException ex)
     {
         Console.WriteLine(string.Format(" - Update Exception: {0}", ex.Message));
     }
 }
Exemplo n.º 4
0
        public async Task <ActionResult> Query(CategoryQueryViewModel model)
        {
            if (ModelState.IsValid)
            {
                using (CategoryServiceClient client = new CategoryServiceClient())
                {
                    await Task.Run(() =>
                    {
                        StringBuilder where = new StringBuilder();
                        if (model != null)
                        {
                            if (!string.IsNullOrEmpty(model.Name))
                            {
                                where.AppendFormat(" {0} Key LIKE '{1}%'"
                                                   , where.Length > 0 ? "AND" : string.Empty
                                                   , model.Name);
                            }
                        }
                        PagingConfig cfg = new PagingConfig()
                        {
                            OrderBy = "Key",
                            Where   = where.ToString()
                        };
                        MethodReturnResult <IList <Category> > result = client.Get(ref cfg);

                        if (result.Code == 0)
                        {
                            ViewBag.PagingConfig = cfg;
                            ViewBag.List         = result.Data;
                        }
                    });
                }
            }
            return(PartialView("_ListPartial"));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Attempts to update the specified category.  Prints results to console.
        /// </summary>
        /// <param name="id">The ID of the category to update</param>
        /// <param name="name">The new name</param>
        /// <param name="description">The new description</param>
        private static void TestUpdateCategory(int id, string name, string description)
        {
            var catService = new CategoryServiceClient();

            try
            {
                Console.WriteLine(string.Format("\nAttempting to update category {0}.", id));
                if (name == null)
                {
                    Console.WriteLine(string.Format(" - Name = null."));
                }
                if (description == null)
                {
                    Console.WriteLine(string.Format(" - Description = null."));
                }
                var cat = new Category
                {
                    ID          = id,
                    Name        = name,
                    Description = description
                };
                catService.UpdateCategory(cat);
                Console.WriteLine(string.Format(" - Category Updated: ID = {0}, Name = {1}, Description = {2}", cat.ID, cat.Name,
                                                cat.Description));
            }
            catch (FaultException <CategoryFault> ex)
            {
                Console.WriteLine(string.Format(" - Update Exception: {0}", ex.Detail.FaultMessage));
            }
            catch (FaultException ex)
            {
                Console.WriteLine(string.Format(" - Update Exception: {0}", ex.Message));
            }
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            CategoryServiceClient client = new CategoryServiceClient("BasicHttpBinding_ICategoryService");

            bool service = true;

            Console.WriteLine("======== Welcome to the Order WCF Service ============");
            Console.WriteLine("Options : ");
            Console.WriteLine("Press 1 to get Category name");
            Console.WriteLine("Press 2 to get Category's product list");
            Console.WriteLine("Press 0 to exit.");
            Console.WriteLine("======================================================");

            while(service)
            {
                Console.WriteLine("# Enter your opcion 1, 2, 0 : ");
                int opc = int.Parse(Console.ReadLine());

                Console.WriteLine("Enter your category id : ");
                int id = int.Parse(Console.ReadLine());

                switch(opc)
                {
                    case 1:
                        Console.WriteLine("The category's name is : " + client.GetCategoryNameById(id));
                        break;
                    case 2:
                        Console.WriteLine("The " + client.GetCategoryNameById(id) + "'s product list : ");
                        var products = client.GetProducts(id);
                        if (products.Count() > 0)
                        {
                            int counter = 1;

                            foreach (ProductEntity p in products)
                            {
                                Console.WriteLine("#" + counter + "Product id : " + p.Id + " Product name : " + p.Name);
                            }
                        }
                        else 
                        {
                            Console.WriteLine("Products not found!!!");
                        }
                      
                        break;
                    case 0:
                        service = false;
                        break;
                }
            }

            Console.WriteLine("Thank you!! :) for use my Order Service");
            Console.ReadLine();
        }
Exemplo n.º 7
0
 /// <summary>
 /// Attempts to get a category and then outputs results to console.
 /// </summary>
 /// <param name="id">The ID of the category to retrieve</param>
 private static void TestGetCategory(int id)
 {
     var catService = new CategoryServiceClient();
     try
     {
         Console.WriteLine(string.Format("\nAttempting to retrieve category {0}.", id));
         Category cat = catService.GetCategory(id);
         Console.WriteLine(string.Format(" - Category Retrieved: ID = {0}, Name = {1}, Description = {2}", cat.ID, cat.Name,
                                         cat.Description));
     }
     catch (FaultException ex)
     {
         Console.WriteLine(string.Format(" - Get Exception: {0}", ex.Message));
     }
 }
Exemplo n.º 8
0
        private void PopulateComboboxes()
        {
            var catService = new CategoryServiceClient();

            cbCategory.DataSource    = catService.GetCategories();
            cbCategory.DisplayMember = "CategoryName";

            cbCategory.ValueMember = "Id";

            var ptService = new PaymentTypeServiceClient();

            cbPaymentType.DataSource    = ptService.GetPaymentTypes();
            cbPaymentType.DisplayMember = "Name";
            cbPaymentType.ValueMember   = "id";
        }
Exemplo n.º 9
0
        public async Task <ActionResult> Delete(string key)
        {
            MethodReturnResult result = new MethodReturnResult();

            using (CategoryServiceClient client = new CategoryServiceClient())
            {
                result = await client.DeleteAsync(key);

                if (result.Code == 0)
                {
                    result.Message = string.Format(EDCResources.StringResource.Category_Delete_Success
                                                   , key);
                }
                return(Json(result));
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Attempts to get a category and then outputs results to console.
        /// </summary>
        /// <param name="id">The ID of the category to retrieve</param>
        private static void TestGetCategory(int id)
        {
            var catService = new CategoryServiceClient();

            try
            {
                Console.WriteLine(string.Format("\nAttempting to retrieve category {0}.", id));
                Category cat = catService.GetCategory(id);
                Console.WriteLine(string.Format(" - Category Retrieved: ID = {0}, Name = {1}, Description = {2}", cat.ID, cat.Name,
                                                cat.Description));
            }
            catch (FaultException ex)
            {
                Console.WriteLine(string.Format(" - Get Exception: {0}", ex.Message));
            }
        }
Exemplo n.º 11
0
        private void btnSet_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(tbPath.Text))
            {
                MessageBox.Show(@"Не выбрано изображение.");
                return;
            }

            using (var serviceClient = new CategoryServiceClient())
            {
                using (var stream = new FileStream(tbPath.Text, FileMode.Open, FileAccess.Read))
                {
                    serviceClient.SetCategoryImage((int)cbCategories.SelectedValue, (int)stream.Length, stream);
                }
            }
            MessageBox.Show(@"Изображение отправлено");
        }
Exemplo n.º 12
0
        //
        // GET: /EDC/Category/
        public async Task <ActionResult> Index()
        {
            using (CategoryServiceClient client = new CategoryServiceClient())
            {
                await Task.Run(() =>
                {
                    PagingConfig cfg = new PagingConfig()
                    {
                        OrderBy = "Key"
                    };
                    MethodReturnResult <IList <Category> > result = client.Get(ref cfg);

                    if (result.Code == 0)
                    {
                        ViewBag.PagingConfig = cfg;
                        ViewBag.List         = result.Data;
                    }
                });
            }
            return(View(new CategoryQueryViewModel()));
        }
Exemplo n.º 13
0
        public IEnumerable <SelectListItem> GetCategoryList()
        {
            using (CategoryServiceClient client = new CategoryServiceClient())
            {
                PagingConfig cfg = new PagingConfig()
                {
                    IsPaging = false,
                    Where    = string.Format("Status='{0}'", Convert.ToInt32(EnumObjectStatus.Available))
                };

                MethodReturnResult <IList <Category> > result = client.Get(ref cfg);
                if (result.Code <= 0)
                {
                    return(from item in result.Data
                           select new SelectListItem()
                    {
                        Text = item.Key,
                        Value = item.Key
                    });
                }
            }
            return(new List <SelectListItem>());
        }
Exemplo n.º 14
0
        public async Task <ActionResult> PagingQuery(string where, string orderBy, int?currentPageNo, int?currentPageSize)
        {
            if (ModelState.IsValid)
            {
                int pageNo   = currentPageNo ?? 0;
                int pageSize = currentPageSize ?? 20;
                if (Request["PageNo"] != null)
                {
                    pageNo = Convert.ToInt32(Request["PageNo"]);
                }
                if (Request["PageSize"] != null)
                {
                    pageSize = Convert.ToInt32(Request["PageSize"]);
                }

                using (CategoryServiceClient client = new CategoryServiceClient())
                {
                    await Task.Run(() =>
                    {
                        PagingConfig cfg = new PagingConfig()
                        {
                            PageNo   = pageNo,
                            PageSize = pageSize,
                            Where    = where ?? string.Empty,
                            OrderBy  = orderBy ?? string.Empty
                        };
                        MethodReturnResult <IList <Category> > result = client.Get(ref cfg);
                        if (result.Code == 0)
                        {
                            ViewBag.PagingConfig = cfg;
                            ViewBag.List         = result.Data;
                        }
                    });
                }
            }
            return(PartialView("_ListPartial"));
        }
Exemplo n.º 15
0
        //
        // GET: /EDC/CategoryDetail/
        public async Task <ActionResult> Index(string categoryName)
        {
            using (CategoryServiceClient client = new CategoryServiceClient())
            {
                MethodReturnResult <Category> result = await client.GetAsync(categoryName ?? string.Empty);

                if (result.Code > 0 || result.Data == null)
                {
                    return(RedirectToAction("Index", "Category"));
                }
                ViewBag.Category = result.Data;
            }

            using (CategoryDetailServiceClient client = new CategoryDetailServiceClient())
            {
                await Task.Run(() =>
                {
                    PagingConfig cfg = new PagingConfig()
                    {
                        OrderBy = "ItemNo",
                        Where   = string.Format(" Key.CategoryName = '{0}'"
                                                , categoryName)
                    };
                    MethodReturnResult <IList <CategoryDetail> > result = client.Get(ref cfg);

                    if (result.Code == 0)
                    {
                        ViewBag.PagingConfig = cfg;
                        ViewBag.List         = result.Data;
                    }
                });
            }
            return(View(new CategoryDetailQueryViewModel()
            {
                CategoryName = categoryName
            }));
        }
Exemplo n.º 16
0
        public ActionResult GetAllCategory()
        {
            dynamic category = 0;

            try
            {
                if (ModelState.IsValid)
                {
                    CategoryServiceClient categoryServiceClient = new CategoryServiceClient();
                    category = categoryServiceClient.GetAllCategory();
                    //if (category.Count == 0 || category == null)
                    //{
                    //    ModelState.AddModelError("error", "No Record Found");
                    //}
                }
            }
            catch (Exception e)
            {
                ModelState.AddModelError("error", "Something Wrong");
                category = null;
                throw e;
            }
            return(Json(category, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 17
0
        public async Task <ActionResult> SaveModify(CategoryViewModel model)
        {
            using (CategoryServiceClient client = new CategoryServiceClient())
            {
                MethodReturnResult <Category> result = await client.GetAsync(model.Name);

                if (result.Code == 0)
                {
                    result.Data.Status      = model.Status;
                    result.Data.Description = model.Description;
                    result.Data.Editor      = User.Identity.Name;
                    result.Data.EditTime    = DateTime.Now;
                    MethodReturnResult rst = await client.ModifyAsync(result.Data);

                    if (rst.Code == 0)
                    {
                        rst.Message = string.Format(EDCResources.StringResource.Category_SaveModify_Success
                                                    , model.Name);
                    }
                    return(Json(rst));
                }
                return(Json(result));
            }
        }
Exemplo n.º 18
0
        public async Task <ActionResult> Save(CategoryViewModel model)
        {
            using (CategoryServiceClient client = new CategoryServiceClient())
            {
                Category obj = new Category()
                {
                    Key         = model.Name.ToUpper(),
                    Status      = model.Status,
                    Description = model.Description,
                    Editor      = User.Identity.Name,
                    EditTime    = DateTime.Now,
                    CreateTime  = DateTime.Now,
                    Creator     = User.Identity.Name
                };
                MethodReturnResult rst = await client.AddAsync(obj);

                if (rst.Code == 0)
                {
                    rst.Message = string.Format(EDCResources.StringResource.Category_Save_Success
                                                , model.Name);
                }
                return(Json(rst));
            }
        }
Exemplo n.º 19
0
 public CategoryRepository()
 {
     categoryServiceClient = new CategoryServiceClient();
     categoryServiceClient.Open();
 }
Exemplo n.º 20
0
 public ProductsController()
 {
     prod = new ProductServiceClient();
     cate = new CategoryServiceClient();
 }
Exemplo n.º 21
0
 public ShopController()
 {
     categoryProxy = new CategoryServiceClient();
     orderProxy    = new OrderServiceClient();
     customerProxy = new CustomerServiceClient();
 }