Exemplo n.º 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));
        }
Exemplo n.º 2
0
        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"));
    }
Exemplo n.º 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));
        }
Exemplo n.º 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));
        }
Exemplo n.º 7
0
        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()));
        }
Exemplo n.º 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));
     }
 }
Exemplo n.º 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));
            }
        }
Exemplo n.º 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());
                }
            }
        }
Exemplo n.º 11
0
 public virtual void Adicionar(T entidade)
 {
     photoSharingContext.Set <T>().Add(entidade);
     photoSharingContext.SaveChanges();
 }