Exemplo n.º 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);
        }
Exemplo n.º 2
0
        private void SetTag(int?tagId, AdviceBase adviceToAdd)
        {
            if (!tagId.HasValue)
            {
                adviceToAdd.Tag = null;
                return;
            }

            adviceToAdd.Tag = _productRepository.FindTag(tagId.Value);
        }
Exemplo n.º 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;
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 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;
        }
Exemplo n.º 6
0
 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");
     }
 }
Exemplo n.º 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);
        }
Exemplo n.º 9
0
 public void AddAdviceRequest(User user, AdviceBase advice, string userAgent, string imei, string model, string osVersion)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 10
0
 protected override void SetClonedData(AdviceBase clone)
 {
     ((IngredientAdvice)clone).IngredientsId = IngredientsId;
     base.SetClonedData(clone);
 }
Exemplo n.º 11
0
 public void AddAdviceRequest(User user, AdviceBase advice, string userAgent, string imei, string model, string osVersion)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 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));
 }
Exemplo n.º 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));
 }
Exemplo n.º 14
0
 protected override void SetClonedData(AdviceBase clone)
 {
     ((BrandAdvice)clone).BrandsId = BrandsId;
     base.SetClonedData(clone);
 }