Exemple #1
0
        /// <summary>
        /// Create page translation
        /// </summary>
        /// <param name="contentTranslation"></param>
        /// <returns></returns>
        public PageContentTranslation CreateTranslation(PageContentTranslation contentTranslation)
        {
            using var context = new DeviserDbContext(_dbOptions);
            var dbPageContentTranslation = _mapper.Map <Entities.PageContentTranslation>(contentTranslation);

            dbPageContentTranslation.CreatedDate = dbPageContentTranslation.LastModifiedDate = DateTime.Now;
            var result = context.PageContentTranslation.Add(dbPageContentTranslation).Entity;

            context.SaveChanges();
            return(_mapper.Map <PageContentTranslation>(result));
        }
Exemple #2
0
        public PageContentTranslation UpdateTranslation(PageContentTranslation pageContentTranslation)
        {
            using var context = new DeviserDbContext(_dbOptions);
            var dbPageContentTranslation = _mapper.Map <Entities.PageContentTranslation>(pageContentTranslation);

            if (!context.PageContentTranslation.Any(t => t.Id == dbPageContentTranslation.Id))
            {
                throw new InvalidOperationException($"Parameter {nameof(pageContentTranslation)} is not found");
            }

            dbPageContentTranslation.LastModifiedDate = DateTime.Now;
            var result = context.PageContentTranslation.Update(dbPageContentTranslation).Entity;

            context.SaveChanges();
            return(_mapper.Map <PageContentTranslation>(result));
        }
Exemple #3
0
 public IActionResult Put([FromBody] PageContentTranslation contentTranslation)
 {
     try
     {
         var result = _pageContentRepository.UpdateTranslation(contentTranslation);
         if (result != null)
         {
             return(Ok(result));
         }
         return(BadRequest());
     }
     catch (Exception ex)
     {
         _logger.LogError(string.Format("Error occured while creating/updating a page content translation"), ex);
         return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
     }
 }
Exemple #4
0
        public void CreateTranslationFail()
        {
            //Arrange
            var pageContentRepository = new PageContentRepository(_container);
            var dbContext             = _serviceProvider.GetRequiredService <DeviserDbContext>();
            var pageContents          = TestDataRepository.GetPageContents();
            PageContentTranslation pageContentTranslation = null;


            //Act
            var result = pageContentRepository.CreateTranslation(pageContentTranslation);

            //Assert
            Assert.Null(result);

            //Clean
            dbContext.PageContentTranslation.RemoveRange(dbContext.PageContentTranslation);
        }
 /// <summary>
 /// Create page translation
 /// </summary>
 /// <param name="contentTranslation"></param>
 /// <returns></returns>
 public PageContentTranslation CreateTranslation(PageContentTranslation contentTranslation)
 {
     try
     {
         using (var context = new DeviserDbContext(DbOptions))
         {
             var dbPageContentTranslation = Mapper.Map <Entities.PageContentTranslation>(contentTranslation);
             dbPageContentTranslation.CreatedDate = dbPageContentTranslation.LastModifiedDate = DateTime.Now;
             var result = context.PageContentTranslation.Add(dbPageContentTranslation).Entity;
             context.SaveChanges();
             return(Mapper.Map <PageContentTranslation>(result));
         }
     }
     catch (Exception ex)
     {
         _logger.LogError("Error occured while Creating/Updating page content translation", ex);
     }
     return(null);
 }