Exemple #1
0
        public AdviceBase UpdateAdvice(AdviceBase updatedAdvice)
        {
            if (updatedAdvice.Id == null)
            {
                throw new ArgumentException("AdviceId cannot be null when updating");
            }

            var adviceToUpdate = _adviceRepository.FindAdvice(updatedAdvice.Id.Value);

            if (adviceToUpdate == null)
            {
                throw new NullReferenceException(string.Format("Could not find advice with id {0}.", updatedAdvice.Id));
            }

            SetSemaphore(updatedAdvice.SemaphoreId, adviceToUpdate);
            adviceToUpdate.CopyStringProperties(updatedAdvice);
            SetTag(updatedAdvice.TagId, adviceToUpdate);
            adviceToUpdate.KeyWords  = updatedAdvice.KeyWords ?? "";
            adviceToUpdate.Published = updatedAdvice.Published;

            _adviceRepository.MergePersist();
            Log.Debug("Advice updated. {0} ", adviceToUpdate.ToString());

            return(adviceToUpdate);
        }
Exemple #2
0
        private void SetTag(int?tagId, AdviceBase adviceToAdd)
        {
            if (!tagId.HasValue)
            {
                adviceToAdd.Tag = null;
                return;
            }

            adviceToAdd.Tag = _productRepository.FindTag(tagId.Value);
        }
Exemple #3
0
        private void SetMentor(int mentorId, AdviceBase adviceToAdd)
        {
            var mentor = _adviceRepository.FindMentor(mentorId);

            if (mentor == null)
            {
                string exceptionMessage = "No Mentor founded when trying to add Advice";
                Log.Error(exceptionMessage);
                throw new NullReferenceException(exceptionMessage);
            }

            adviceToAdd.Mentor = mentor;
        }
Exemple #4
0
        private void SetTag(int?tagId, AdviceBase adviceToAdd)
        {
            if (tagId == null)
            {
                adviceToAdd.Tag = null;
                return;
            }

            using (var adviceTagRepository = _repositoryFactory.Build <IRepository <AdviceTag>, AdviceTag>())
            {
                var tag = adviceTagRepository.FindOne(x => x.Id == tagId);
                tag             = _adviceRepository.FindDomainObject(tag);
                adviceToAdd.Tag = tag;
            }
        }
Exemple #5
0
        private void SetSemaphore(int?semaphoreId, AdviceBase adviceToAdd)
        {
            if (!semaphoreId.HasValue)
            {
                throw new ArgumentException("Semaphore not set");
            }

            var semaphore = _adviceRepository.FindSemaphore(semaphoreId.Value);

            if (semaphore == null)
            {
                string exceptonMessage = "No Semaphore found when trying to add Advice";
                Log.Error(exceptonMessage);
                throw new NullReferenceException(exceptonMessage);
            }
            adviceToAdd.Semaphore = semaphore;
        }
 protected void ValidateAdvice(AdviceBase advice)
 {
     if (String.IsNullOrEmpty(advice.Label))
     {
         ModelState.AddModelError("Label", "Label is required!");
     }
     if (String.IsNullOrEmpty(advice.Introduction))
     {
         ModelState.AddModelError("Introduction", "Introduction is required!");
     }
     if (String.IsNullOrEmpty(advice.Advice))
     {
         ModelState.AddModelError("Advice", "Advice text is required!");
     }
     if (String.IsNullOrEmpty(advice.KeyWords))
     {
         advice.KeyWords = "";
     }
     if (advice.SemaphoreId == null)
     {
         ModelState.AddModelError("Semaphore", "Please choose a signal for your advice");
     }
 }
Exemple #7
0
 protected override void SetClonedData(AdviceBase clone)
 {
     ((ProductAdvice) clone).ProductsId = ProductsId;
     base.SetClonedData(clone);
 }
        private void SetTag(int? tagId, AdviceBase adviceToAdd)
        {
            if (!tagId.HasValue)
            {
                adviceToAdd.Tag = null;
                return;
            }

            adviceToAdd.Tag = _productRepository.FindTag(tagId.Value);
        }
 public void AddAdviceRequest(User user, AdviceBase advice, string userAgent, string imei, string model, string osVersion)
 {
     throw new NotImplementedException();
 }
 protected override void SetClonedData(AdviceBase clone)
 {
     ((IngredientAdvice)clone).IngredientsId = IngredientsId;
     base.SetClonedData(clone);
 }
 public void AddAdviceRequest(User user, AdviceBase advice, string userAgent, string imei, string model, string osVersion)
 {
     throw new NotImplementedException();
 }
Exemple #12
0
 public ConceptAdvice AddConceptAdvice(Mentor mentor, Concept concept, AdviceBase advice, bool publish)
 {
     return(AddConceptAdvice(mentor.Id, concept.Id, advice.SemaphoreId.Value, advice.Label,
                             advice.Introduction, advice.Advice, advice.KeyWords, publish));
 }
Exemple #13
0
 public BrandAdvice AddBrandAdvice(Mentor mentor, Brand brand, AdviceBase advice, bool publish)
 {
     return(AddBrandAdvice(mentor.Id, brand.Id, advice.SemaphoreId.Value, advice.Label,
                           advice.Introduction, advice.Advice, advice.KeyWords, publish));
 }
Exemple #14
0
 protected override void SetClonedData(AdviceBase clone)
 {
     ((BrandAdvice)clone).BrandsId = BrandsId;
     base.SetClonedData(clone);
 }