public void AddPhoto_IfUserIdIsZeroShouldAddPhoto()
        {
            var options = new DbContextOptionsBuilder <AppDbContext>()
                          .UseInMemoryDatabase(databaseName: "ImageAlbumDb")
                          .Options;

            using (var context = new AppDbContext(options))
            {
                context.Photos.AddRange(_photos.ToList());
                context.SaveChanges();
            }

            using (var context = new AppDbContext(options))
            {
                _photoRepo = new PhotoRepo(context);
                var photo = new Photo()
                {
                    Id = 0
                };

                _photoRepo.AddPhoto(photo);

                Assert.AreEqual(3, context.Photos.Count());
            }
        }
        public void UpdateComments_IfPhotoExistsShouldUpdateComments()
        {
            var options = new DbContextOptionsBuilder <AppDbContext>()
                          .UseInMemoryDatabase(databaseName: random.Next().ToString())
                          .Options;

            using (var context = new AppDbContext(options))
            {
                context.Photos.AddRange(_photos.ToList());
                context.SaveChanges();
            }

            using (var context = new AppDbContext(options))
            {
                _photoRepo = new PhotoRepo(context);

                _photoRepo.UpdateComments(new Photo()
                {
                    Id = 1, Comments = new List <Comment>()
                    {
                        new Comment {
                            Content = "comment"
                        }
                    }
                });

                Assert.AreEqual(1, context.Photos.First(c => c.Id == 1).Comments.Count());
                Assert.AreEqual("comment", context.Photos.First(c => c.Id == 1).Comments.First().Content);
            }
        }
示例#3
0
        public ActionResult Delete(int photoid)
        {
            PhotoRepo.DeletePhoto(PhotoRepo.GetPhoto(photoid));

            //TODO: remove the file from the folder where it lays

            return(RedirectToAction("Index", "User"));
        }
示例#4
0
        public ActionResult Index()
        {
            List <PhotoEntity> photoEntities = PhotoRepo.RetrieveAll();

            List <PhotoModel> photoModels = new List <PhotoModel>();

            foreach (var photoEntity in photoEntities)
            {
                photoModels.Add(EntityModelMapper.EntityToModel(photoEntity));
            }

            return(View(photoModels));
        }
示例#5
0
        public ActionResult Details(PhotoModel photo, string comment)
        {
            PhotoModel photoToCommentOn = EntityModelMapper.EntityToModel(PhotoRepo.GetPhoto(photo.PhotoModelId));

            CommentModel newComment = new CommentModel()
            {
                //CommentId = Guid.NewGuid(),
                Comment     = comment,
                DateCreated = DateTime.Now,
                //Photo = photo,
            };

            photoToCommentOn.Comments.Add(newComment);

            return(View(photoToCommentOn));
        }
示例#6
0
        public async Task <ActionResult> createCategorie([FromForm] CategorieToAddDto categorieToAddDto)
        {
            if (categorieToAddDto.userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized("You are not the User cliamd to be"));
            }
            string title  = " ";
            Author author = new Author();

            author = await _db.getAuthorByUserId(categorieToAddDto.userId);

            if (author == null)
            {
                return(Unauthorized("You are not an author"));
            }
            string    imageUrl  = "";
            string    coverUrl  = "";
            PhotoRepo photoRepo = new PhotoRepo();

            if (categorieToAddDto.image != null)
            {
                imageUrl = photoRepo.addPhoto(categorieToAddDto.image);
            }
            else
            {
                imageUrl = "https://res.cloudinary.com/afdgadsfg/image/upload/v1620223243/dbujq3h-13f8d636-9028-474c-b0fa-2a588511ac5f_dcy4lo.png";
            }
            if (categorieToAddDto.cover != null)
            {
                coverUrl = photoRepo.addPhoto(categorieToAddDto.cover);
            }
            else
            {
                coverUrl = "https://res.cloudinary.com/afdgadsfg/image/upload/v1620222961/final-image-diverse-people-1_svynwn.jpg";
            }

            title = await _db.createCategorie(categorieToAddDto, imageUrl, coverUrl);



            if (title == " ")
            {
                return(BadRequest("didn't create"));
            }
            return(Ok(new{ categorieTitle = title }));
        }
        public async Task <ActionResult> add(int userId, [FromForm] PostToAddDto postToAddDto)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized("You are not the Author"));
            }
            int       postId    = 0;
            Categorie categorie = await _postContext.getCatergorieById(postToAddDto.categorieId);

            Author author = new Author();

            author = await _postContext.GetAuthorByUserId(userId);

            if (author == null)
            {
                return(Unauthorized("You are not an author"));
            }
            if (categorie == null)
            {
                return(BadRequest("categorie doesn't exist"));
            }
            PhotoRepo photoRepo = new PhotoRepo();

            if (postToAddDto.postTypeId == 1)
            {
                postId = await _postContext.add(postToAddDto.title, postToAddDto.content, author.id, categorie.id, postToAddDto.postTypeId, " ");
            }
            if (postToAddDto.postTypeId == 2)
            {
                Console.WriteLine(postToAddDto.image + "  f");

                string imageUrl = photoRepo.addPhoto(postToAddDto.image);

                postId = await _postContext.add(postToAddDto.title, " ", author.id, categorie.id, postToAddDto.postTypeId, imageUrl);
            }

            if (postId == 0)
            {
                return(BadRequest("didn't post"));
            }
            Console.WriteLine("postNumber : " + postId);
            return(Ok(new{ num = postId }));
        }
