Exemple #1
0
        public async Task <IActionResult> Edit(BEProductViewModel product, string id, int?categoryId = null)
        {
            if (id != product.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var result = await product.SaveModelAsync(true).ConfigureAwait(false);

                    if (result.IsSucceed)
                    {
                        if (categoryId.HasValue)
                        {
                            return(RedirectToAction("Contents", "Pages", new { id = categoryId }));
                        }
                        else
                        {
                            return(RedirectToAction("Index"));
                        }
                    }
                    else
                    {
                        if (result.Exception != null)
                        {
                            ModelState.AddModelError(string.Empty, result.Exception?.Message);
                        }

                        foreach (var error in result.Errors)
                        {
                            ModelState.AddModelError(string.Empty, error);
                        }
                        return(View(product));
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BEProductViewModel.Repository.CheckIsExists(m => m.Id == product.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                //return RedirectToAction("Index");
            }
            return(View(product));
        }
        public async Task <RepositoryResponse <BEProductViewModel> > Post([FromBody] BEProductViewModel model)
        {
            if (model != null)
            {
                var result = await model.SaveModelAsync(true).ConfigureAwait(false);

                if (result.IsSucceed)
                {
                    result.Data.Domain = this._domain;
                }
                return(result);
            }
            return(new RepositoryResponse <BEProductViewModel>());
        }
Exemple #3
0
        public async Task <RepositoryResponse <BEProductViewModel> > Save([FromBody] BEProductViewModel product)
        {
            if (product != null)
            {
                var result = await product.SaveModelAsync(true).ConfigureAwait(false);

                if (result.IsSucceed)
                {
                    result.Data.DetailsUrl = SwCmsHelper.GetRouterUrl("Product", new { seoName = product.SeoName }, Request, Url);
                }
                return(result);
            }
            return(new RepositoryResponse <BEProductViewModel>());
        }
 public IActionResult Create(int? categoryId = null)
 {
     var vmProduct = new BEProductViewModel(new SiocProduct()
     {
         Id = Guid.NewGuid().ToString(),
         Specificulture = _lang,
         CreatedBy = User.Identity.Name,
         CreatedDateTime = DateTime.UtcNow
     })
     {
         Status = SWStatus.Preview
     };
     if (categoryId.HasValue)
     {
         var activeCate = vmProduct.Categories.Find(c => c.CategoryId == categoryId);
         if (activeCate != null)
         {
             activeCate.IsActived = true;
         }
     }
     ViewBag.categoryId = categoryId;
     return View(vmProduct);
 }