コード例 #1
0
        public ActionResult Create(FormCollection formCollection, ProductViewModel vo)
        {
            if (ModelState.IsValid)
            {
                var entity = MappingManager.ProductViewMapping(vo);
                entity.CreatedUser         = CurrentUser.CustomerId;
                entity.UpdatedUser         = CurrentUser.CustomerId;
                entity.CreatedDate         = DateTime.Now;
                entity.RecommendedReason   = entity.RecommendedReason ?? string.Empty;
                entity.RecommendUser       = CurrentUser.CustomerId;
                entity.RecommendSourceId   = entity.RecommendUser;
                entity.RecommendSourceType = (int)RecommendSourceType.Default;
                entity.UpdatedDate         = DateTime.Now;
                entity.Status = (int)DataStatus.Default;
                using (var ts = new TransactionScope())
                {
                    entity = _productRepository.Insert(entity);
                    SaveT(entity.Id, StringsToInts(vo.TopicIds, ","));
                    SaveP(entity.Id, StringsToInts(vo.PromotionIds, ","));
                    _resourceService.Save(ControllerContext.HttpContext.Request.Files
                                          , CurrentUser.CustomerId
                                          , -1, entity.Id
                                          , SourceType.Product);
                    ts.Complete();
                }

                return(RedirectToAction("Edit", new { id = @entity.Id }));
            }

            return(View(vo));
        }
コード例 #2
0
        public ActionResult Edit(int?id, [FetchProduct(KeyName = "id")] ProductEntity entity)
        {
            if (id == null || entity == null)
            {
                ModelState.AddModelError("", "参数验证失败.");
                return(View());
            }

            var vo = MappingManager.ProductViewMapping(entity);

            return(View(vo));
        }