示例#8
0
        public ICollection <TimeLapseFrame> CreateTimeLapseFramesFromIDs(long[] photoIDs)
        {
            List <TimeLapseFrame> frames = new List <TimeLapseFrame>();
            long firstID = photoIDs[0]; // stupid LINQ

            USCounty county = DMRepository.GetCountyForFips(PhotoRepository.Find(p => p.ID == firstID, p => p.Site)
                                                            .FirstOrDefault().Site.CountyFips);

            var properties = PhotoRepo.GetPhotoProperties(photoIDs, new string[] { "ID", "Captured" });

            foreach (var property in properties)
            {
                var frame = new TimeLapseFrame()
                {
                    FrameTime = (DateTime)property["Captured"], PhotoID = (long)property["ID"]
                };
                frames.Add(frame);
            }

            return(frames);
        }
        public void DeletePhoto_IfPhotoExistsShouldDeletePhoto()
        {
            var options = new DbContextOptionsBuilder <AppDbContext>()
                          .UseInMemoryDatabase(databaseName: "InMemoryDb")
                          .Options;

            using (var context = new AppDbContext(options))
            {
                context.Photos.AddRange(_photos.ToList());
                context.SaveChanges();
            }

            using (var context = new AppDbContext(options))
            {
                _photoRepo = new PhotoRepo(context);

                _photoRepo.DeletePhoto(2);

                Assert.AreEqual(1, context.Photos.Count());
            }
        }
        public void Photos_ShouldReturnAllPhotos()
        {
            var options = new DbContextOptionsBuilder <AppDbContext>()
                          .UseInMemoryDatabase(databaseName: random.Next().ToString())
                          .Options;

            using (var context = new AppDbContext(options))
            {
                context.Photos.AddRange(_photos.ToList());
                context.SaveChanges();
            }

            using (var context = new AppDbContext(options))
            {
                _photoRepo = new PhotoRepo(context);

                var result = _photoRepo.Photos;

                Assert.AreEqual(2, result.Count());
            }
        }
        public void UpdatePhoto_IfPhotoExistsShouldUpdatePhoto()
        {
            var options = new DbContextOptionsBuilder <AppDbContext>()
                          .UseInMemoryDatabase(databaseName: random.Next().ToString())
                          .Options;

            using (var context = new AppDbContext(options))
            {
                context.Photos.AddRange(_photos.ToList());
                context.SaveChanges();
            }

            using (var context = new AppDbContext(options))
            {
                _photoRepo = new PhotoRepo(context);

                _photoRepo.UpdatePhoto(new Photo()
                {
                    Id = 1, Description = "changed"
                });

                Assert.AreEqual("changed", context.Photos.First(c => c.Id == 1).Description);
            }
        }
示例#12
0
        public ActionResult Details(PhotoModel photo)
        {
            PhotoModel photoToDisplay = EntityModelMapper.EntityToModel(PhotoRepo.GetPhoto(photo.PhotoModelId));

            return(View(photoToDisplay));
        }
示例#13
0
 public PhotoService(PhotoRepo pr)
 {
     _pRepo = pr;
 }
示例#14
0
        public ActionResult Add(FailureViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            try
            {
                model.ClientId = System.Web.HttpContext.Current.User.Identity.GetUserId();

                var data = Mapper.Map <FailureViewModel, Failure>(model);

                var failureRepo = new FailureRepo();
                failureRepo.Insert(data);
                var photoRepo = new PhotoRepo();
                if (model.PostedPhoto.Count > 0)
                {
                    model.PostedPhoto.ForEach(file =>
                    {
                        if (file == null || file.ContentLength <= 0)
                        {
                            return;
                        }

                        string fileName = "failure-";
                        fileName       += Path.GetFileNameWithoutExtension(file.FileName);
                        string extName  = Path.GetExtension(file.FileName);
                        fileName        = StringHelpers.UrlFormatConverter(fileName);
                        fileName       += StringHelpers.GetCode();
                        var klasoryolu  = Server.MapPath("~/Upload/Failure/");
                        var dosyayolu   = Server.MapPath("~/Upload/Failure/") + fileName + extName;

                        if (!Directory.Exists(klasoryolu))
                        {
                            Directory.CreateDirectory(klasoryolu);
                        }
                        file.SaveAs(dosyayolu);

                        WebImage img = new WebImage(dosyayolu);
                        img.Resize(800, 600, false);
                        img.AddTextWatermark("Teknik Servisçi");
                        img.Save(dosyayolu);
                        photoRepo.Insert(new Photo()
                        {
                            FailureId = data.Id,
                            Path      = "/Upload/Failure/" + fileName + extName
                        });
                    });
                }

                var photos = photoRepo.GetAll(x => x.FailureId == data.Id).ToList();
                var photo  = photos.Select(x => x.Path).ToList();
                data.PhotoPath = photo;
                failureRepo.Update(data);

                new OperationRepo().Insert(new Operation()
                {
                    FailureId = data.Id,
                    Message   = $"#{data.Id} - {data.FailureName} adlı arıza kaydı oluşturuldu.",
                    FromWhom  = IdentityRoles.User
                });
                TempData["Message"] = $"{model.FailureName} adlı arızanız operatörlerimizce incelenecektir ve size 24 saat içinde dönüş yapılacaktır.";
                return(RedirectToAction("Add"));
            }
            catch (DbEntityValidationException ex)
            {
                TempData["Model"] = new ErrorViewModel()
                {
                    Text           = $"Bir hata oluştu: {EntityHelpers.ValidationMessage(ex)}",
                    ActionName     = "Add",
                    ControllerName = "Failure",
                    ErrorCode      = 500
                };
                return(RedirectToAction("Error", "Home"));
            }
            catch (Exception ex)
            {
                TempData["Model"] = new ErrorViewModel()
                {
                    Text           = $"Bir hata oluştu: {ex.Message}",
                    ActionName     = "Add",
                    ControllerName = "Failure",
                    ErrorCode      = 500
                };
                return(RedirectToAction("Error", "Home"));
            }
        }