Exemple #1
0
        private void CriticizeInternal()
        {
            // Read file and create rule context
            var sourceCodePath = SettingsBuilder.RulePath;
            var sourceCode     = TryReadSourceCode(sourceCodePath);

            if (sourceCode != null)
            {
                var ruleContext = new RuleContext(sourceCode);

                // Evaluate the code with skeptic
                Critic critic = TryCreateCritic(ruleContext);
                if (critic != null)
                {
                    critic.Criticize();

                    // Output the result
                    var skepticWriter = new SkepticWriter(critic, System.Console.Out);
                    skepticWriter.Write();
                }
            }
            else // The file was not found
            {
                "Cannot load file to evaluate".ConsoleWriteLine();
            }
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,FullName,MovieName,Rating")] Critic critic)
        {
            if (id != critic.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(critic);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CriticExists(critic.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(critic));
        }
Exemple #3
0
 /// <summary>
 /// Build the object Critic and add to inputErrors list
 /// to send the object InvalidInputException to LightController
 /// </summary>
 /// <param name="inputErrors"></param>
 public BusinessValidationException(List <string> inputErrors) : base()
 {
     InputErrors.Clear();
     foreach (string errorCode in inputErrors)
     {
         Critic critic = new Critic();
         critic.AddError(errorCode);
         InputErrors.Add(critic);
     }
 }
        public IHttpActionResult GetCritic(int id)
        {
            Critic critic = _dALCritic.GetCriticById(id);

            if (critic == null)
            {
                return(NotFound());
            }
            return(Ok(critic));
        }
Exemple #5
0
        public UpdateCriticViewModel(UpdateCritic window, Critic critic)
        {
            _criticWindow  = window;
            _currentCritic = critic;

            for (int i = 0; i < 5; i++)
            {
                scores[i] = i + 1;
            }
            selectedScore = _currentCritic.ReliabilityScore;
        }
        public async Task <IActionResult> Create([Bind("Id,FullName,MovieName,Rating")] Critic critic)
        {
            if (ModelState.IsValid)
            {
                _context.Add(critic);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(critic));
        }
        public IHttpActionResult PostCritic(Critic critic)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _dALCritic.AddCritic(critic);

            return(CreatedAtRoute("DefaultApi", new { id = critic.Id }, critic));
        }
Exemple #8
0
        private Critic TryCreateCritic(RuleContext ruleContext)
        {
            Critic critic = null;

            try
            {
                critic = new Critic(ruleContext, SettingsBuilder.Settings);
            }
            catch (FileNotFoundException ex)
            {
                "Cannot load rules file - {0}".ConsoleWriteLine(ex.FileName);
            }
            return(critic);
        }
Exemple #9
0
        public async Task <Unit> Handle(AddMovieCriticCommand request, CancellationToken cancellationToken)
        {
            var    userId = _context.HttpContext.User.FindFirst(ClaimTypes.Name).Value;
            Critic critic = new Critic
            {
                UserId  = Convert.ToInt32(userId),
                MovieId = request.MovieId,
                Rating  = request.Rating,
                Comment = request.Comment
            };

            await _criticRepository.AddAsync(critic);

            return(Unit.Value);
        }
        public IHttpActionResult PutCritic(int id, Critic critic)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != critic.Id)
            {
                return(BadRequest());
            }

            _dALCritic.UpdateCritic(critic);

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IActionResult CreateCritic([FromBody] Critic createCritic) //FromBody indicates the object is coming from body/form
        {
            if (createCritic == null)
            {
                return(BadRequest(ModelState));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (!criticRepository.CreateCritic(createCritic))
            {
                ModelState.AddModelError("", "Something Went wrong, Please try again");
                return(StatusCode(500, ModelState));
            }
            return(CreatedAtRoute("GetCritic", new { criticId = createCritic.Id }, createCritic));
        }
            public async Task CreateAsync_CriticValidationSucceed_CreatesScreening()
            {
                // Arrange
                var podcast          = new CriticUpdateModel();
                var expected         = new Critic();
                var ratingGetService = new Mock <IRatingGetService>();

                ratingGetService.Setup(x => x.ValidateAsync(podcast));
                var podcastDataAccess = new Mock <ICriticDataAccess>();

                podcastDataAccess.Setup(x => x.InsertAsync(podcast)).ReturnsAsync(expected);
                var podcastGetService = new CriticCreateService(podcastDataAccess.Object, ratingGetService.Object);
                // Act
                var result = await podcastGetService.CreateAsync(podcast);

                // Assert
                result.Should().Be(expected);
            }
Exemple #13
0
 public UpdateRatingCommand(
     int stars,
     IUnitOfWork unitOfWork,
     RatingOutput output,
     Rating rating,
     Critic ratingAuthor,
     Critics criticsHavingRated,
     Movies allMovies,
     Movie ratedMovie)
 {
     _stars              = stars;
     _unitOfWork         = unitOfWork;
     _output             = output;
     _rating             = rating;
     _ratingAuthor       = ratingAuthor;
     _criticsHavingRated = criticsHavingRated;
     _allMovies          = allMovies;
     _ratedMovie         = ratedMovie;
 }
        public IActionResult UpdateCritic(int criticId, [FromBody] Critic updateCritic)
        {
            if (updateCritic == null || criticId != updateCritic.Id || !ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!criticRepository.CriticExists(criticId))
            {
                return(NotFound());
            }

            if (!criticRepository.UpdateCritic(updateCritic))
            {
                ModelState.AddModelError("", "Something went wrong, please try again");
                return(StatusCode(500, ModelState));
            }
            return(NoContent());
        }
        public IHttpActionResult DeleteCritic(int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Critic critic = _dALCritic.GetCriticById(id);

            if (id != critic.Id)
            {
                return(BadRequest());
            }

            critic.Deleted = true;
            _dALCritic.DeleteCritic(critic.Id);

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #16
0
 public void UpdateCritic(Critic critic)
 {
     if (critic.Id != 0)
     {
         using (IMDBEntities7 dbContext = new IMDBEntities7())
         {
             var fest = dbContext.Critics.Where(b => b.Id == critic.Id).FirstOrDefault();
             if (fest != null)
             {
                 fest.Name                   = critic.Name;
                 fest.Surname                = critic.Surname;
                 fest.Deleted                = critic.Deleted;
                 fest.ReliabilityScore       = critic.ReliabilityScore;
                 dbContext.Entry(fest).State = EntityState.Modified;
                 dbContext.SaveChanges();
             }
         }
     }
 }
Exemple #17
0
 public void AddCritic(Critic critic)
 {
     if (critic.Id == 0)
     {
         using (IMDBEntities7 dbContext = new IMDBEntities7())
         {
             var fest = dbContext.Actors.Where(b => b.Id == critic.Id && b.Deleted == false).FirstOrDefault();
             if (fest == null)
             {
                 Critic newCritic = new Critic
                 {
                     Name             = critic.Name,
                     Surname          = critic.Surname,
                     ReliabilityScore = critic.ReliabilityScore,
                     Deleted          = false
                 };
                 dbContext.Critics.Add(newCritic);
                 dbContext.SaveChanges();
             }
         }
     }
 }
Exemple #18
0
 private void AddCriticExecute()
 {
     try
     {
         if (!string.IsNullOrEmpty(Critic.Name) || !string.IsNullOrEmpty(Critic.Surname))
         {
             Critic newCritic = new Critic
             {
                 Name             = Critic.Name,
                 Surname          = Critic.Surname,
                 ReliabilityScore = SelectedScore,
                 Deleted          = false
             };
             _dALCritic.AddCritic(newCritic);
             critic_window.Close();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Exemple #19
0
 public bool CreateCritic(Critic critic)
 {
     _criticContext.AddAsync(critic);
     return(Save());
 }
Exemple #20
0
 public UpdateCritic(Critic critic)
 {
     InitializeComponent();
     DataContext = new UpdateCriticViewModel(this, critic);
 }
Exemple #21
0
 public bool DeleteCritic(Critic critic)
 {
     _criticContext.Remove(critic);
     return(Save());
 }
Exemple #22
0
 public SkepticWriter(Critic critic, TextWriter writer)
 {
     Critic = critic;
     Writer = writer;
 }
Exemple #23
0
 public bool UpdateCritic(Critic critic)
 {
     _criticContext.Update(critic);
     return(Save());
 }