Пример #1
0
 public static void CleanUpProducts(ServiceClientMessageHandler handler, List <string> productCodes)
 {
     foreach (var code in productCodes)
     {
         //should return NoContent, bypass for now
         try
         {
             ProductFactory.DeleteProduct(handler, code);
         }
         catch (TestFailException e)
         {
             // ToDo: e.ActualReturnCode
         }
     }
 }
Пример #2
0
        public ActionResult Delete(ProductModels model)
        {
            try
            {
                List <string> lstImgs = new List <string>();
                lstImgs = _factory.GetListImageProduct(model.ID);

                //-----------------------
                string msg    = "";
                var    result = _factory.DeleteProduct(model.ID, ref msg);
                if (result)
                {
                    if (lstImgs != null && lstImgs.Any())
                    {
                        //Delete image on forder
                        foreach (var item in lstImgs)
                        {
                            if (!item.Equals(Commons.Image200_100))
                            {
                                var filePath = Server.MapPath("~/Uploads/Images/Product/" + item);
                                if (System.IO.File.Exists(filePath))
                                {
                                    System.IO.File.Delete(filePath);
                                }
                            }
                        }
                    }
                }
                else
                {
                    ModelState.AddModelError("Name", msg);
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(PartialView("_Delete", model));
                }
                return(new HttpStatusCodeResult(HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                NSLog.Logger.Error("Land_Delete: ", ex);
                ModelState.AddModelError("Name", "Sản phẩm này hiện đang sử dụng. Làm ơn kiểm tra lại!");
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(PartialView("_Delete", model));
            }
        }
Пример #3
0
 public ActionResult Delete(ProductModels model)
 {
     try
     {
         string msg    = "";
         var    result = _factory.DeleteProduct(model.ID, ref msg);
         if (!result)
         {
             //ModelState.AddModelError("Name", "Have an error when you delete a Set menu");
             ModelState.AddModelError("Name", msg);
             Response.StatusCode = (int)HttpStatusCode.BadRequest;
             return(PartialView("_Delete", model));
         }
         return(new HttpStatusCodeResult(HttpStatusCode.OK));
     }
     catch (Exception ex)
     {
         _logger.Error("Product_Modifier_Delete: " + ex);
         ModelState.AddModelError("Name", CurrentUser.GetLanguageTextFromKey("Have an error when you delete a modifier"));
         Response.StatusCode = (int)HttpStatusCode.BadRequest;
         return(PartialView("_Delete", model));
     }
 }
Пример #4
0
        /// <summary>
        /// clean up products, attributes, productypes and categories since provisioning the tenant
        /// </summary>
        /// <param name="tenantId"></param>
        /// <param name="masterCatalogId"></param>
        /// <param name="siteId"></param>
        public static void CleanUpProducts(int tenantId, int masterCatalogId, int?catalogId = null, int?siteId = null)
        {
            var tenant            = TenantFactory.GetTenant(ServiceClientMessageFactory.GetTestClientMessage(), tenantId);
            var ApiMessageHandler = ServiceClientMessageFactory.GetTestClientMessage(tenantId: tenantId, masterCatalogId: masterCatalogId, catalogId: catalogId, siteId: siteId);
            var products          = ProductFactory.GetProducts(ApiMessageHandler, noCount: null, pageSize: null, q: null, qLimit: null, sortBy: null, startIndex: null, filter: "createdate gt " + SinceWhen(DateTime.Now.AddDays(-1)));

            foreach (var pro in products.Items)
            {
                ProductFactory.DeleteProduct(ApiMessageHandler, pro.ProductCode);
            }
            var productTypes = ProductTypeFactory.GetProductTypes(handler: ApiMessageHandler, successCode: HttpStatusCode.OK, expectedCode: HttpStatusCode.OK);

            foreach (var pt in productTypes.Items)
            {
                if (pt.AuditInfo.CreateDate.Value > DateTime.Now.AddDays(-1))
                {
                    try
                    {
                        ProductTypeFactory.DeleteProductType(ApiMessageHandler, pt.Id.Value);
                    }
                    catch (TestFailException e)   //getaround base product type
                    {
                        // ToDo: e.ActualReturnCode
                    }
                }
            }
            var attributes = AttributeFactory.GetAttributes(handler: ApiMessageHandler, successCode: HttpStatusCode.OK, expectedCode: HttpStatusCode.OK);

            if (attributes.TotalCount != 0)
            {
                foreach (var attr in attributes.Items)
                {
                    if (attr.AuditInfo.CreateDate.Value > DateTime.Now.AddDays(-1))
                    {
                        //bug 18745, should return NoContent
                        try
                        {
                            AttributeFactory.DeleteAttribute(ApiMessageHandler, attr.AttributeFQN);
                        }
                        catch (TestFailException e)  //get around the bug
                        {
                            // ToDo: e.ActualReturnCode
                        }
                    }
                }
            }
            var cates = CategoryFactory.GetCategories(ApiMessageHandler, pageSize: null, sortBy: null, startIndex: null, filter: "createdate gt " + SinceWhen(DateTime.Now.AddDays(-1)));

            foreach (var cate in cates.Items)
            {
                var messageHandler1 = ServiceClientMessageFactory.GetTestClientMessage(tenantId: tenantId, masterCatalogId: masterCatalogId, catalogId: catalogId, siteId: siteId);
                try
                {
                    CategoryFactory.DeleteCategoryById(handler: messageHandler1, categoryId: (int)cate.Id, cascadeDelete: true);
                }
                catch (TestFailException e)   //work around notfound
                {
                    // ToDo: e.ActualReturnCode
                }
            }
        }