예제 #1
0
        public async Task <IHttpActionResult> AddNewPhoto(Photo ph)
        {
            var pathName = "PenjualanPhotoGalery";

            ph.Path = pathName;
            var path = HttpContext.Current.Server.MapPath(string.Format("~/{0}/", pathName));

            //if (!Request.Content.IsMimeMultipartContent())
            //    throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotAcceptable,
            //    "This request is not properly formatted"));
            //var streamProvider = new MultipartFileStreamProvider(path);
            //var res= await Request.Content.ReadAsMultipartAsync(streamProvider);
            try
            {
                if (ph != null)
                {
                    var context = new PhotoContext(path);
                    return(Ok(await context.AddNewPhoto(ph, pathName)));
                }
                else
                {
                    throw new SystemException("Tidak ada gambar yang dikirim");
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
 public IdentityUnitOfWork(string connectionString)
 {
     db            = new PhotoContext(connectionString);
     userManager   = new ApplicationUserManager(new UserStore <ApplicationUser>(db));
     roleManager   = new ApplicationRoleManager(new RoleStore <ApplicationRole>(db));
     clientManager = new ClientManager(db);
 }
예제 #3
0
 private static string CreateTargetPath(PhotoContext photoContext, DateTime dateTime)
 {
     return(Path.Combine(
                photoContext.Context.TargetRoot.FullName,
                dateTime.Year.ToString(),
                dateTime.Month.ToString().PadLeft(2, '0')));
 }
예제 #4
0
        public ActionResult Crear(Photo p)
        {
            PhotoContext c = new PhotoContext();

            c.Photos.Add(p);
            c.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #5
0
        public void Configure(IApplicationBuilder app, PhotoContext photoContext, IHostingEnvironment environment)
        {
            photoContext.Database.EnsureDeleted();
            photoContext.Database.EnsureCreated();

            app.UseStaticFiles();

            app.UseNodeModules(environment.ContentRootPath);

            app.UseMvcWithDefaultRoute();
        }
        public async Task RunOrganizer_FivePhotos()
        {
            /// Description
            /// Generates JPEG files and runs the organizer service

            /// Expectation
            /// The generated JPEG files are found, sorted and added to the database

            var files = 5;

            // Create temp JPEG files
            var tempDirectory = PathHelper.GetTemporaryDirectory();

            var filenames = new List <string>();

            for (var i = 0; i < files; i++)
            {
                // Generate faux JPEG files and save names
                var filepath = PathHelper.CreateImageFile(tempDirectory, ImageFormat.Jpeg);
                filenames.Add(Path.GetFileName(filepath));
            }

            // Mock ISortService
            var sortServiceMock = new Mock <ISortService>();

            // Setup SortPhoto method
            sortServiceMock.Setup(mock => mock.SortPhoto(It.IsAny <Photo>(), It.IsAny <string>()))
            .Verifiable();

            // Fetch mocked objects
            var sortService = sortServiceMock.Object;

            // Create IConfiguration
            var configuration = CreateInMemoryConfiguration("MD5");

            // Setup DbContextOptions
            using var dbContext = new PhotoContext(DbOptions);
            await dbContext.Database.EnsureDeletedAsync();

            // Init and call OrganizerService
            var organizerService = new OrganizerService(logger, configuration, sortService, dbContext);
            await organizerService.RunOrganizerAsync(tempDirectory);

            // Verify mock call
            sortServiceMock.Verify(mock => mock.SortPhoto(It.IsAny <Photo>(), It.IsAny <string>()), Times.Exactly(files));

            // Assert database is not empty and contains the generated files
            Assert.NotEmpty(dbContext.Photos);

            foreach (var fn in filenames)
            {
                Assert.NotNull(dbContext.Photos.Find(fn));
            }
        }
예제 #7
0
        // GET: api/Photos
        public async Task <IHttpActionResult> GetPhotosByPenjualanId(int Id)
        {
            PhotoContext  context = new PhotoContext();
            List <IPhoto> photos  = context.GetPhotoByPenjualanId(Id);


            foreach (var item in photos)
            {
                var path = HttpContext.Current.Server.MapPath(string.Format("~/{0}/", item.Path));
                context    = new PhotoContext(path);
                item.Thumb = await context.GetThumb(item);
            }
            return(Ok(photos));
        }
예제 #8
0
 public PhotoController(PhotoContext context)
 {
     _context = context;
     for (int i = 1; i <= 5; i++)
     {
         if (_context.PhotoItems.Count() >= 5)
         {
             break;
         }
         _context.PhotoItems.Add(new Photo {
             Caption = $"Round {i}", Url = $"oracle.com/{i}", Contact_id = (i % 2 == 0) ? 1 : 2
         });
         _context.SaveChangesAsync();
     }
 }
예제 #9
0
        public async Task <IHttpActionResult> DeletePhoto(int id)
        {
            PhotoContext context = new PhotoContext();

            try
            {
                var result = context.GetPhotoById(id);
                var path   = HttpContext.Current.Server.MapPath(string.Format("~/{0}/", result.Path));
                context = new PhotoContext(path);
                return(Ok(await context.DeletePhoto(result)));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
예제 #10
0
        private static IEnumerable <string> GetDateTime(PhotoContext photoContext)
        {
            yield return(photoContext.RgbaImage?.MetaData?.ExifProfile?.GetValue(ExifTag.DateTimeOriginal)?.Value?.ToString());

            yield return(photoContext.RgbaImage?.MetaData?.ExifProfile?.GetValue(ExifTag.DateTimeDigitized)?.Value?.ToString());

            yield return(photoContext.RgbaImage?.MetaData?.ExifProfile?.GetValue(ExifTag.DateTime)?.Value?.ToString());

            var dateStamp = photoContext.RgbaImage?.MetaData?.ExifProfile?.GetValue(ExifTag.GPSDateStamp)?.Value?.ToString();
            var timeStamp = photoContext.RgbaImage?.MetaData?.ExifProfile?.GetValue(ExifTag.GPSTimestamp)?.Value?.ToString();

            if (!string.IsNullOrEmpty(dateStamp) && !string.IsNullOrEmpty(timeStamp))
            {
                yield return($"{dateStamp} {timeStamp.Substring(0, 8)}");
            }

            yield return(photoContext.Source.CreationTime.ToString("yyyy:MM:dd HH:mm:ss"));
        }
예제 #11
0
        static void Main(string[] args)
        {
            var context = new PhotoContext();

            ////Tag
            //Tag tag = new Tag()
            //{
            //    Label = "hahah"
            //};
            //context.Tags.Add(tag);
            //try
            //{
            //    context.SaveChanges();
            //}
            //catch (DbEntityValidationException e)
            //{
            //    tag.Label = TagTransformer.Transfrom(tag.Label);
            //    context.SaveChanges();
            //}

            Console.WriteLine(context.Photographers.Count());
        }
예제 #12
0
        public async Task RunOrganizer_NoPhotos()
        {
            /// Description
            /// Test the organizer with no photos

            /// Expectation
            /// ISortService.SortPhoto is never called. Database is empty.

            // Mock ISortService
            var sortServiceMock = new Mock <ISortService>();

            // Setup SortPhoto method
            sortServiceMock.Setup(mock => mock.SortPhoto(It.IsAny <Photo>(), It.IsAny <string>()))
            .Verifiable();

            // Fetch mocked objects
            var sortService = sortServiceMock.Object;

            // Create IConfiguration
            var configuration = CreateInMemoryConfiguration("MD5");

            // Create workdirectory in Temp
            var tempDirectory = PathHelper.GetTemporaryDirectory();

            // Setup DbContextOptions
            using var dbContext = new PhotoContext(DbOptions);
            await dbContext.Database.EnsureDeletedAsync();

            // Init and call OrganizerService
            var organizerService = new OrganizerService(logger, configuration, sortService, dbContext);
            await organizerService.RunOrganizerAsync(tempDirectory);

            // Verify mock call
            sortServiceMock.Verify(mock => mock.SortPhoto(It.IsAny <Photo>(), It.IsAny <string>()), Times.Never);

            // Assert database is empty
            Assert.Empty(dbContext.Photos);
        }
 public AlbumRepository(PhotoContext context)
 {
     this.db = context;
 }
예제 #14
0
        public static void Initialize(PhotoContext context)
        {
            context.Database.EnsureCreated();

            // If DB contains already labels ==> nothing need to be done
            if (context.Labels.Any())
            {
                return;
            }

            // Initialize labels
            var labels = new Label[]
            {
                new Label {
                    Name = "Daily", Color = "red"
                },
                new Label {
                    Name = "Travel", Color = "blue"
                },
                new Label {
                    Name = "Pet", Color = "green"
                },
                new Label {
                    Name = "Foods", Color = "orange"
                },
                new Label {
                    Name = "Nature", Color = "cyan"
                }
            };

            // Add labels into DB
            foreach (var label in labels)
            {
                context.Labels.Add(label);
            }
            context.SaveChanges();

            // Initialize users
            var users = new User[]
            {
                new User {
                    Username = "******", Password = "******", Role = Role.Admin
                },
                new User {
                    Username = "******", Password = "******", Role = Role.Friend
                },
                new User {
                    Username = "******", Password = "******", Role = Role.Admin
                },
                new User {
                    Username = "******", Password = "******", Role = Role.Visitor
                }
            };

            // Add users into DB
            foreach (var user in users)
            {
                context.Users.Add(user);
            }
            context.SaveChanges();
        }
 public ClientProfileRepository(PhotoContext context)
 {
     this.db = context;
 }
예제 #16
0
        public static void Main()
        {
            PhotoContext db = new PhotoContext();

            db.Database.Migrate();
        }
예제 #17
0
 public BlobController(IConfiguration configuration, PhotoContext dbContext)
 {
     _dbContext        = dbContext;
     _configuration    = configuration;
     _connectionString = _configuration.GetConnectionString("AzureStorageConnectionString-1");
 }
예제 #18
0
 public PhotoRepository(PhotoContext context)
 {
     this.db = context;
 }
예제 #19
0
        public static void Seed(PhotoContext db)
        {
            Photographer photographer = new Photographer()
            {
                Username       = "******",
                Email          = "*****@*****.**",
                Password       = "******",
                BirthDate      = new DateTime(1990, 10, 02),
                RegisteredDate = new DateTime(2017, 10, 10)
            };

            Photographer photographerTwo = new Photographer()
            {
                Username       = "******",
                Email          = "*****@*****.**",
                Password       = "******",
                BirthDate      = new DateTime(1989, 09, 02),
                RegisteredDate = new DateTime(2016, 10, 10)
            };

            Photographer photographerThree = new Photographer()
            {
                Username       = "******",
                Email          = "*****@*****.**",
                Password       = "******",
                BirthDate      = new DateTime(1977, 09, 02),
                RegisteredDate = new DateTime(2016, 01, 10)
            };

            Album album = new Album()
            {
                BackgroundColor = "Black",
                IsPublic        = true
            };

            Album albumTwo = new Album()
            {
                BackgroundColor = "White",
                IsPublic        = false
            };

            PhotographerAlbum photographerAlbum = new PhotographerAlbum()
            {
                Album        = album,
                Photographer = photographer
            };

            PhotographerAlbum photographerAlbumTwo = new PhotographerAlbum()
            {
                Album        = album,
                Photographer = photographerTwo
            };

            PhotographerAlbum photographerAlbumThree = new PhotographerAlbum()
            {
                Album        = albumTwo,
                Photographer = photographerTwo
            };

            PhotographerAlbum photographerAlbumFour = new PhotographerAlbum()
            {
                Album        = albumTwo,
                Photographer = photographerThree
            };

            Picture picture = new Picture()
            {
                Caption = "Nature",
                Path    = @"C:\Users\Admin\Desktop\Pictures",
                Title   = "SummerView"
            };

            Picture pictureOne = new Picture()
            {
                Caption = "Animals",
                Path    = @"C:\Users\Admin\Desktop\Pictures",
                Title   = "Zoo"
            };

            Picture pictureTwo = new Picture()
            {
                Caption = "Forest",
                Path    = @"C:\Users\Admin\Desktop\Pictures",
                Title   = "Tree"
            };

            db.PictureAlbums.Add(new PictureAlbum()
            {
                Album   = album,
                Picture = picture
            });

            db.PictureAlbums.Add(new PictureAlbum()
            {
                Album   = album,
                Picture = pictureOne
            });

            db.PictureAlbums.Add(new PictureAlbum()
            {
                Album   = albumTwo,
                Picture = pictureTwo
            });

            db.SaveChanges();
        }
예제 #20
0
 public PhotoRepository(PhotoContext dbContext)
 {
     _dbContext = dbContext;
 }
예제 #21
0
 public PhotoRepository(PhotoContext context)
 {
     _context = context;
 }
 public EFUnitOfWork()
 {
     db = new PhotoContext();
 }
예제 #23
0
 public LabelRepository(PhotoContext context)
 {
     _context = context;
 }
예제 #24
0
 public BlobController(IConfiguration configuration, PhotoContext dbContext)
 {
     _dbContext        = dbContext;
     _configuration    = configuration;
     _connectionString = _configuration.GetConnectionString("{your_connection_string_name}");
 }
예제 #25
0
 public PhotosController(PhotoContext _context)
 {
     context = _context;
 }
예제 #26
0
 //dep.inj tölti be a PhotoContext-et
 public HomeController(PhotoContext context)
 {
     bl = new BusinessLogic(context);
 }
예제 #27
0
 public ClientManager(PhotoContext db)
 {
     Database = db;
 }
예제 #28
0
 public AlbumController(PhotoContext context)
 {
     _context = context;
 }
예제 #29
0
 public CommentRepository(PhotoContext context)
 {
     this.db = context;
 }
예제 #30
0
 public HomeController(PhotoContext dbContext, IHostingEnvironment environment)
 {
     _dbContext   = dbContext;
     _environment = environment;
 }