Example #1
0
        public IHttpActionResult PutPhoto(int id, Photo photo)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PhotoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        TEntity IDataRepository.Add <TEntity>(TEntity entity)
        {
            var photo = context.Set <TEntity>().Add(entity);

            context.SaveChanges();
            return(photo);
        }
    public ActionResult Create
        (Photo photo, HttpPostedFileBase image)
    {
        photo.CreatedDate = DateTime.Today;
        if (!ModelState.IsValid)
        {
            return(View("Create", photo));
        }
        else
        {
            if (image != null)
            {
                photo.ImageMimeType =
                    image.ContentType;
                photo.PhotoFile = new byte[image.ContentLength];
                image.InputStream.Read(photo.PhotoFile, 0, image.ContentLength);
            }
            return(RedirectToAction("Index"));
        }

        photo.PhotoFile = new
                          byte[image.ContentLength];
        image.InputStream.Read(
            photo.PhotoFile, 0,
            image.ContentLength);
        context.Photos.Add(photo);
        context.SaveChanges();
        return(View("Index"));
    }
Example #4
0
        public ActionResult Create([Bind(Include = "PhotoID,Title,ImageMimeType,Description,CreatedDate,UserName,PhotoFile")] Photo photo)
        {
            if (ModelState.IsValid)
            {
                db.Photos.Add(photo);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(photo));
        }
        public ActionResult Create(Photo photo)
        {
            if (ModelState.IsValid)
            {
                db.Photos.Add(photo);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(photo));
        }
Example #6
0
        public async Task <ActionResult> Create([Bind(Include = "PhotoID,Title,PhotoFile,ImageMimeType,Description,CreatedDate,UserName")] Photo photo)
        {
            if (ModelState.IsValid)
            {
                db.Photos.Add(photo);
                db.SaveChanges();
                var t = await Common.CreateTableAsync("Photos");

                TableOperation op = TableOperation.InsertOrMerge(photo);
                var            r  = await t.ExecuteAsync(op);

                return(RedirectToAction("Index"));
                // v
            }

            return(View(photo));
        }
        public PartialViewResult _CommentsForPhoto(int PhotoID, Comment comment)
        {
            context.Comment.Add(comment);
            context.SaveChanges();

            var comments = context.Comment.Where(m => m.PhotoID == PhotoID).OrderByDescending(m => m.CommentID);

            ViewBag.PhotoID = PhotoID;

            return(PartialView("_CommentsForPhoto", comments.ToList()));
        }
Example #8
0
 public ActionResult Create(Photo photo, HttpPostedFileBase image)
 {
     photo.CreatedDate = DateTime.Today;
     if (ModelState.IsValid)
     {
         //有post照片才做照片上傳的處理
         if (image != null)
         {
             photo.ImageMimeType = image.ContentType;             //抓照片型態
             photo.PhotoFile     = new byte[image.ContentLength]; //取得上傳照片的大小再轉byte陣列
             image.InputStream.Read(photo.PhotoFile, 0, image.ContentLength);
         }
         context.Photos.Add(photo);
         context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View("Create", photo));
     }
 }
Example #9
0
        // PUT api/CommentApi/5
        public HttpResponseMessage PutComment(int id, Comment comment)
        {
            if (ModelState.IsValid && id == comment.CommentID)
            {
                db.Entry(comment).State = EntityState.Modified;

                try
                {
                    db.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
Example #10
0
        public async void GetImageReturnsFile(int id)
        {
            var options = CreateNewContextOptions();

            // Run the test against one instance of the context
            using (var context = new PhotoSharingContext(options))
            {
                using (PhotosController controller = new PhotosController(context))
                {
                    var photos = new List <Photo>
                    {
                        new Photo {
                            Title         = "Me standing on top of a mountain",
                            Description   = "I was very impressed with myself",
                            UserName      = "******",
                            PhotoFile     = new byte[] { 255, 255, 255, 255, 255, 255, 255, 255 },
                            ImageMimeType = "image/jpeg",
                            CreatedDate   = DateTime.Today
                        },
                        new Photo {
                            Title         = "My New Adventure Works Bike",
                            Description   = "It's the bees knees!",
                            UserName      = "******",
                            PhotoFile     = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 },
                            ImageMimeType = "image/jpeg",
                            CreatedDate   = DateTime.Today
                        },
                        new Photo {
                            Title         = "View from the start line",
                            Description   = "I took this photo just before we started over my handle bars.",
                            UserName      = "******",
                            PhotoFile     = new byte[] { 255, 255, 255, 255, 0, 0, 0, 0 },
                            ImageMimeType = "image/jpeg",
                            CreatedDate   = DateTime.Today
                        }
                    };
                    photos.ForEach(s => context.Photos.Add(s));
                    context.SaveChanges();

                    var result = (await controller.GetImage(id)) as ActionResult;

                    Assert.Equal(typeof(FileContentResult), result.GetType());
                }
            }
        }
Example #11
0
 public virtual void Adicionar(T entidade)
 {
     photoSharingContext.Set <T>().Add(entidade);
     photoSharingContext.SaveChanges();
 }