public async Task <IHttpActionResult> PutPostPhoto(Guid id, PostPhoto postPhoto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != postPhoto.id)
            {
                return(BadRequest());
            }

            db.Entry(postPhoto).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PostPhotoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IHttpActionResult> PostPostPhoto(PostPhoto postPhoto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.PostPhotos.Add(postPhoto);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (PostPhotoExists(postPhoto.id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = postPhoto.id }, postPhoto));
        }
        public ActionResult Edit(int id, PetProfile petProfile, HttpPostedFileBase file)
        {
            int imageid;
            PODBProjectEntities entities = new PODBProjectEntities();
            String userId = User.Identity.GetUserId();

            PostPhoto photo = new PostPhoto();
            String    path  = photo.PostPhotoPet(file);

            if (file != null)
            {
                imageid = entities.Images.Where(e => e.imagePath.Equals(path)).FirstOrDefault().imageID;
            }
            else
            {
                imageid = entities.Announcements.Where(e => e.announceId.Equals(id)).FirstOrDefault().imageID;
            }
            try
            {
                using (PODBProjectEntities edit = new PODBProjectEntities())
                {
                    petProfile.Id                = User.Identity.GetUserId();
                    petProfile.imageID           = 1;
                    edit.Entry(petProfile).State = EntityState.Modified;
                    edit.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch
            {
                return(View());
            }
        }
Example #4
0
        public ActionResult Create(Announcement announce, HttpPostedFileBase file)
        {
            PODBProjectEntities entities = new PODBProjectEntities();

            PostPhoto photo = new PostPhoto();
            String    path  = photo.PostPhotoAnnouncement(file);

            int ImageID = entities.Images.Where(e => e.imagePath.Equals(path)).FirstOrDefault().imageID;

            try
            {
                using (PODBProjectEntities announcement = new PODBProjectEntities())
                {
                    announce.Id           = User.Identity.GetUserId();
                    announce.announceDate = DateTime.Now;
                    announce.imageID      = ImageID;
                    entities.Announcements.Add(announce);
                    entities.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Example #5
0
        public IActionResult CreatePost(IFormFile postImage, string postText)
        {
            string   fileName    = "";
            DateTime dateTimeNow = DateTime.Now;

            if (postText == null || postText == "")
            {
                return(Json(new { statusCode = ResponseStatus.ValidationError, responseMessage = ValidationMessages.EmptyPostText }));
            }

            if (postImage != null)
            {
                if (postImage.ContentType.ToLower() != "image/jpeg" && postImage.ContentType.ToLower() != "image/png" && postImage.ContentType.ToLower() != "image/jpg")
                {
                    return(Json(new { statusCode = ResponseStatus.ValidationError, responseMessage = ValidationMessages.WrongFormat }));
                }

                var uploads = Path.Combine(hostingEnvironment.WebRootPath, "PostPics");
                fileName = postImage.FileName.Split(".")[0] + "_" + DateTime.Now.ToFileTime() + "." + postImage.FileName.Split(".")[1];
                var filePath = Path.Combine(uploads, fileName);
                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    postImage.CopyTo(fileStream);
                }
            }

            User user = userData.GetUser(HttpContext);

            Post post = new Post()
            {
                IsDeleted = false, PostContent = postText
            };

            facebookDataContext.Posts.Add(post);
            try { facebookDataContext.SaveChanges(); }
            catch { return(Json(new { statusCode = ResponseStatus.Error })); }

            UsersPost usersPost = new UsersPost()
            {
                PostId = post.Id, IsCreator = true, CreatedAt = dateTimeNow, UserId = user.Id
            };

            facebookDataContext.UsersPosts.Add(usersPost);
            try { facebookDataContext.SaveChanges(); }
            catch { return(Json(new { statusCode = ResponseStatus.Error })); }

            if (postImage != null)
            {
                PostPhoto postPhoto = new PostPhoto()
                {
                    IsDeleted = false, PostId = post.Id, CreatedAt = dateTimeNow, Url = fileName
                };
                facebookDataContext.PostPhotos.Add(postPhoto);
                try { facebookDataContext.SaveChanges(); }
                catch { return(Json(new { statusCode = ResponseStatus.Error })); }
            }

            return(Json(new { statusCode = ResponseStatus.Success }));
        }
Example #6
0
        public ActionResult EditDetail(PetOwnerProfile info, HttpPostedFileBase file, Image ImageModel)
        {
            int imageid;
            PODBProjectEntities entities = new PODBProjectEntities();
            String userId = User.Identity.GetUserId();

            PostPhoto photo = new PostPhoto();
            String    path  = photo.PostPhotoPetOwner(file);

            if (file != null)
            {
                imageid = entities.Images.Where(e => e.imagePath.Equals(path)).FirstOrDefault().imageID;
            }
            else
            {
                imageid = entities.PetOwnerProfiles.Where(e => e.Id.Equals(userId)).FirstOrDefault().imageID;
            }

            using (PODBProjectEntities image = new PODBProjectEntities())
            {
                ImageModel.imageID               = imageid;
                ImageModel.imagePath             = path;
                ImageModel.imageType             = "PetOwnerProfile";
                entities.Entry(ImageModel).State = EntityState.Modified;
                entities.SaveChanges();
            }

            using (entities)
            {
                var result = entities.PetOwnerProfiles.SingleOrDefault(e => e.Id == userId);
                if (result != null)
                {
                    if (info.subdivision == null)
                    {
                        info.subdivision = "none";
                    }
                    else
                    {
                    }
                    var user = new PetOwnerProfile()
                    {
                        Id            = userId,
                        fullName      = info.fullName,
                        gender        = info.gender,
                        street        = info.street,
                        subdivision   = info.subdivision,
                        barangay      = info.barangay,
                        contactNumber = info.contactNumber,
                        email         = entities.AspNetUsers.Where(e => e.Id.Equals(userId)).FirstOrDefault().Email,
                        registerDate  = entities.PetOwnerProfiles.Where(e => e.Id.Equals(userId)).FirstOrDefault().registerDate,
                        updateDate    = DateTime.Now,
                        imageID       = imageid
                    };
                    entities.SaveChanges();
                }
                return(RedirectToAction("ViewDetail", "Manage"));
            }
        }
Example #7
0
        public async Task <IActionResult> Post(PhotosViewModel vm)
        {
            var post = this.unitOfWork.PostsRepository.GetById(vm.PostId);

            if (post == null)
            {
                return(BadRequest("The post does not exist."));
            }
            if (post.UserId != User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier).Value)
            {
                return(Forbid());
            }
            var numberOfFiles = vm.Files.Count;

            if (numberOfFiles > 8)
            {
                ModelState.AddModelError("size", "Number of images can't exceed 8.");
                return(BadRequest(ModelState));
            }
            foreach (var file in vm.Files)
            {
                string type = file.ContentType.Split("/")[0];
                if (type != "image")
                {
                    ModelState.AddModelError("type", "Invalid type");
                    return(BadRequest(ModelState));
                }
                else if (file.Length > 2145728)
                {
                    ModelState.AddModelError("size", "Image size must be lower than 2MB");
                    return(BadRequest(ModelState));
                }
                else
                {
                    string currentFileName = file.FileName.Trim('"');
                    string fileExtension   = Path.GetExtension(currentFileName);
                    string newFileName     = Guid.NewGuid().ToString() + fileExtension;
                    string filePath        = Path.Combine(this.hostingEnvironment.WebRootPath, "images", "posts", newFileName);
                    string dbPath          = Path.Combine("images", "posts", newFileName);
                    using (var stream = new FileStream(filePath, FileMode.Create))
                    {
                        file.CopyTo(stream);
                        stream.Flush();
                    }
                    PostPhoto newPhoto = new PostPhoto
                    {
                        Source = dbPath,
                        Alt    = "Post photo",
                        PostId = vm.PostId
                    };
                    this.unitOfWork.PostPhotosRepository.Add(newPhoto);
                }
            }
            await this.unitOfWork.Save();

            return(Created("PostPhotos", new { id = vm.PostId }));
        }
        public async Task <IHttpActionResult> GetPostPhoto(Guid id)
        {
            PostPhoto postPhoto = await db.PostPhotos.FindAsync(id);

            if (postPhoto == null)
            {
                return(NotFound());
            }

            return(Ok(postPhoto));
        }
        public async Task <IHttpActionResult> DeletePostPhoto(Guid id)
        {
            PostPhoto postPhoto = await db.PostPhotos.FindAsync(id);

            if (postPhoto == null)
            {
                return(NotFound());
            }

            db.PostPhotos.Remove(postPhoto);
            await db.SaveChangesAsync();

            return(Ok(postPhoto));
        }
Example #10
0
        public ActionResult PetOwnerProfile(PetOwnerProfile info, HttpPostedFileBase file, Image ImageModel)
        {
            PODBProjectEntities entities = new PODBProjectEntities();
            String userId = User.Identity.GetUserId();

            PostPhoto photo = new PostPhoto();
            String    path  = photo.PostPhotoPetOwner(file);

            int    imageid = entities.Images.Where(e => e.imagePath.Equals(path)).FirstOrDefault().imageID;
            string Email   = entities.AspNetUsers.Where(e => e.Id.Equals(userId)).FirstOrDefault().Email;

            if (info.subdivision == null)
            {
                info.subdivision = "N/A";
            }
            else
            {
            }
            var user = new PetOwnerProfile()
            {
                Id            = userId,
                fullName      = info.fullName,
                gender        = info.gender,
                street        = info.street,
                subdivision   = info.subdivision,
                barangay      = info.barangay,
                contactNumber = info.contactNumber,
                email         = Email,
                registerDate  = DateTime.Now,
                updateDate    = DateTime.Now,
                imageID       = imageid
            };

            entities.PetOwnerProfiles.Add(user);
            entities.SaveChanges();

            if (!entities.AspNetUsers.Where(e => e.Email.Equals(Email)).FirstOrDefault().EmailConfirmed)
            {
                Session.Abandon();
                AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
                ModelState.AddModelError("", "You need to confirm your email address");
                return(RedirectToAction("ConfirmBeforeLogin", "Account"));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Example #11
0
        public async Task <bool> PostVideo(PostPhoto postVideo)
        {
            var tour = await _dataContext.Tours.FirstOrDefaultAsync(x => x.Id == postVideo.TourId);

            var pathName = Guid.NewGuid();
            var dir      = _env.ContentRootPath;
            var fullPath = Path.Combine(dir, pathName + ".mp4");

            using (var filestream = new FileStream(fullPath, FileMode.Create, FileAccess.Write))
            {
                await postVideo.TourPhoto.CopyToAsync(filestream);
            }

            await _dataContext.TourVideo.AddAsync(new TourVideo { Tour = tour, Path = fullPath });

            await _dataContext.SaveChangesAsync();

            return(true);
        }
        public ActionResult Create(PetProfileModel petProfile, HttpPostedFileBase file)
        {
            PODBProjectEntities entities = new PODBProjectEntities();
            PostPhoto           photo    = new PostPhoto();
            String path = photo.PostPhotoPet(file);

            int ImageID = entities.Images.Where(e => e.imagePath.Equals(path)).FirstOrDefault().imageID;

            if (petProfile.mChipId == null)
            {
                petProfile.mChipId = "Not Microchipped";
            }
            var pet = new PetProfile
            {
                Id           = User.Identity.GetUserId(),
                imageID      = ImageID,
                petName      = petProfile.petName,
                petType      = petProfile.petType,
                petBreed     = petProfile.petBreed,
                gender       = petProfile.gender,
                mChipId      = petProfile.mChipId,
                mChipStatus  = petProfile.mChipStatus,
                nueterStatus = petProfile.nueterStatus
            };

            entities.PetProfiles.Add(pet);
            try
            {
                entities.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {
                foreach (var entityValidationErrors in ex.EntityValidationErrors)
                {
                    foreach (var validationError in entityValidationErrors.ValidationErrors)
                    {
                        Response.Write("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);
                    }
                }
            }
            return(RedirectToAction("Index"));
        }
Example #13
0
        public async Task <bool> PostPhoto(PostPhoto postPhoto)
        {
            var tour = await _dataContext.Tours.FirstOrDefaultAsync(x => x.Id == postPhoto.TourId);

            if (tour == null)
            {
                return(false);
            }

            var newEntity = new TourPhoto
            {
                TourId = tour.Id,
                Photo  = await GetFileAsByteArrayAsync(postPhoto.TourPhoto),
                Tour   = tour
            };

            var tourPhoto = await _dataContext.TourPhotos.AddAsync(newEntity);

            await _dataContext.SaveChangesAsync();

            return(true);
        }
Example #14
0
        public async Task <IActionResult> PostVideoFile([FromForm] PostPhoto postPhoto)
        {
            var response = await tourService.PostVideo(postPhoto);

            return(Ok(response));
        }
 public void Delete(PostPhoto postPhoto)
 {
     this.dbContext.PostPhotos.Remove(postPhoto);
 }
 public void Add(PostPhoto postPhoto)
 {
     this.dbContext.PostPhotos.Add(postPhoto);
 }