示例#1
0
        /// <summary>
        /// 检查 entity 为 null的情况
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        private SpecialTopicEntity SpecialTopicEntityCheck(SpecialTopicEntity source)
        {
            source.Description = source.Description ?? String.Empty;
            source.Name        = source.Name ?? String.Empty;
            source.CreatedDate = EntityDateTime(source.CreatedDate);
            source.UpdatedDate = EntityDateTime(source.UpdatedDate);

            return(source);
        }
示例#2
0
        public SpecialTopicViewModel SpecialTopicViewMapping(SpecialTopicEntity source)
        {
            if (source == null)
            {
                return(null);
            }

            var resouces = ResourceViewMapping(GetListResourceEntities(SourceType.SpecialTopic, source.Id)).ToList();

            return(SpecialTopicViewMapping(source, resouces));
        }
        public ActionResult Details(int?id, [FetchSpecialTopic(KeyName = "id")] SpecialTopicEntity entity)
        {
            if (id == null || entity == null)
            {
                ModelState.AddModelError("", "参数验证失败.");
                return(View());
            }

            var vo = MappingManager.SpecialTopicViewMapping(entity);

            return(View(vo));
        }
示例#4
0
        private SpecialTopicViewModel SpecialTopicViewMapping(SpecialTopicEntity source,
                                                              List <ResourceViewModel> resourceViewModels)
        {
            if (source == null)
            {
                return(null);
            }

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

            target.Resources = resourceViewModels;

            return(target);
        }
        public JsonResult Delete([FetchSpecialTopic(KeyName = "id")] SpecialTopicEntity entity)
        {
            try
            {
                entity.UpdatedDate = DateTime.Now;
                entity.UpdatedUser = CurrentUser.CustomerId;
                entity.Status      = (int)DataStatus.Deleted;

                this._specialTopicRepository.Update(entity);
                return(SuccessResponse());
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                return(FailResponse());
            }
        }
        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"));
        }
示例#7
0
        public SpecialTopicEntity SpecialTopicEntityMapping(SpecialTopicEntity source, SpecialTopicEntity target)
        {
            var result = Mapper.Map(source, target);

            return(SpecialTopicEntityCheck(result));
        }