예제 #1
0
        public ActionResult Details(int id = 1)
        {
            StyleDTO style = null;

            try
            {
                style = styleService.Get(id);
            }
            catch
            {
                return(RedirectToAction("Error", new { exeption = "The style doesn't exist anymore!" }));
            }
            if (style == null)
            {
                return(NotFound());
            }
            var _style = new StyleViewModel
            {
                Id          = style.Id,
                Name        = style.Name,
                Description = style.Description
            };

            ViewBag.Image   = style.Image;
            ViewBag.IsAdmin = HttpContext.User.IsInRole("Administrator");

            return(View(_style));
        }
        public async Task ThrowExc_If_StyleAlreadyExist()
        {
            var options      = TestUtils.GetOptions(nameof(ThrowExc_If_StyleAlreadyExist));
            var mockDateTime = new Mock <IDateTimeProvider>();

            var style = new Style
            {
                Name = "Pale"
            };

            var styleDTO = new StyleDTO
            {
                Name = "Pale"
            };

            using (var arrangeContext = new BeeroverflowContext(options))
            {
                await arrangeContext.Styles.AddAsync(style);

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new BeeroverflowContext(options))
            {
                var sut = new StyleService(assertContext, mockDateTime.Object);

                await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => sut.CreateStyleAsync(styleDTO));
            }
        }
예제 #3
0
        public void SetRuleStyle(StyleDTO dto, string userId, string entityId)
        {
            validateParameters(userId, entityId);
            switch (this.Scope)
            {
            case RuleEntityScope.Global:
                this.DefaultStyle.SetStyleProperties(dto);
                break;

            default:
                var customStyle = StyleCustomizations.Where(sc => sc.UserId == userId && sc.EntityId == entityId).FirstOrDefault();
                if (customStyle == null)
                {
                    customStyle = new MockStyleCustomization
                    {
                        EntityId = entityId
                        ,
                        UserId = userId
                    };

                    /*
                     * before setting style properties from dto, we need to copy default style first then update
                     * copied object with dto values
                     */
                    customStyle.Style = new MockStyle(this.DefaultStyle);
                    customStyle.Style.SetStyleProperties(dto);
                    StyleCustomizations.Add(customStyle);
                }
                else
                {
                    customStyle.Style.SetStyleProperties(dto);
                }
                break;
            }
        }
예제 #4
0
        public StyleDTO GetStyleDTO()
        {
            var dto = new StyleDTO();

            dto.BackgroundColor = this.BackgroundColor;
            dto.BackgroundImage = this.BackgroundImage;
            dto.Color           = this.Color;

            return(dto);
        }
        public async Task <IActionResult> Put(int id, [FromBody] StyleDTO model)
        {
            if (id == 0 || model == null)
            {
                return(BadRequest());
            }

            var style = await this.styleService.UpdateStyleAsync(model.Id, model.Name);

            return(Ok(style));
        }
 public static StyleViewModel GetViewModel(this StyleDTO dto)
 {
     if (dto == null)
     {
         throw new ArgumentException();
     }
     ;
     return(new StyleViewModel
     {
         Id = dto.Id,
         Name = dto.Name,
         Beers = dto.Beers.GetViewModels()
     });
 }
예제 #7
0
 public void SetStyleProperties(StyleDTO dto)
 {
     if (dto.Color != null)
     {
         this.Color = dto.Color;
     }
     if (dto.BackgroundColor != null)
     {
         this.BackgroundColor = dto.BackgroundColor;
     }
     if (dto.BackgroundImage.HasValue)
     {
         this.BackgroundImage = dto.BackgroundImage;
     }
 }
        public async Task <IActionResult> Post([FromBody] StyleViewModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

            var styleDTO = new StyleDTO
            {
                Id   = model.Id,
                Name = model.Name,
            };

            var newStyle = await this.styleService.CreateStyleAsync(styleDTO);

            return(Created("Post", newStyle));
        }
        public async Task CreateNewStyle_When_ParamsAreValid()
        {
            var options      = TestUtils.GetOptions(nameof(CreateNewStyle_When_ParamsAreValid));
            var mockDateTime = new Mock <IDateTimeProvider>();

            var styleDTO = new StyleDTO
            {
                Id   = 1,
                Name = "Pale"
            };

            using (var assertContext = new BeeroverflowContext(options))
            {
                var sut    = new StyleService(assertContext, mockDateTime.Object);
                var styles = await sut.CreateStyleAsync(styleDTO);

                Assert.AreEqual(1, styles.Id);
                Assert.AreEqual("Pale", styles.Name);
            }
        }
예제 #10
0
        public ActionResult Create(StyleViewModel _style)
        {
            StyleDTO style = new StyleDTO();

            if (ModelState.IsValid)
            {
                if (styleService.GetAll().Where(x => x.Name == _style.Name).Count() > 0)
                {
                    return(RedirectToAction("Error", new { exeption = "The style already exist!" }));
                }
                else
                {
                    style.Name        = _style.Name;
                    style.Description = _style.Description;
                    style.Image       = _style.Image != null?ImageConverter.GetBytes(_style.Image) : null;

                    styleService.Add(style);
                    styleService.Save();
                    return(RedirectToAction(nameof(List)));
                }
            }
            return(View(_style));
        }
예제 #11
0
        public async Task <StyleDTO> CreateStyleAsync(StyleDTO styleDTO)
        {
            var check = await this.context.Styles
                        .FirstOrDefaultAsync(x => x.Name == styleDTO.Name);

            if (check != null)
            {
                throw new ArgumentNullException("Style already existing");
            }

            var style = new Style
            {
                Name      = styleDTO.Name,
                CreatedOn = this.dateTimeProvider.GetDateTime(),
            };

            await this.context.Styles.AddAsync(style);

            await this.context.SaveChangesAsync();

            styleDTO.Id = style.Id;
            return(styleDTO);
        }
예제 #12
0
 public void PutStyle([FromBody] StyleDTO value)
 {
     stylesService.Add(value);
     stylesService.Save();
 }
예제 #13
0
 public void PostStyle([FromBody] StyleDTO value)
 {
     stylesService.Update(value);
 }