Beispiel #1
0
        public ActionResult Update(Product product)
        {
            ProductEx productEx = new ProductEx();

            productEx.Update(product);
            return(RedirectToAction("Index"));
        }
Beispiel #2
0
        public ApiMessage <string> Edit(ProductEx t)
        {
            using (var scope = new PetaPoco.Transaction(_db))
            {
                try
                {
                    if (string.IsNullOrEmpty(t.ID))
                    {
                        t.ID   = Guid.NewGuid().ToString();
                        t.Code = CodeNo.Get(CodeType.Product);
                        t.Insert();

                        for (int i = 0; i < t.Imgs.Count; i++)
                        {
                            var item = t.Imgs[i];
                            var img  = new productimg
                            {
                                ID        = Guid.NewGuid().ToString(),
                                ProductID = t.ID,
                                RowNO     = i,
                                Url       = item.url
                            };
                            img.Insert();
                        }
                    }
                    else
                    {
                        t.Update();
                        productimg.Delete("where ProductId=@0", t.ID);
                        for (int i = 0; i < t.Imgs.Count; i++)
                        {
                            var item = t.Imgs[i];
                            var img  = new productimg
                            {
                                ID        = Guid.NewGuid().ToString(),
                                ProductID = t.ID,
                                RowNO     = i,
                                Url       = item.url
                            };
                            img.Insert();
                        }
                    }
                    scope.Complete();
                    return(new ApiMessage <string>());
                }
                catch (Exception e)
                {
                    scope.Dispose();
                    throw e;
                }
            }
        }