Esempio n. 1
0
        public SpecialTopicEntity SpecialTopicEntityMapping(SpecialTopicViewModel source)
        {
            if (source == null)
            {
                return(null);
            }

            var target = Mapper.Map <SpecialTopicViewModel, SpecialTopicEntity>(source);

            target.CreatedDate = EntityDateTime(source.CreatedDate);
            target.UpdatedDate = EntityDateTime(source.UpdatedDate);

            return(SpecialTopicEntityCheck(target));
        }
        public ActionResult Create(FormCollection formCollection, SpecialTopicViewModel vo)
        {
            if (ModelState.IsValid)
            {
                var entity = MappingManager.SpecialTopicEntityMapping(vo);
                entity.CreatedUser = base.CurrentUser.CustomerId;
                entity.UpdatedUser = base.CurrentUser.CustomerId;
                entity.Status      = (int)DataStatus.Default;
                entity.CreatedDate = DateTime.Now;
                entity.UpdatedDate = DateTime.Now;
                using (TransactionScope ts = new TransactionScope())
                {
                    entity = this._specialTopicRepository.Insert(entity);
                    var ids = _resourceRepository.Save(ControllerContext.HttpContext.Request.Files
                                                       , CurrentUser.CustomerId
                                                       , -1, entity.Id
                                                       , SourceType.SpecialTopic);
                    ts.Complete();
                }
                return(RedirectToAction("List"));
            }

            return(View(vo));
        }
        public ActionResult Edit(FormCollection formCollection, [FetchSpecialTopic(KeyName = "id")] SpecialTopicEntity entity, SpecialTopicViewModel vo)
        {
            if (entity == null || !ModelState.IsValid)
            {
                ModelState.AddModelError("", "参数验证失败.");
                return(View(vo));
            }

            var newEntity = MappingManager.SpecialTopicEntityMapping(vo);

            newEntity.CreatedUser = entity.CreatedUser;
            newEntity.CreatedDate = entity.CreatedDate;
            newEntity.UpdatedDate = DateTime.Now;
            newEntity.UpdatedUser = base.CurrentUser.CustomerId;

            MappingManager.SpecialTopicEntityMapping(newEntity, entity);
            using (TransactionScope ts = new TransactionScope())
            {
                this._specialTopicRepository.Update(entity);
                if (ControllerContext.HttpContext.Request.Files.Count > 0)
                {
                    foreach (string fileName in ControllerContext.HttpContext.Request.Files)
                    {
                        var file = ControllerContext.HttpContext.Request.Files[fileName];
                        if (file == null || file.ContentLength == 0)
                        {
                            continue;
                        }
                        //remove existing resource
                        var resourceParts = fileName.Split('_');
                        if (resourceParts.Length > 1)
                        {
                            int resourceId = int.Parse(resourceParts[1]);
                            _resourceRepository.Del(resourceId);
                        }
                    }
                    //add new resource
                    _resourceRepository.Save(ControllerContext.HttpContext.Request.Files
                                             , CurrentUser.CustomerId
                                             , -1, entity.Id
                                             , SourceType.SpecialTopic);
                }
                ts.Complete();
            }
            return(RedirectToAction("List"));
        }