Esempio n. 1
0
        public void UpdateRecommend(RecommendDto model, string operatedBy)
        {
            var entity = _recommendRepository.Get(model.Id);

            if (entity == null)
            {
                throw new AppServiceException("No recommend found.");
            }

            entity.Description = string.IsNullOrEmpty(model.Description) ? entity.Description : model.Description;
            entity.GetUrl      = string.IsNullOrEmpty(model.GetUrl) ? entity.GetUrl : model.GetUrl;
            entity.Price       = model.Price == null ? entity.Price : model.Price;
            entity.Title       = string.IsNullOrEmpty(model.Title) ? entity.Title : model.Title;

            var medias = _recommendMediaRepository.GetFiltered(o => o.RecommendId == entity.Id).ToList();
            var specs  = _recommendSpecRepository.GetFiltered(o => o.RecommendId == entity.Id).ToList();

            if (medias != null && medias.Any())
            {
                foreach (var item in medias)
                {
                    _recommendMediaRepository.Remove(item);
                }
            }
            if (specs != null && specs.Any())
            {
                foreach (var item in specs)
                {
                    _recommendSpecRepository.Remove(item);
                }
            }
            if (model.Medias != null && model.Medias.Any())
            {
                foreach (var item in model.Medias)
                {
                    var media = RecommendMediaFactory.CreateInstance(item.Title, model.Id, item.Url, item.MediaType, operatedBy);
                    _recommendMediaRepository.Add(media);
                }
            }
            if (model.Specs != null && model.Specs.Any())
            {
                foreach (var item in model.Specs)
                {
                    var spec = RecommendSpecFactory.CreateInstance(item.Name, item.Value, model.Id, operatedBy);
                    _recommendSpecRepository.Add(spec);
                }
            }
            _dbUnitOfWork.Commit();
        }
Esempio n. 2
0
        public void AddRecommend(RecommendDto model, string operatedBy)
        {
            var recommend = RecommendFactory.CreateInstance(model.Title, model.GetUrl, model.Price, model.Description, model.QuestionId, operatedBy);

            _recommendRepository.Add(recommend);
            if (model.Medias != null && model.Medias.Any())
            {
                foreach (var item in model.Medias)
                {
                    var media = RecommendMediaFactory.CreateInstance(item.Title, recommend.Id, item.Url, item.MediaType, operatedBy);
                    _recommendMediaRepository.Add(media);
                }
            }
            if (model.Specs != null && model.Specs.Any())
            {
                foreach (var item in model.Specs)
                {
                    var spec = RecommendSpecFactory.CreateInstance(item.Name, item.Value, recommend.Id, operatedBy);
                    _recommendSpecRepository.Add(spec);
                }
            }
            _dbUnitOfWork.Commit();
        }