Ejemplo n.º 1
0
        public void CreateMagicKinderLaunchingTest()
        {
            /* arrange : 저장할 참여자 정보 */
            var user = CreateMagicKinderLaunchingList()[0];

            mockRepository.Setup(x => x.Add(It.IsAny <MagicKinderAppLaunching>())).Returns(user);
            mockRepository.Setup(x => x.Save());

            /* action : 참여자 정보 저장 서비스 실행 */
            var result = service.CreateMagicKinderAppLaunching(user);

            /* assert : 검증 */
            Assert.NotNull(result);
            mockRepository.Verify(x => x.Add(It.IsAny <MagicKinderAppLaunching>()), Times.Once);
            mockRepository.Verify(x => x.Save(), Times.Once);
        }
Ejemplo n.º 2
0
        public ActionResult CreateMagicKinderAppLaunching(MagicKinderAppLaunchingEventModel model)
        {
            try
            {
                //if (common.Now >= new DateTime(2017, 4, 15))
                //{
                //    throw new Exception("이벤트가 종료되었습니다.");
                //}
                if (!ModelState.IsValid)
                {
                    var errorProp = ModelState.Values.Where(x => x.Errors.Count > 0).FirstOrDefault();
                    if (errorProp != null)
                    {
                        throw new Exception(errorProp.Errors[0].ErrorMessage);
                    }
                }

                var mapper = mapperConfig.CreateMapper();
                var entry  = mapper.Map <MagicKinderAppLaunching>(model);

                entry.IpAddress  = common.ClientIP;
                entry.Channel    = common.IsMobileDevice ? "mobile" : "pc";
                entry.CreateDate = common.Now;
                entry.IsShow     = false;

                var img = Image.FromStream(model.ScreenShotFile.InputStream);
                //이미지 회전 check
                if (img.PropertyIdList.Contains(0x0112))
                {
                    int rotationValue = img.GetPropertyItem(0x0112).Value[0];
                    switch (rotationValue)
                    {
                    case 1:
                        // No rotation required.
                        break;

                    case 2:
                        img.RotateFlip(RotateFlipType.RotateNoneFlipX);
                        break;

                    case 3:
                        img.RotateFlip(RotateFlipType.Rotate180FlipNone);
                        break;

                    case 4:
                        img.RotateFlip(RotateFlipType.Rotate180FlipX);
                        break;

                    case 5:
                        img.RotateFlip(RotateFlipType.Rotate90FlipX);
                        break;

                    case 6:
                        img.RotateFlip(RotateFlipType.Rotate90FlipNone);
                        break;

                    case 7:
                        img.RotateFlip(RotateFlipType.Rotate270FlipX);
                        break;

                    case 8:
                        img.RotateFlip(RotateFlipType.Rotate270FlipNone);
                        break;
                    }
                    // This EXIF data is now invalid and should be removed.
                    img.RemovePropertyItem(0x0112);
                }

                using (MemoryStream ms = new MemoryStream())
                {
                    //회전시킨 이미지를 스트림에 저장
                    img.Save(ms, ImageFormat.Jpeg);

                    //회전시킨 원본이미지 s3에 upload
                    entry.ScreenShot = common.S3FileUpload(ms, "MagicKinderAppLaunching2017", model.ScreenShotFile.FileName.ToString());
                }
                var result = service.CreateMagicKinderAppLaunching(entry);

                return(Json(new
                {
                    result = true,
                    data = result
                }));
            }
            catch (Exception e)
            {
                return(Json(new
                {
                    result = false,
                    message = e.Message
                }));
            }
        }