コード例 #1
0
        public ActionResult Edit(FormCollection formCollection, [FetchBrand(KeyName = "id")]BrandEntity entity, BrandViewModel vo)
        {
            if (entity == null || !ModelState.IsValid)
            {
                ModelState.AddModelError("", "参数验证失败.");
                return View(vo);
            }

            entity.Name = vo.Name;
            entity.Group = vo.Group;
            entity.WebSite = vo.WebSite??string.Empty;
            entity.Description = vo.Description??string.Empty;
            entity.EnglishName = vo.EnglishName??string.Empty;
            entity.UpdatedDate = DateTime.Now;
            entity.UpdatedUser = CurrentUser.CustomerId;
            using (var ts = new TransactionScope())
            {

                if (ControllerContext.HttpContext.Request.Files.Count > 0)
                {
                    var oldImage = _resourceRepository.Get(r => r.SourceType == (int)SourceType.BrandLogo &&
                         r.SourceId == entity.Id).FirstOrDefault();
                    if (oldImage != null)
                        _resourceService.Del(oldImage.Id);
                    var resources = this._resourceService.Save(ControllerContext.HttpContext.Request.Files
                           , CurrentUser.CustomerId
                         , -1, entity.Id
                         , SourceType.BrandLogo);
                    if (resources != null &&
                        resources.Count() > 0)
                    {
                        entity.Logo = resources[0].AbsoluteUrl;
                    }

                }
                _brandRepository.Update(entity);

                ts.Complete();


            }
            return RedirectToAction("Details", new { id = entity.Id });
           
        }
コード例 #2
0
        public ActionResult Delete(int? id, [FetchBrand(KeyName = "id")]BrandEntity entity)
        {
            if (id == null || entity == null)
            {
                ModelState.AddModelError("", "参数验证失败.");
                return View();
            }

            var vo = new BrandViewModel().FromEntity<BrandViewModel>(entity,
                       b => b.Resource = new ResourceViewModel().FromEntity<ResourceViewModel>(_resourceRepository.Get(r => r.SourceId == b.Id && r.SourceType == (int)SourceType.BrandLogo).FirstOrDefault()));


            return View(vo);
        }
コード例 #3
0
        public ActionResult Create(FormCollection formCollection, BrandViewModel vo)
        {
            if (ModelState.IsValid)
            {
                var entity = MappingManager.BrandEntityMapping(vo);
                entity.CreatedUser = base.CurrentUser.CustomerId;
                entity.UpdatedUser = base.CurrentUser.CustomerId;
                entity.WebSite = vo.WebSite ?? string.Empty;
                entity.Status = (int)DataStatus.Normal;
                entity.CreatedDate = DateTime.Now;
                entity.UpdatedDate = DateTime.Now;
                using (TransactionScope ts = new TransactionScope())
                {

                    entity = this._brandRepository.Insert(entity);
                    if (ControllerContext.HttpContext.Request.Files.Count > 0)
                    {
                        var resources = _resourceService.Save(ControllerContext.HttpContext.Request.Files
                            , CurrentUser.CustomerId
                            , -1, entity.Id
                            , SourceType.BrandLogo);
                        if (resources != null &&
                            resources.Count() > 0)
                        {
                            entity.Logo = resources[0].AbsoluteUrl;
                            _brandRepository.Update(entity);

                        }
                    }
                    ts.Complete();
                    return RedirectToAction("Details", new { id = entity.Id });
                }

            }

            return View(vo);
        }