Пример #1
0
        public void EditFeedback(FeedbackDetailsViewModel feedbackDetailsViewModel)
        {
            Feedback feedback = _feedbackRepository.GetById(feedbackDetailsViewModel.Id);

            if (feedback == null)
            {
                throw new Exception($"The feedback with id {feedbackDetailsViewModel.Id} was not found!");
            }

            Feedback editedFeedback = feedbackDetailsViewModel.ToFeedback();

            _feedbackRepository.Update(editedFeedback);
        }
Пример #2
0
        public void CreateFeedback(FeedbackDetailsViewModel feedbackDetailsViewModel)
        {
            Feedback feedback = feedbackDetailsViewModel.ToFeedback();


            int numOfChars = feedback.Message.ToCharArray().Count();

            if (numOfChars > 100)
            {
                throw new Exception();
            }

            char [] emailValidation = feedback.Email.ToCharArray();
            if (!emailValidation.Contains('@'))
            {
                throw new Exception();
            }
            if (!emailValidation.Contains('.'))
            {
                throw new Exception();
            }
            if (emailValidation.Length < 3)
            {
                throw new Exception();
            }

            // Prefrleno vo repo taka mi imase poveke logika.

            //List<Feedback> feedbacks = _feedbackRepository.GetAll();
            //var numOfEmails = feedbacks.Where(x => x.Email == feedbackDetailsViewModel.Email).ToList().Count();

            //if(numOfEmails > 2)
            //{
            //    throw new Exception();
            //}

            if (_feedbackRepository.GetNumOfEmails(feedback) > 2)
            {
                throw new Exception();
            }

            int newFeedbackId = _feedbackRepository.Insert(feedback);

            if (newFeedbackId <= 0)
            {
                throw new Exception("Something went wrong while saving the feedback");
            }
        }